Skip to content

Commit fa0024c

Browse files
committed
Fix package import hook
Resolves #861.
1 parent 892ce3c commit fa0024c

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pyston/
137137
pyprover/
138138
bbopt/
139139
coconut-prelude/
140+
coconut-issue/
140141
index.rst
141142
/coconut/icoconut/coconut/
142143
__coconut_cache__/

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ docs: clean
331331

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

336336
.PHONY: clean
337337
clean: clean-no-tests

coconut/api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,12 @@ class CoconutImporter(object):
202202
command = None
203203

204204
def __init__(self, *args):
205-
self.use_cache_dir(default_use_cache_dir)
206205
self.set_args(args)
206+
self.use_cache_dir(default_use_cache_dir)
207207

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

239239
if package:
240240
self.cmd(path, *extra_args)
241-
return cache_dir or path
241+
if cache_dir:
242+
return os.path.join(cache_dir, "__init__.py")
243+
else:
244+
return path
242245
else:
243246
destpath, = self.cmd(path, *extra_args)
244247
return destpath

coconut/root.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
VERSION = "3.1.2"
2727
VERSION_NAME = None
2828
# False for release, int >= 1 for develop
29-
DEVELOP = 5
29+
DEVELOP = 6
3030
ALPHA = False # for pre releases rather than post releases
3131

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

coconut/tests/main_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ def pexpect(p, out):
136136
pyprover = os.path.join(os.curdir, "pyprover")
137137
prelude = os.path.join(os.curdir, "coconut-prelude")
138138
bbopt = os.path.join(os.curdir, "bbopt")
139+
imp_issue_dir = os.path.join(os.curdir, "coconut-issue")
139140

140141
pyston_git = "https://github.com/evhub/pyston.git"
141142
pyprover_git = "https://github.com/evhub/pyprover.git"
142143
prelude_git = "https://github.com/evhub/coconut-prelude"
143144
bbopt_git = "https://github.com/evhub/bbopt.git"
145+
imp_issue_git = "https://github.com/evhub/coconut-issue.git"
144146

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

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

11211130
# -----------------------------------------------------------------------------------------------------------------------
11221131
# MAIN:

0 commit comments

Comments
 (0)