Skip to content

Commit

Permalink
Fix package import hook
Browse files Browse the repository at this point in the history
Resolves   #861.
  • Loading branch information
evhub committed Dec 1, 2024
1 parent 892ce3c commit fa0024c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pyston/
pyprover/
bbopt/
coconut-prelude/
coconut-issue/
index.rst
/coconut/icoconut/coconut/
__coconut_cache__/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ docs: clean

.PHONY: clean-no-tests
clean-no-tests:
rm -rf ./docs ./dist ./build ./bbopt ./pyprover ./pyston ./coconut-prelude index.rst ./.mypy_cache
rm -rf ./docs ./dist ./build ./bbopt ./pyprover ./pyston ./coconut-prelude ./coconut-issue index.rst ./.mypy_cache

.PHONY: clean
clean: clean-no-tests
Expand Down
9 changes: 6 additions & 3 deletions coconut/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ class CoconutImporter(object):
command = None

def __init__(self, *args):
self.use_cache_dir(default_use_cache_dir)
self.set_args(args)
self.use_cache_dir(default_use_cache_dir)

def use_cache_dir(self, use_cache_dir):
"""Set the cache directory if any to use for compiled Coconut files."""
if use_cache_dir:
if use_cache_dir and "--no-cache" not in self.args:
if not PY34:
raise CoconutException("coconut.api.auto_compilation only supports the usage of a cache directory on Python 3.4+")
self.cache_dir = coconut_cache_dir
Expand Down Expand Up @@ -238,7 +238,10 @@ def compile(self, path, package):

if package:
self.cmd(path, *extra_args)
return cache_dir or path
if cache_dir:
return os.path.join(cache_dir, "__init__.py")
else:
return path
else:
destpath, = self.cmd(path, *extra_args)
return destpath
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.1.2"
VERSION_NAME = None
# False for release, int >= 1 for develop
DEVELOP = 5
DEVELOP = 6
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
9 changes: 9 additions & 0 deletions coconut/tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,13 @@ def pexpect(p, out):
pyprover = os.path.join(os.curdir, "pyprover")
prelude = os.path.join(os.curdir, "coconut-prelude")
bbopt = os.path.join(os.curdir, "bbopt")
imp_issue_dir = os.path.join(os.curdir, "coconut-issue")

pyston_git = "https://github.com/evhub/pyston.git"
pyprover_git = "https://github.com/evhub/pyprover.git"
prelude_git = "https://github.com/evhub/coconut-prelude"
bbopt_git = "https://github.com/evhub/bbopt.git"
imp_issue_git = "https://github.com/evhub/coconut-issue.git"

coconut_snip = "msg = '<success>'; pmsg = print$(msg); `pmsg`"
target_3_snip = "assert super is py_super; print('<success>')"
Expand Down Expand Up @@ -1117,6 +1119,13 @@ def test_pyston(self):
if PYPY and PY2:
run_pyston()

def test_imp_issue(self):
with using_paths(imp_issue_dir):
if not os.path.exists(imp_issue_dir):
call(["git", "clone", imp_issue_git])
with using_env_vars({"PYTHONPATH": os.pathsep.join([imp_issue_dir, os.environ.get("PYTHONPATH", "")])}):
call_coconut(["-r", os.path.join(imp_issue_dir, "main.coco")])


# -----------------------------------------------------------------------------------------------------------------------
# MAIN:
Expand Down

0 comments on commit fa0024c

Please sign in to comment.