Skip to content

Commit

Permalink
also add packages that are placed in src folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-vivien committed Nov 6, 2023
1 parent 6342aa9 commit 9e0b154
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion cluster_pack/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ def _get_editable_requirements(executable: str = sys.executable) -> List[str]:
top_level_pkgs = []
for pkg in _get_packages(True, executable):
location = pkg.get("editable_project_location", pkg.get("location", ""))
for _pkg in setuptools.find_packages(location):
packages_found = set(
setuptools.find_packages(location) + setuptools.find_packages(f"{location}/src")
)
for _pkg in packages_found:
if "." in _pkg:
continue
imported = __import__(_pkg)
Expand Down
20 changes: 18 additions & 2 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def test__get_editable_requirements():
assert "user_lib" in pkg_names
assert "user_lib2" in pkg_names

def test__get_editable_requirements_for_src_layout():
with tempfile.TemporaryDirectory() as tempdir:
_create_venv(tempdir)
_pip_install(tempdir)
editable_requirements = packaging._get_editable_requirements(
f"{tempdir}/bin/python", use_src_layout=True
)
assert len(editable_requirements) == 2
pkg_names = [os.path.basename(req) for req in editable_requirements]
assert "user_lib" in pkg_names
assert "user_lib2" in pkg_names


@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher")
def test__get_editable_requirements_withpip23():
Expand Down Expand Up @@ -90,10 +102,11 @@ def _create_venv(tempdir: str):
subprocess.check_call([sys.executable, "-m", "venv", f"{tempdir}"])


def _pip_install(tempdir: str, pip_version: str = "18.1"):
def _pip_install(tempdir: str, pip_version: str = "18.1", use_src_layout: bool = False):
subprocess.check_call([f"{tempdir}/bin/python", "-m", "pip", "install",
"cloudpickle", f"pip=={pip_version}"])
pkg = _get_editable_package_name()
pkg = (_get_editable_package_name_src_layout() if use_src_layout
else _get_editable_package_name())
subprocess.check_call([f"{tempdir}/bin/python", "-m", "pip", "install", "-e", pkg])
if pkg not in sys.path:
sys.path.append(pkg)
Expand All @@ -102,6 +115,9 @@ def _pip_install(tempdir: str, pip_version: str = "18.1"):
def _get_editable_package_name():
return os.path.join(os.path.dirname(__file__), "user-lib")

def _get_editable_package_name_src_layout():
return os.path.join(os.path.dirname(__file__), "user-lib-src-layout")


def test_get_current_pex_filepath():
with tempfile.TemporaryDirectory() as tempdir:
Expand Down
Empty file.
8 changes: 8 additions & 0 deletions tests/user-lib-src-layout/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python3

import setuptools

setuptools.setup(
name='user_lib_src_layout',
version='0.0.1',
packages=setuptools.find_packages())
Empty file.
2 changes: 2 additions & 0 deletions tests/user-lib-src-layout/src/user_lib/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_method():
print("Hello World!")
Empty file.

0 comments on commit 9e0b154

Please sign in to comment.