Skip to content

Commit cc3613a

Browse files
committed
build-release: Support repos with multiple distribution packages
For repos with multiple distribution packages, they're still released individually by running `build-release` in the directory with the package's pyproject.toml. But if there's no `pactivate` in the current working directory, we look for `../pactivate` and use the shared ../.build/ and its virtualenv. This removes the previous support for giving a subdirectory name, which superficially had a similar effect but didn't actually deal with multiple packages in one .build/release/ dir properly. We might add this back at a later point if we feel it's useful not to have to `cd`. Amongst other changes, this now requires that our logfile names include the name of the distribution package and that when we clean before building we remove only the logfile and package files for this package, not all packages.
1 parent f285f6f commit cc3613a

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ distribution package and releasing it to [PyPI][] (the Python Package
66
Index), whence it can be installed [pip] and similar tools.
77

88
Requirements:
9-
- You must be using a `pyproject.toml` file to define your project
10-
information.
9+
- You must be using a `pyproject.toml` file to define your project information.
1110
- You must have [`pactivate`] present in the same directory as
12-
`pyproject.toml` to build a virtual environment. (You do not actually
13-
need to be using pactivate for your project itself, though of course this
14-
is recommended!)
11+
`pyproject.toml` or in the parent directory. . (You do not actually need
12+
to be using pactivate for your project itself, though of course this is
13+
recommended!)
1514

1615
Currently this is mostly a manual process, but a little bit of it is
1716
automated with the [`build-release`](./build-release) script in this repo.
1817
That script can be run from any location, but it assumes that you're in the
1918
root of your project (i.e., the directory containing the `pyproject.toml`
20-
and `pactivate` files).
19+
file).
20+
21+
The release files will be built under `.build/release/` in the same
22+
directory as `pactivate`. This allows for repos with a single package or
23+
repos with multiple distribution packages, each in a direct subdirectory of
24+
the repo root. (In the latter case you will want to use a tag name that
25+
includes the package name, rather than just `v0.0.0`.)
2126

2227

2328
Release Process
@@ -37,15 +42,10 @@ Release Process
3742

3843
2. Build and check the release.
3944
- Change the current working directory to the project root.
40-
- `build-release` assumes that the Python distribution module source
41-
(i.e., the directory with `pyproject.toml`) is in the current working
42-
directory. If it's in a subdirectory, provide that subdirectory name
43-
_dir_ as a parameter: `build-release DIR`. (The virtualenv and output
44-
files will still be under `.build/` under the CWD.)
45-
- Run `build-release [DIR]`, which will do a few checks of the
46-
configuration (these are far from comprehensive), create/activate the
47-
`pactivate` virtualenv, install `build` and `twine`, and run
48-
`pyproject-build` and `twine check`.
45+
- Run `build-release`, which will do a few checks of the configuration
46+
(these are far from comprehensive), create/activate the `pactivate`
47+
virtualenv, install `build` and `twine`, and run `pyproject-build`
48+
and `twine check`.
4949
- Fix anything broken.
5050

5151
3. Upload the release

build-release

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ while [[ $# -gt 0 ]]; do case "$1" in
2626
-*) die 2 "Unknown option: $1";;
2727
*) break;;
2828
esac; done
29-
[[ $# -eq 0 ]] && packagedir='.'
30-
[[ $# -eq 1 ]] && { packagedir="$1"; shift; }
31-
[[ $# -eq 0 ]] || die 2 "Too many arguments."
29+
[[ $# -gt 0 ]] && die 2 "This program does not accept arguments."
3230

3331
####################################################################
3432
# Configuration validation
3533

36-
[[ -r $packagedir/pyproject.toml ]] \
37-
|| die 1 "$packagedir/pyproject.toml not found"
38-
if grep '^version = ' "$packagedir/pyproject.toml" | grep -q dev; then
34+
[[ -r pyproject.toml ]] || die 1 'pyproject.toml not found'
35+
if grep '^version = ' pyproject.toml | grep -q dev; then
3936
if $allow_dev; then
4037
warn 'pyproject.toml version number includes "dev"'
4138
else
@@ -48,20 +45,37 @@ fi
4845
####################################################################
4946
# Release process
5047

51-
reldir=$(pwd -L)/.build/release
52-
5348
echo '• pactivate'
54-
. ./pactivate -q
55-
pip -q install build twine
56-
rm -rf "$reldir"; mkdir -p "$reldir/dist"
49+
if [[ -r pactivate ]]; then
50+
reldir=.build/release
51+
. ./pactivate -q
52+
elif [[ -r ../pactivate ]]; then
53+
reldir=../.build/release
54+
. ../pactivate -q
55+
else
56+
die 3 "Cannot find pactivate or ../pactivate"
57+
fi
58+
pip -q install build twine toml
59+
60+
package_name=$(python3 -c '
61+
import toml;
62+
data = toml.load("pyproject.toml");
63+
print(data["project"]["name"])
64+
')
65+
logfile="$package_name-build.log"
5766

58-
echo "• pyproject-build (output to $reldir/build.log)"
59-
pyproject-build >"$reldir/build.log" --outdir "$reldir/dist/" "$packagedir"
67+
echo '• cleaning previous builds'
68+
mkdir -p "$reldir/dist"
69+
rm -f "$reldir/$package_name"* "$reldir/dist/$package_name"*
70+
71+
echo "• pyproject-build (output to $reldir/$logfile)"
72+
pyproject-build --outdir "$reldir/dist/" >"$reldir/$logfile"
6073

6174
echo '• twine check'
6275
twine check --strict "$reldir/dist"/*
6376
if $upload; then
6477
echo '• twine upload'
6578
twine upload "$reldir/dist"/*
6679
fi
80+
6781
echo '• OK'

0 commit comments

Comments
 (0)