Skip to content

Commit 4020114

Browse files
authored
Merge pull request #358 from NLeSC/345_build_module
2 parents 0f699f7 + 0635bcd commit 4020114

6 files changed

Lines changed: 23 additions & 31 deletions

File tree

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ my-python-project/
135135
├── pyproject.toml
136136
├── README.dev.md
137137
├── README.md
138-
├── setup.cfg
139-
├── setup.py
140138
├── sonar-project.properties
141139
└── tests
142140
├── __init__.py

tests/test_project.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_tox(baked_with_development_dependencies, project_env_bin_dir):
8080

8181

8282
def test_subpackage(baked_with_development_dependencies, project_env_bin_dir):
83-
"""Test if subpackages end up in sdist and bdist_wheel distributions"""
83+
"""Test if subpackages end up in (wheel) distributions"""
8484
project_dir = baked_with_development_dependencies
8585
bin_dir = project_env_bin_dir
8686
subpackage = (project_dir / 'my_python_package' / 'mysub')
@@ -91,9 +91,14 @@ def test_subpackage(baked_with_development_dependencies, project_env_bin_dir):
9191
subsubpackage.mkdir()
9292
(subsubpackage / '__init__.py').write_text('FOO = "bar"\n', encoding="utf-8")
9393

94-
# sdist and bdist_wheel both call build command to create build/ dir
95-
# So instead of looking in distribution archives we can look in build/ dir
96-
result = run([f'{bin_dir}python', '-m', 'build', '--sdist', '--wheel'], project_dir)
94+
# Note: we pass --wheel explicitly, because wheel has a useful side-effect
95+
# of leaving a build directory after building that we can check for its
96+
# contents in the asserts below. However, be aware that this behavior is
97+
# not guaranteed to stay and is in fact a known bug / PEP-violation!
98+
# See https://github.com/pypa/wheel/issues/447. Also, by passing --wheel
99+
# explicitly (although by default build already builds a wheel as well),
100+
# we omit the sdist being built, saving some seconds.
101+
result = run([f'{bin_dir}python', '-m', 'build', '--wheel'], project_dir)
97102
assert result.returncode == 0
98103
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / '__init__.py').exists()
99104
assert (project_dir / 'build' / 'lib' / 'my_python_package' / 'mysub' / 'mysub2' / '__init__.py').exists()

{{cookiecutter.directory_name}}/.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
- name: Run unit tests
3737
run: python -m pytest -v
3838
- name: Verify that we can build the package
39-
run: python setup.py sdist bdist_wheel
39+
run: python -m build
4040

4141
lint:
4242
name: Linting build

{{cookiecutter.directory_name}}/.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v2
1919
- name: Set up Python 3.9
20-
uses: actions/setup-python@v2
20+
uses: actions/setup-python@v3
2121
with:
2222
python-version: 3.9
2323
- name: Python info

{{cookiecutter.directory_name}}/README.dev.md

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -138,35 +138,23 @@ This section describes how to make a release in 3 parts:
138138

139139
### (2/3) PyPI
140140

141-
In a new terminal, without an activated virtual environment or an env directory:
141+
In a new terminal:
142142

143143
```shell
144-
# prepare a new directory
144+
# OPTIONAL: prepare a new directory with fresh git clone to ensure the release
145+
# has the state of origin/main branch
145146
cd $(mktemp -d {{ cookiecutter.package_name }}.XXXXXX)
146-
147-
# fresh git clone ensures the release has the state of origin/main branch
148147
git clone {{ cookiecutter.repository }} .
149148

150-
# prepare a clean virtual environment and activate it
151-
python -m venv env
152-
source env/bin/activate
153-
154-
# make sure to have a recent version of pip and setuptools
155-
python -m pip install --upgrade pip setuptools
156-
157-
# install runtime dependencies and publishing dependencies
158-
python -m pip install --no-cache-dir .
159-
python -m pip install --no-cache-dir .[publishing]
160-
161-
# clean up any previously generated artefacts
162-
rm -rf {{ cookiecutter.package_name }}.egg-info
163-
rm -rf dist
149+
# make sure to have a recent version of pip and the publishing dependencies
150+
python -m pip install --upgrade pip
151+
python -m pip install .[publishing]
164152

165153
# create the source distribution and the wheel
166-
python setup.py sdist bdist_wheel
154+
python -m build
167155

168156
# upload to test pypi instance (requires credentials)
169-
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
157+
python -m twine upload --repository testpypi dist/*
170158
```
171159

172160
Visit
@@ -183,7 +171,7 @@ python -m venv env
183171
source env/bin/activate
184172

185173
# make sure to have a recent version of pip and setuptools
186-
python -m pip install --upgrade pip setuptools
174+
python -m pip install --upgrade pip
187175

188176
# install from test pypi instance:
189177
python -m pip -v install --no-cache-dir \
@@ -198,7 +186,7 @@ Then upload to pypi.org with:
198186
```shell
199187
# Back to the first terminal,
200188
# FINAL STEP: upload to PyPI (requires credentials)
201-
twine upload dist/*
189+
python -m twine upload dist/*
202190
```
203191

204192
### (3/3) GitHub

{{cookiecutter.directory_name}}/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ version = "{{ cookiecutter.version }}"
4343

4444
[project.optional-dependencies]
4545
dev = [
46-
"build",
46+
"build", # build is not only used in publishing (below), but also in the template's test suite
4747
"bump2version",
4848
"coverage [toml]",
4949
"pytest",
@@ -56,6 +56,7 @@ dev = [
5656
"myst_parser",
5757
]
5858
publishing = [
59+
"build",
5960
"twine",
6061
"wheel",
6162
]

0 commit comments

Comments
 (0)