Skip to content

Commit 9639e2c

Browse files
Pull version from VCS to simplify release and build dynamic docs via mkdocs plugin (#1130)
Co-authored-by: Jason Lam <meowmeowcat1211@gmail.com>
1 parent 28ffb99 commit 9639e2c

16 files changed

+242
-512
lines changed

.github/workflows/tests.yml

Lines changed: 74 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: tests
22

33
on:
4+
workflow_dispatch:
45
push:
56
pull_request:
67
schedule:
@@ -41,12 +42,26 @@ jobs:
4142
- name: Install nox
4243
run: python -m pip install nox
4344
- name: Execute Tests
44-
run: nox --non-interactive --session tests-${{ matrix.python-version }}
45+
run: nox --error-on-missing-interpreters --non-interactive --session tests-${{ matrix.python-version }}
46+
man:
47+
name: Build man page
48+
runs-on: ubuntu-latest
49+
steps:
50+
- uses: actions/checkout@v4
51+
- name: Set up Python ${{ env.default-python }}
52+
uses: actions/setup-python@v4
53+
with:
54+
python-version: ${{ env.default-python }}
55+
cache: "pip"
56+
- name: Install nox
57+
run: python -m pip install nox
58+
- name: Build man page
59+
run: nox --error-on-missing-interpreters --non-interactive --session build_man
60+
- name: Show man page
61+
run: man -l pipx.1
4562

46-
pypi-publish:
47-
name: Publish pipx to PyPI on release
48-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
49-
needs: [tests]
63+
zipapp:
64+
name: Build zipapp
5065
runs-on: ubuntu-latest
5166
steps:
5267
- name: Checkout ${{ github.ref }}
@@ -58,19 +73,26 @@ jobs:
5873
cache: "pip"
5974
- name: Install nox
6075
run: pip install nox
61-
- name: Build sdist and wheel
62-
run: nox --error-on-missing-interpreters --non-interactive --session build
63-
- name: Publish to PyPi
64-
uses: pypa/gh-action-pypi-publish@v1.8.11
76+
- name: Build zipapp
77+
run: nox --error-on-missing-interpreters --non-interactive --session zipapp
78+
- name: Test zipapp by installing black
79+
run: python ./pipx.pyz install black
80+
- uses: actions/upload-artifact@v3
6581
with:
66-
user: __token__
67-
password: ${{ secrets.pypi_password }}
82+
name: pipx.pyz
83+
path: pipx.pyz
84+
retention-days: 3
6885

69-
build-zipapp:
70-
name: Build zipapp
86+
pypi-publish:
87+
name: Publish pipx to PyPI on release
7188
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
72-
needs: [tests]
89+
needs: [tests, man, zipapp]
7390
runs-on: ubuntu-latest
91+
environment:
92+
name: release
93+
url: https://pypi.org/p/pipx
94+
permissions:
95+
id-token: write
7496
steps:
7597
- name: Checkout ${{ github.ref }}
7698
uses: actions/checkout@v4
@@ -79,15 +101,44 @@ jobs:
79101
with:
80102
python-version: ${{ env.default-python }}
81103
cache: "pip"
82-
- name: Install shiv
83-
run: pip install shiv
84-
- name: Build zipapp
85-
run: shiv -c pipx -o ./pipx.pyz git+https://github.com/pypa/pipx@${{ github.ref_name }}
86-
- name: Show zipapp version
87-
run: python ./pipx.pyz --version
88-
- name: Test zipapp by installing black
89-
run: python ./pipx.pyz install black
90-
- name: Upload to releases
104+
- name: Install nox
105+
run: pip install nox
106+
- name: Build sdist and wheel
107+
run: nox --error-on-missing-interpreters --non-interactive --session build
108+
- name: Publish to PyPi
109+
uses: pypa/gh-action-pypi-publish@v1.8.11
110+
111+
upload-zipapp:
112+
name: Upload zipapp to GitHub Release on release
113+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
114+
needs: [tests, man, zipapp]
115+
runs-on: ubuntu-latest
116+
steps:
117+
- uses: actions/download-artifact@v3
118+
with:
119+
name: pipx.pyz
120+
- name: Upload to release
91121
uses: softprops/action-gh-release@v1
92122
with:
93123
files: pipx.pyz
124+
125+
bump-changelog:
126+
name: Bump changelog on release
127+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
128+
needs: [pypi-publish, upload-zipapp]
129+
runs-on: ubuntu-latest
130+
permissions:
131+
contents: write
132+
steps:
133+
- name: Checkout ${{ github.ref }}
134+
uses: actions/checkout@v4
135+
- name: Extract release tag
136+
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
137+
- name: Update changelog
138+
run: echo -e "## dev\n\n## $RELEASE_VERSION\n$(tail -n +2 CHANGELOG.md)" > CHANGELOG.md
139+
- name: Commit and push change
140+
run: |
141+
git config --global user.name 'Github Actions'
142+
git config --global user.email 'gh-action@users.noreply.github.com'
143+
git commit -am "Bump changelog for $RELEASE_VERSION"
144+
git push

.gitignore

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
/.nox/
2-
/.coverage
3-
*egg*
4-
.mypy_cache
5-
.vscode
6-
build
7-
dist
8-
activate
9-
__pypackages__
10-
venv
11-
.venv
12-
.DS_Store
13-
.tox
1+
/.*_cache
2+
/build
3+
/dist
4+
/src/pipx/version.py
5+
/noxfile.py
6+
/.nox
7+
*.py[co]
148
__pycache__
15-
site
16-
docs/docs.md
17-
pipx.1
18-
.pipx_tests
9+
/site
1910
/.coverage*
20-
/testdata
21-
!/testdata/empty_project
22-
/.idea
11+
/.pipx_tests
12+
/testdata/tests_packages/*.txt
13+
/pipx.pyz
14+
*.egg-info
15+
build
16+
*.whl
17+
/pipx.1

.pre-commit-config.yaml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# See https://pre-commit.com for more information
2-
# See https://pre-commit.com/#installation for installation instructions
3-
# See https://pre-commit.com/hooks.html for more hooks
4-
#
5-
# use `git commit --no-verify` to disable git hooks for this commit
6-
71
repos:
82
- repo: https://github.com/pre-commit/pre-commit-hooks
93
rev: v4.5.0
@@ -22,15 +16,15 @@ repos:
2216
- id: ruff-format
2317
- id: ruff
2418
args: [ "--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
25-
# mypy args:
26-
# must include --ignore-missing-imports for mypy. It is included by default
27-
# if no arguments are supplied, but we must supply it ourselves since we
28-
# specify args
29-
# cannot use --warn-unused-ignores because it conflicts with
30-
# --ignore-missing-imports
3119
- repo: https://github.com/pre-commit/mirrors-mypy
3220
rev: v1.7.1
3321
hooks:
3422
- id: mypy
3523
args: ['--warn-unused-ignores', '--strict-equality','--no-implicit-optional', '--check-untyped-defs']
3624
exclude: 'testdata/test_package_specifier/local_extras/setup.py'
25+
additional_dependencies:
26+
- "mkdocs-gen-files"
27+
- "nox"
28+
- "packaging>=20"
29+
- "platformdirs>=2.1"
30+
- "tomli; python_version < '3.11'"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## dev
22

3+
- The project version number is now dynamic and generated from the VCS at build time
34
- [docs] Add additonal example for --pip-args option, to docs/examples.md
45

56
## 1.3.1

CONTRIBUTING.md

Lines changed: 16 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,6 @@ To run the pipx executable from your source tree during development, run pipx fr
1111
python src/pipx --version
1212
```
1313

14-
## Pre-commit
15-
16-
The use of [pre-commit](https://pre-commit.com/) is recommended. It can show all and fix some lint errors before commit,
17-
saving you the trouble of finding out later that it failed CI Lint errors, and saving you from having to run
18-
`nox -s lint` separately.
19-
20-
In the pipx git repository is a `.pre-commit-config.yaml` configuration file tailored just for pipx and its lint
21-
requirements. To use pre-commit in your clone of the pipx repository, you need to do the following **one-time setup
22-
procedure**:
23-
24-
1. Install pre-commit using `pipx install pre-commit`
25-
2. In the top level directory of your clone of the pipx repository, execute `pre-commit install`
26-
27-
Afterwards whenever you commit in this repository, it will first run pipx's personalized lint checks. If it makes a fix
28-
to a file (e.g. using `black` or `isort`), you will need to `git add` that file again before committing it again. If it
29-
can't fix your commit itself, it will tell you what's wrong, and you can fix it manually before re-adding the edited
30-
files and committing again.
31-
32-
If for some reason you want to commit and skip running pre-commit, you can use the switch `git commit --no-verify`.
33-
3414
## Running Tests
3515

3616
### Setup
@@ -88,15 +68,18 @@ At the time of this writing, the output looks like this
8868
* build_docs
8969
- watch_docs
9070
* build_man
91-
- pre_release
92-
- post_release
9371
- create_test_package_list-3.12
9472
- create_test_package_list-3.11
9573
- create_test_package_list-3.10
9674
- create_test_package_list-3.9
9775
- create_test_package_list-3.8
9876
```
9977

78+
### Creating a developer environment
79+
80+
For developing the tool (and to attach to your IDE) we recommend creating a Python environment via
81+
`nox -s develop-3.12`, afterwards use the Python interpreter available under `.nox/develop-3.12/bin/python`.
82+
10083
### Unit Tests
10184

10285
To run unit tests in Python3.12, you can run
@@ -123,13 +106,13 @@ nox -s tests-3.12
123106

124107
Running the unit tests requires a directory `.pipx_tests/package_cache` to be populated from a fixed list of package
125108
distribution files (wheels or source files). If you have network access, `nox -s tests` automatically makes sure this
126-
directory is populated (including downloading files if necessary) as a first step. Thus if you are running the tests
109+
directory is populated (including downloading files if necessary) as a first step. Thus, if you are running the tests
127110
with network access, you can ignore the rest of this section.
128111

129112
If, however, you wish to run tests offline without the need for network access, you can populate
130113
`.pipx_tests/package_cache` yourself manually beforehand when you do have network access.
131114

132-
#### Populating the cache directory using nox
115+
### Populating the cache directory using nox
133116

134117
To populate `.pipx_tests/package_cache` manually using nox, execute:
135118

@@ -140,19 +123,10 @@ nox -s refresh_packages_cache
140123
This will sequence through available python executable versions to populate the cache directory for each version of
141124
python on your platform.
142125

143-
#### Populating the cache directory without nox
144-
145-
An alternate method to populate `.pipx_tests/package_cache` without nox is to execute:
146-
147-
```
148-
mkdir -p .pipx_tests/package_cache
149-
python3 scripts/update_package_cache.py testdata/tests_packages .pipx_tests/package_cache
150-
```
151-
152-
You must do this using every python version that you wish to use to run the tests.
153-
154126
### Lint Tests
155127

128+
Linting is done via `pre-commit`, setting it up and running it can be done via `nox` by typing:
129+
156130
```
157131
nox -s lint
158132
```
@@ -181,16 +155,13 @@ Finally, check-in the new or modified list files in the directory `testdata/test
181155

182156
## Testing pipx on Continuous Integration builds
183157

184-
When you push a new git branch, tests will automatically be run against your code as defined in
185-
`.github/workflows/on-push.yml`.
158+
Upon opening pull requests GitHub Actions will automatically trigger.
186159

187160
## Building Documentation
188161

189162
`pipx` autogenerate API documentation, and also uses templates.
190163

191-
When updating pipx docs, make sure you are either modifying a file in the `templates` directory, or the `docs`
192-
directory. If in the `docs` directory, make sure the file was not autogenerated from the `templates` directory.
193-
Autogenerated files have a note at the top of the file.
164+
When updating pipx docs, make sure you are modifying the `docs` directory.
194165

195166
You can generate the documentation with
196167

@@ -207,44 +178,12 @@ To preview changes, including live reloading, open another terminal and run
207178
nox -s watch_docs
208179
```
209180

210-
### Publishing Doc Changes to GitHub pages
211-
212-
```
213-
nox -s publish_docs
214-
```
215-
216181
## Releasing New `pipx` Versions
217182

218-
### Pre-release
219-
220-
First, make sure the changelog is complete. Next decide what the next version number will be. Then, from a clone of the
221-
main pypa pipx repo (not a fork) execute:
222-
223-
```
224-
nox -s pre_release
225-
```
226-
227-
Enter the new version number when asked. When the script is finished, check the diff it produces. If the diff looks
228-
correct, commit the changes as the script instructs, and push the result.
229-
230-
The script will modify `src/pipx/version.py` to contain the new version, and also update the changelog
231-
(`docs/changelog.md`) to specify the new version.
232-
233-
### Release
234-
235-
To publish to PyPI simply create a "published" release on Github. This will trigger Github workflows that both publish
236-
the pipx version to PyPI and publish the pipx documentation to the pipx website.
237-
238-
### Post-release
239-
240-
From a clone of the main pypa pipx repo (not a fork) execute:
241-
242-
```
243-
nox -s post_release
244-
```
183+
To publish to PyPI simply create a "published" release on GitHub. This will trigger GitHub workflows that publishes:
245184

246-
When the script is finished, check the diff it produces. If the diff looks correct, commit the changes as the script
247-
instructs, and push the result.
185+
- the pipx version to PyPI,
186+
- the documentation to readthedocs,
187+
- the `zipapp` to the GitHub release created.
248188

249-
This will update pipx's version in `src/pipx/version.py` by adding a suffix `"dev0"` for unreleased development, and
250-
will update the changelog to start a new section at the top entitled `dev`.
189+
No need for any other pre or post publish steps.

mkdocs.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ nav:
4040

4141
markdown_extensions:
4242
- admonition # note blocks, warning blocks -- https://github.com/mkdocs/mkdocs/issues/1659
43+
44+
plugins:
45+
- search:
46+
lang: en
47+
enabled: true
48+
- gen-files:
49+
scripts:
50+
- scripts/gen_doc_pages.py

0 commit comments

Comments
 (0)