Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move generated package to src/ layout #374

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

### Changed

* Moved to src/ based layout for generated packages
* Moved from setup.cfg/.py to pyproject.toml [#351](https://github.com/NLeSC/python-template/issues/351)
* Moved from prospector to ruff [#336](https://github.com/NLeSC/python-template/issues/336)
* Renamed `project_name` to `directory_name` in cookiecutter questionnaire
Expand Down
44 changes: 21 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,6 @@ Good job! You have now generated the skeleton for your package:

```text
my-python-project/
├── CHANGELOG.md
├── CITATION.cff
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── docs
│ ├── conf.py
│ ├── index.rst
│ ├── make.bat
│ ├── Makefile
│ ├── _static
│ │ └── theme_overrides.css
│ └── _templates
│ └── .gitignore
├── .editorconfig
├── .githooks
│ └── pre-commit
Expand All @@ -115,26 +102,37 @@ my-python-project/
│ └── workflows
│ ├── build.yml
│ ├── cffconvert.yml
│ ├── lint.yml
│ ├── documentation.yml
│ ├── markdown-link-check.yml
│ ├── next_steps.yml
│ └── sonarcloud.yml
├── .gitignore
├── .mlc-config.json
├── .readthedocs.yaml
├── CHANGELOG.md
├── CITATION.cff
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── MANIFEST.in
├── .mlc-config.json
├── my_python_package
│ ├── __init__.py
│ ├── my_module.py
│ └── __version__.py
├── next_steps.md
├── NOTICE
├── project_setup.md
├── .pylintrc
├── pyproject.toml
├── README.dev.md
├── README.md
├── docs
│ ├── Makefile
│ ├── _templates
│ │ └── .gitignore
│ ├── conf.py
│ ├── index.rst
│ └── make.bat
├── next_steps.md
├── project_setup.md
├── pyproject.toml
├── sonar-project.properties
├── src
│ └── my_python_package
│ ├── __init__.py
│ └── my_module.py
└── tests
├── __init__.py
└── test_my_module.py
Expand Down
8 changes: 4 additions & 4 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def test_subpackage(baked_with_development_dependencies, project_env_bin_dir):
"""Test if subpackages end up in (wheel) distributions"""
project_dir = baked_with_development_dependencies
bin_dir = project_env_bin_dir
subpackage = (project_dir / 'my_python_package' / 'mysub')
subpackage = (project_dir / 'src' / 'my_python_package' / 'mysub')
subpackage.mkdir()
(subpackage / '__init__.py').write_text('FOO = "bar"\n', encoding="utf-8")

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

Expand Down Expand Up @@ -179,7 +179,7 @@ def test_bumpversion(baked_with_development_dependencies, project_env_bin_dir):
original_version = '0.1.0'
assert original_version in (project_dir / 'pyproject.toml').read_text('utf-8')
assert original_version in (project_dir / 'CITATION.cff').read_text('utf-8')
assert original_version in (project_dir / 'my_python_package' / '__init__.py').read_text('utf-8')
assert original_version in (project_dir / 'src' / 'my_python_package' / '__init__.py').read_text('utf-8')
assert original_version in (project_dir / 'docs' / 'conf.py').read_text('utf-8')

result = run([f'{bin_dir}bump-my-version', 'major'], project_dir)
Expand All @@ -188,5 +188,5 @@ def test_bumpversion(baked_with_development_dependencies, project_env_bin_dir):
expected_version = '1.0.0'
assert expected_version in (project_dir / 'pyproject.toml').read_text('utf-8')
assert expected_version in (project_dir / 'CITATION.cff').read_text('utf-8')
assert expected_version in (project_dir / 'my_python_package' / '__init__.py').read_text('utf-8')
assert expected_version in (project_dir / 'src' / 'my_python_package' / '__init__.py').read_text('utf-8')
assert expected_version in (project_dir / 'docs' / 'conf.py').read_text('utf-8')
2 changes: 1 addition & 1 deletion {{cookiecutter.directory_name}}/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

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

autoapi_dirs = ['../{{ cookiecutter.package_name }}']
autoapi_dirs = ['../src/{{ cookiecutter.package_name }}']

# -- Options for HTML output ----------------------------------------------

Expand Down
11 changes: 3 additions & 8 deletions {{cookiecutter.directory_name}}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,17 @@ testpaths = ["tests"]

[tool.coverage.run]
branch = true
source = ["{{ cookiecutter.package_name }}"]
source = ["src/{{ cookiecutter.package_name }}"]
command_line = "-m pytest"

[tool.isort]
lines_after_imports = 2
force_single_line = 1
no_lines_before = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
known_first_party = "{{ cookiecutter.package_name }}"
src_paths = ["{{ cookiecutter.package_name }}", "tests"]
src_paths = ["src/{{ cookiecutter.package_name }}", "tests"]
line_length = 120

# For completeness, until we move to an src-based layout
[tool.setuptools.packages.find]
include = ["{{ cookiecutter.package_name }}*"]
exclude = ["tests*"]

[tool.tox]
legacy_tox_ini = """
[tox]
Expand Down Expand Up @@ -177,7 +172,7 @@ no-lines-before = ["future","standard-library","third-party","first-party","loca
current_version = "{{ cookiecutter.version }}"

[[tool.bumpversion.files]]
filename = "{{ cookiecutter.package_name }}/__init__.py"
filename = "src/{{ cookiecutter.package_name }}/__init__.py"

[[tool.bumpversion.files]]
filename = "pyproject.toml"
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.directory_name}}/sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sonar.organization={{ cookiecutter.github_organization }}
sonar.projectKey={{ cookiecutter.github_organization }}_{{ cookiecutter.directory_name }}
sonar.host.url=https://sonarcloud.io
sonar.sources={{ cookiecutter.package_name }}/
sonar.sources=src/{{ cookiecutter.package_name }}/
sonar.tests=tests/
sonar.links.homepage={{ cookiecutter.repository_url }}
sonar.links.scm={{ cookiecutter.repository }}
Expand Down
Cmurilochem marked this conversation as resolved.
Show resolved Hide resolved
File renamed without changes.
Loading