Skip to content

Commit fc8f91b

Browse files
authored
Merge pull request #374 from NLeSC/src-layout
Move generated package to `src/` layout
2 parents 8b205dc + f5b0ad1 commit fc8f91b

File tree

8 files changed

+31
-37
lines changed

8 files changed

+31
-37
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
### Changed
1414

15+
* Moved to src/ based layout for generated packages
1516
* Moved from setup.cfg/.py to pyproject.toml [#351](https://github.com/NLeSC/python-template/issues/351)
1617
* Moved from prospector to ruff [#336](https://github.com/NLeSC/python-template/issues/336)
1718
* Renamed `project_name` to `directory_name` in cookiecutter questionnaire

README.md

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@ Good job! You have now generated the skeleton for your package:
8989

9090
```text
9191
my-python-project/
92-
├── CHANGELOG.md
93-
├── CITATION.cff
94-
├── CODE_OF_CONDUCT.md
95-
├── CONTRIBUTING.md
96-
├── docs
97-
│ ├── conf.py
98-
│ ├── index.rst
99-
│ ├── make.bat
100-
│ ├── Makefile
101-
│ ├── _static
102-
│ │ └── theme_overrides.css
103-
│ └── _templates
104-
│ └── .gitignore
10592
├── .editorconfig
10693
├── .githooks
10794
│ └── pre-commit
@@ -115,26 +102,37 @@ my-python-project/
115102
│ └── workflows
116103
│ ├── build.yml
117104
│ ├── cffconvert.yml
118-
│ ├── lint.yml
105+
│ ├── documentation.yml
119106
│ ├── markdown-link-check.yml
120107
│ ├── next_steps.yml
121108
│ └── sonarcloud.yml
122109
├── .gitignore
110+
├── .mlc-config.json
111+
├── .readthedocs.yaml
112+
├── CHANGELOG.md
113+
├── CITATION.cff
114+
├── CODE_OF_CONDUCT.md
115+
├── CONTRIBUTING.md
123116
├── LICENSE
124117
├── MANIFEST.in
125-
├── .mlc-config.json
126-
├── my_python_package
127-
│ ├── __init__.py
128-
│ ├── my_module.py
129-
│ └── __version__.py
130-
├── next_steps.md
131118
├── NOTICE
132-
├── project_setup.md
133-
├── .pylintrc
134-
├── pyproject.toml
135119
├── README.dev.md
136120
├── README.md
121+
├── docs
122+
│ ├── Makefile
123+
│ ├── _templates
124+
│ │ └── .gitignore
125+
│ ├── conf.py
126+
│ ├── index.rst
127+
│ └── make.bat
128+
├── next_steps.md
129+
├── project_setup.md
130+
├── pyproject.toml
137131
├── sonar-project.properties
132+
├── src
133+
│ └── my_python_package
134+
│ ├── __init__.py
135+
│ └── my_module.py
138136
└── tests
139137
├── __init__.py
140138
└── test_my_module.py

tests/test_project.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ def test_subpackage(baked_with_development_dependencies, project_env_bin_dir):
8383
"""Test if subpackages end up in (wheel) distributions"""
8484
project_dir = baked_with_development_dependencies
8585
bin_dir = project_env_bin_dir
86-
subpackage = (project_dir / 'my_python_package' / 'mysub')
86+
subpackage = (project_dir / 'src' / 'my_python_package' / 'mysub')
8787
subpackage.mkdir()
8888
(subpackage / '__init__.py').write_text('FOO = "bar"\n', encoding="utf-8")
8989

90-
subsubpackage = (project_dir / 'my_python_package' / 'mysub' / 'mysub2')
90+
subsubpackage = (project_dir / 'src' / 'my_python_package' / 'mysub' / 'mysub2')
9191
subsubpackage.mkdir()
9292
(subsubpackage / '__init__.py').write_text('FOO = "bar"\n', encoding="utf-8")
9393

@@ -179,7 +179,7 @@ def test_bumpversion(baked_with_development_dependencies, project_env_bin_dir):
179179
original_version = '0.1.0'
180180
assert original_version in (project_dir / 'pyproject.toml').read_text('utf-8')
181181
assert original_version in (project_dir / 'CITATION.cff').read_text('utf-8')
182-
assert original_version in (project_dir / 'my_python_package' / '__init__.py').read_text('utf-8')
182+
assert original_version in (project_dir / 'src' / 'my_python_package' / '__init__.py').read_text('utf-8')
183183
assert original_version in (project_dir / 'docs' / 'conf.py').read_text('utf-8')
184184

185185
result = run([f'{bin_dir}bump-my-version', 'bump', 'major'], project_dir)
@@ -188,5 +188,5 @@ def test_bumpversion(baked_with_development_dependencies, project_env_bin_dir):
188188
expected_version = '1.0.0'
189189
assert expected_version in (project_dir / 'pyproject.toml').read_text('utf-8')
190190
assert expected_version in (project_dir / 'CITATION.cff').read_text('utf-8')
191-
assert expected_version in (project_dir / 'my_python_package' / '__init__.py').read_text('utf-8')
191+
assert expected_version in (project_dir / 'src' / 'my_python_package' / '__init__.py').read_text('utf-8')
192192
assert expected_version in (project_dir / 'docs' / 'conf.py').read_text('utf-8')

{{cookiecutter.directory_name}}/docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
# -- Use autoapi.extension to run sphinx-apidoc -------
6363

64-
autoapi_dirs = ['../{{ cookiecutter.package_name }}']
64+
autoapi_dirs = ['../src/{{ cookiecutter.package_name }}']
6565

6666
# -- Options for HTML output ----------------------------------------------
6767

{{cookiecutter.directory_name}}/pyproject.toml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,17 @@ testpaths = ["tests"]
7272

7373
[tool.coverage.run]
7474
branch = true
75-
source = ["{{ cookiecutter.package_name }}"]
75+
source = ["src/{{ cookiecutter.package_name }}"]
7676
command_line = "-m pytest"
7777

7878
[tool.isort]
7979
lines_after_imports = 2
8080
force_single_line = 1
8181
no_lines_before = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
8282
known_first_party = "{{ cookiecutter.package_name }}"
83-
src_paths = ["{{ cookiecutter.package_name }}", "tests"]
83+
src_paths = ["src/{{ cookiecutter.package_name }}", "tests"]
8484
line_length = 120
8585

86-
# For completeness, until we move to an src-based layout
87-
[tool.setuptools.packages.find]
88-
include = ["{{ cookiecutter.package_name }}*"]
89-
exclude = ["tests*"]
90-
9186
[tool.tox]
9287
legacy_tox_ini = """
9388
[tox]
@@ -177,7 +172,7 @@ no-lines-before = ["future","standard-library","third-party","first-party","loca
177172
current_version = "{{ cookiecutter.version }}"
178173

179174
[[tool.bumpversion.files]]
180-
filename = "{{ cookiecutter.package_name }}/__init__.py"
175+
filename = "src/{{ cookiecutter.package_name }}/__init__.py"
181176

182177
[[tool.bumpversion.files]]
183178
filename = "pyproject.toml"

{{cookiecutter.directory_name}}/sonar-project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sonar.organization={{ cookiecutter.github_organization }}
22
sonar.projectKey={{ cookiecutter.github_organization }}_{{ cookiecutter.directory_name }}
33
sonar.host.url=https://sonarcloud.io
4-
sonar.sources={{ cookiecutter.package_name }}/
4+
sonar.sources=src/{{ cookiecutter.package_name }}/
55
sonar.tests=tests/
66
sonar.links.homepage={{ cookiecutter.repository_url }}
77
sonar.links.scm={{ cookiecutter.repository }}

{{cookiecutter.directory_name}}/{{cookiecutter.package_name}}/__init__.py renamed to {{cookiecutter.directory_name}}/src/{{cookiecutter.package_name}}/__init__.py

File renamed without changes.

{{cookiecutter.directory_name}}/{{cookiecutter.package_name}}/my_module.py renamed to {{cookiecutter.directory_name}}/src/{{cookiecutter.package_name}}/my_module.py

File renamed without changes.

0 commit comments

Comments
 (0)