Skip to content

Commit 75206df

Browse files
author
Michael Fraenkel
committed
Add the correct path when it's a package
1 parent 0fa82cf commit 75206df

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from invoke import task
2+
from . import pytest as pt
3+
import pytest
4+
5+
pytest.__version__
26

37

48
@task
59
def mytask(c):
6-
print("hi!")
10+
print(pt.hi)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hi = "hi!"

invoke/loader.py

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def load(self, name: Optional[str] = None) -> Tuple[ModuleType, str]:
7373
# being imported is trying to load local-to-it names.
7474
if os.path.isfile(spec.origin):
7575
path = os.path.dirname(spec.origin)
76+
if spec.origin.endswith("__init__.py"):
77+
path = os.path.dirname(path)
7678
if path not in sys.path:
7779
sys.path.insert(0, path)
7880
# Actual import

tests/loader.py

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ def adds_module_parent_dir_to_sys_path(self):
5151
# Crummy doesn't-explode test.
5252
_BasicLoader().load("namespacing")
5353

54+
def adds_package_dir_to_sys_path(self):
55+
config = Config({"tasks": {"collection_name": "module"}})
56+
_BasicLoader(config).load("package")
57+
package = Path(support) / "package"
58+
assert str(package) not in sys.path
59+
5460
def doesnt_duplicate_parent_dir_addition(self):
5561
_BasicLoader().load("namespacing")
5662
_BasicLoader().load("namespacing")

0 commit comments

Comments
 (0)