Skip to content

Commit 60017f5

Browse files
authored
Merge pull request #13 from openscm/8-src-dist-issues
1. Included the `locked` targets in releases 2. Stripped out all superfluous files from the source distribution and check that the package can be installed from the source distribution alone
2 parents 6816e6c + 33b1826 commit 60017f5

File tree

8 files changed

+101
-4
lines changed

8 files changed

+101
-4
lines changed

.github/workflows/bump.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,25 @@ jobs:
5151
5252
# Bump
5353
uv version --no-sync --bump ${{ github.event.inputs.bump_rule }}
54+
# Create a copy of pyproject.toml which we can use for restoring
55+
cp pyproject.toml pyproject-dev.toml
5456
5557
NEW_VERSION=`sed -ne 's/^version = "\([0-9\.]*\)"/\1/p' pyproject.toml`
5658
echo "Bumping to version $NEW_VERSION"
5759
5860
# Build CHANGELOG
5961
uv run --no-sync towncrier build --yes --version v$NEW_VERSION
62+
# Add locked targets to pyproject.toml
63+
uv run --no-sync python scripts/add-locked-targets-to-pyproject-toml.py
64+
# Propogate new version to meson.build
65+
uv run --no-sync python scripts/propogate-pyproject-metadata.py
66+
67+
# Lock everything again
68+
git add .
69+
uv run --no-sync pre-commit run --all-files
70+
uv sync --no-editable --all-extras --group all-dev
71+
git add .
72+
uv run --no-sync pre-commit run --all-files
6073
6174
# Commit, tag and push
6275
git commit -a -m "bump: version $BASE_VERSION -> $NEW_VERSION"
@@ -67,8 +80,12 @@ jobs:
6780
# version as the tagged commit)
6881
BASE_VERSION=`sed -ne 's/^version = "\([0-9\.]*\)"/\1/p' pyproject.toml`
6982
83+
# Put pyproject.toml back
84+
mv pyproject-dev.toml pyproject.toml
7085
# Bump to pre-release of next version
7186
uv version --no-sync --bump post
87+
# Propogate dev version back to meson.build
88+
uv run --no-sync python scripts/propogate-pyproject-metadata.py
7289
7390
NEW_VERSION=`sed -ne 's/^version = "\([0-9\.post]*\)"/\1/p' pyproject.toml`
7491
echo "Bumping version $BASE_VERSION > $NEW_VERSION"

.github/workflows/ci.yaml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,22 @@ jobs:
232232
run: |
233233
uv run --no-sync python scripts/add-locked-targets-to-pyproject-toml.py
234234
cat pyproject.toml
235-
uv build
235+
uv build --sdist
236236
# Just in case, undo the changes to `pyproject.toml`
237237
git restore --staged . && git restore .
238-
- name: Check build
238+
- name: Check included files in source distribution
239239
run: |
240240
tar -tvf dist/example_fgen_basic-*.tar.gz --wildcards '*example_fgen_basic/py.typed'
241241
tar -tvf dist/example_fgen_basic-*.tar.gz --wildcards 'example_fgen_basic-*/LICENCE'
242+
- name: Check source distribution can be used for installation
243+
run: |
244+
cd dist
245+
ls
246+
python3 -m venv venv
247+
# TODO: alter for windows
248+
source venv/bin/activate
249+
pip install example_fgen_basic*
250+
python -c 'from example_fgen_basic.get_wavelength import get_wavelength_plain; print(get_wavelength_plain(23.4))'
242251
243252
check-dependency-licences:
244253
strategy:

.github/workflows/deploy.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ jobs:
3434
uv-dependency-install-flags: "--all-extras --group dev"
3535
- name: Publish to PyPI
3636
run: |
37-
uv run --no-sync python scripts/add-locked-targets-to-pyproject-toml.py
3837
# TODO: move to using cibuildwheel so we have wheels for multiple platforms and python versions
3938
# starting docs: https://cibuildwheel.pypa.io/en/stable/
4039
uv build --sdist

.github/workflows/release.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
echo "PROJECT_VERSION=$PROJECT_VERSION" >> $GITHUB_ENV
3232
- name: Build package for PyPI
3333
run: |
34-
uv run --no-sync python scripts/add-locked-targets-to-pyproject-toml.py
3534
uv build
3635
# Just in case, undo the changes to `pyproject.toml`
3736
git restore --staged . && git restore .

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Dev copy of pyproject.toml used in CI
2+
pyproject-dev.toml
3+
14
# Local install dir
25
install-example
36

changelog/13.fix.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fixed building:
2+
3+
- now include the `locked` targets in releases
4+
- stripped out all superfluous files from the source distribution and check that the package can be installed from the source distribution alone

meson.build

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ if pyprojectwheelbuild_enabled
142142

143143
endforeach
144144

145+
# dist - script to reduce the *tar.gz
146+
meson.add_dist_script(py, files('scripts' / 'strip-sdist.py'))
147+
145148
else
146149
## Fortran library standalone compilation
147150

scripts/strip-sdist.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""
2+
Script file to strip unwanted files from dist tarball
3+
"""
4+
5+
import os
6+
import shutil
7+
from pathlib import Path
8+
9+
10+
def main():
11+
"""
12+
Strip the files we don't want in the tarball
13+
"""
14+
dist_root = os.environ.get("MESON_DIST_ROOT")
15+
16+
# Files/Folders to strip from the *.tar.gz
17+
exclude = [
18+
".github",
19+
"docs",
20+
"tests",
21+
"changelog",
22+
"stubs",
23+
Path("scripts") / "add-locked-targets-to-pyproject-toml.py",
24+
Path("scripts") / "inject-srcs-into-meson-build.py",
25+
Path("scripts") / "propogate-pyproject-metadata.py",
26+
Path("scripts") / "test-install.py",
27+
Path("scripts") / "changelog-to-release-template.py",
28+
Path("scripts") / "print-conda-recipe-pins.py",
29+
# Keep this one
30+
# Path("scripts") / "strip-sdist.py",
31+
".pre-commit-config.yaml",
32+
".gitignore",
33+
".readthedocs.yaml",
34+
"Makefile",
35+
"environment-docs-conda-base.yml",
36+
"mkdocs.yml",
37+
"uv.lock",
38+
"requirements-docs-locked.txt",
39+
"requirements-incl-optional-locked.txt",
40+
"requirements-locked.txt",
41+
"requirements-only-tests-locked.txt",
42+
"requirements-only-tests-min-locked.txt",
43+
"requirements-upstream-dev.txt",
44+
".copier-answers.yml",
45+
".fprettify.rc",
46+
]
47+
48+
# Strip
49+
for path in exclude:
50+
abs_path = os.path.join(dist_root, path)
51+
if not os.path.exists(abs_path):
52+
msg = f"File not found: {abs_path}"
53+
raise FileNotFoundError(msg)
54+
55+
if os.path.isdir(abs_path):
56+
shutil.rmtree(abs_path)
57+
58+
elif os.path.isfile(abs_path):
59+
os.remove(abs_path)
60+
61+
62+
if __name__ == "__main__":
63+
main()

0 commit comments

Comments
 (0)