Skip to content

Commit

Permalink
Fix jobs on standalone mode
Browse files Browse the repository at this point in the history
Resolves   #739.
  • Loading branch information
evhub committed May 25, 2023
1 parent c427350 commit 7315d7e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
24 changes: 13 additions & 11 deletions coconut/command/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
can_parse,
invert_mypy_arg,
run_with_stack_size,
memoized_isdir,
memoized_isfile,
)
from coconut.compiler.util import (
should_indent,
Expand Down Expand Up @@ -302,7 +304,7 @@ def execute_args(self, args, interact=True, original_args=None):
]

# disable jobs if we know we're only compiling one file
if len(src_dest_package_triples) <= 1 and not any(package for _, _, package in src_dest_package_triples):
if len(src_dest_package_triples) <= 1 and not any(memoized_isdir(source) for source, dest, package in src_dest_package_triples):
self.disable_jobs()

# do compilation
Expand Down Expand Up @@ -363,12 +365,12 @@ def process_source_dest(self, source, dest, args):
processed_source = fixpath(source)

# validate args
if (args.run or args.interact) and os.path.isdir(processed_source):
if (args.run or args.interact) and memoized_isdir(processed_source):
if args.run:
raise CoconutException("source path %r must point to file not directory when --run is enabled" % (source,))
if args.interact:
raise CoconutException("source path %r must point to file not directory when --run (implied by --interact) is enabled" % (source,))
if args.watch and os.path.isfile(processed_source):
if args.watch and memoized_isfile(processed_source):
raise CoconutException("source path %r must point to directory not file when --watch is enabled" % (source,))

# determine dest
Expand All @@ -389,9 +391,9 @@ def process_source_dest(self, source, dest, args):
package = False
else:
# auto-decide package
if os.path.isfile(source):
if memoized_isfile(processed_source):
package = False
elif os.path.isdir(source):
elif memoized_isdir(processed_source):
package = True
else:
raise CoconutException("could not find source path", source)
Expand Down Expand Up @@ -442,17 +444,17 @@ def compile_path(self, path, write=True, package=True, **kwargs):
"""Compile a path and returns paths to compiled files."""
if not isinstance(write, bool):
write = fixpath(write)
if os.path.isfile(path):
if memoized_isfile(path):
destpath = self.compile_file(path, write, package, **kwargs)
return [destpath] if destpath is not None else []
elif os.path.isdir(path):
elif memoized_isdir(path):
return self.compile_folder(path, write, package, **kwargs)
else:
raise CoconutException("could not find source path", path)

def compile_folder(self, directory, write=True, package=True, **kwargs):
"""Compile a directory and returns paths to compiled files."""
if not isinstance(write, bool) and os.path.isfile(write):
if not isinstance(write, bool) and memoized_isfile(write):
raise CoconutException("destination path cannot point to a file when compiling a directory")
filepaths = []
for dirpath, dirnames, filenames in os.walk(directory):
Expand Down Expand Up @@ -660,7 +662,7 @@ def running_jobs(self, exit_on_error=True):

def has_hash_of(self, destpath, code, package_level):
"""Determine if a file has the hash of the code."""
if destpath is not None and os.path.isfile(destpath):
if destpath is not None and memoized_isfile(destpath):
with univ_open(destpath, "r") as opened:
compiled = readfile(opened)
hashash = gethash(compiled)
Expand Down Expand Up @@ -989,7 +991,7 @@ def watch(self, src_dest_package_triples, run=False, force=False):

def recompile(path, src, dest, package):
path = fixpath(path)
if os.path.isfile(path) and os.path.splitext(path)[1] in code_exts:
if memoized_isfile(path) and os.path.splitext(path)[1] in code_exts:
with self.handling_exceptions():
if dest is True or dest is None:
writedir = dest
Expand Down Expand Up @@ -1043,7 +1045,7 @@ def site_uninstall(self):
python_lib = self.get_python_lib()
pth_file = os.path.join(python_lib, os.path.basename(coconut_pth_file))

if os.path.isfile(pth_file):
if memoized_isfile(pth_file):
os.remove(pth_file)
logger.show_sig("Removed %s from %s" % (os.path.basename(coconut_pth_file), python_lib))
else:
Expand Down
5 changes: 5 additions & 0 deletions coconut/command/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
pickleable_obj,
get_encoding,
get_clock_time,
memoize,
)
from coconut.constants import (
WINDOWS,
Expand Down Expand Up @@ -132,6 +133,10 @@
# -----------------------------------------------------------------------------------------------------------------------


memoized_isdir = memoize(128)(os.path.isdir)
memoized_isfile = memoize(128)(os.path.isfile)


def writefile(openedfile, newcontents):
"""Set the contents of a file."""
openedfile.seek(0)
Expand Down
2 changes: 1 addition & 1 deletion coconut/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
VERSION = "3.0.0"
VERSION_NAME = None
# False for release, int >= 1 for develop
DEVELOP = 2
DEVELOP = 3
ALPHA = False # for pre releases rather than post releases

assert DEVELOP is False or DEVELOP >= 1, "DEVELOP must be False or an int >= 1"
Expand Down

0 comments on commit 7315d7e

Please sign in to comment.