Skip to content

Commit b01915e

Browse files
authored
Merge pull request #248 from NLeSC/160-subpackage
Subpackage support
2 parents 100929e + 22e6e34 commit b01915e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

tests/test_project.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from sys import platform
44
from typing import Sequence
55

6+
import pytest
7+
68

79
def test_project_folder(cookies):
810
project = cookies.bake()
@@ -21,7 +23,8 @@ def run(args: Sequence[str], dirpath: os.PathLike) -> subprocess.CompletedProces
2123
encoding="utf-8")
2224

2325

24-
def test_pytest(cookies):
26+
@pytest.fixture
27+
def baked_with_development_dependencies(cookies):
2528
result = cookies.bake()
2629
env_output = run(['python3', '-m', 'venv', 'env'], result.project)
2730
assert env_output.returncode == 0
@@ -30,9 +33,29 @@ def test_pytest(cookies):
3033
assert latest_pip_output.returncode == 0
3134
pip_output = run([f'{env_bin}pip3', 'install', '--editable', '.[dev]'], result.project)
3235
assert pip_output.returncode == 0
36+
return result.project, env_bin
37+
3338

34-
pytest_output = run([f'{env_bin}pytest'], result.project)
39+
def test_pytest(baked_with_development_dependencies):
40+
project_dir, env_bin = baked_with_development_dependencies
41+
pytest_output = run([f'{env_bin}pytest'], project_dir)
3542
assert pytest_output.returncode == 0
36-
assert '== 3 passed in' in pytest_output.stdout
37-
assert (result.project / 'coverage.xml').exists()
38-
assert (result.project / 'htmlcov/index.html').exists()
43+
assert '== 3 passed in' in pytest_output.stdout
44+
assert (project_dir / 'coverage.xml').exists()
45+
assert (project_dir / 'htmlcov/index.html').exists()
46+
47+
48+
def test_subpackage(baked_with_development_dependencies):
49+
project_dir, env_bin = baked_with_development_dependencies
50+
subpackage = (project_dir / 'my_python_package' / 'mysub')
51+
subpackage.mkdir()
52+
(subpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8")
53+
54+
subsubpackage = (project_dir / 'my_python_package' / 'mysub' / 'mysub2')
55+
subsubpackage.mkdir()
56+
(subsubpackage / '__init__.py').write_text('FOO = "bar"', encoding="utf-8")
57+
58+
build_output = run([f'{env_bin}python3', 'setup.py', 'build'], project_dir)
59+
assert build_output.returncode == 0
60+
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / '__init__.py').exists()
61+
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / 'mysub2' / '__init__.py').exists()

{{cookiecutter.project_name}}/setup.cfg

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ version = {{ cookiecutter.version }}
3434
[options]
3535
zip_safe = False
3636
include_package_data = True
37-
packages =
38-
{{ cookiecutter.package_name }}
37+
packages = find:
3938
install_requires =
4039

4140
[options.data_files]
@@ -57,10 +56,13 @@ dev =
5756
sphinx
5857
sphinx_rtd_theme
5958
recommonmark
60-
publishing =
59+
publishing =
6160
twine
6261
wheel
6362

63+
[options.packages.find]
64+
include = {{ cookiecutter.package_name }}, {{ cookiecutter.package_name }}.*
65+
6466
[coverage:run]
6567
branch = True
6668
source = {{ cookiecutter.package_name }}

0 commit comments

Comments
 (0)