Skip to content

Commit 102d93c

Browse files
authored
hatch-vcs-tunable: feat: new project (#1)
The hatch-vcs-tunable hook allows you to override settings passed to hatch_vcs (and to setuptools_scm from there) via environment variables, useful when working on a project that has multiple release tracks with different versions.
1 parent 0dfe66a commit 102d93c

22 files changed

+927
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
on:
2+
pull_request_target:
3+
types:
4+
- opened
5+
- synchronized
6+
7+
jobs:
8+
which-paths:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
HATCH_VCS_TUNABLE_DIFF: ${{ steps.hatch-vcs-tunable-diff.outputs.HATCH_VCS_TUNABLE_DIFF }}
12+
steps:
13+
- name: Fetch repo for diffing
14+
uses: actions/checkout@v3
15+
- name: Check if vcs-tunable-analysis changed
16+
uses: actions/get-diff-action@v6
17+
with:
18+
PATTERNS: |
19+
+hatch-vcs-tunable/**/*
20+
+.github/workflows/pull-request.yml
21+
- name: Set diff output for hatch-vcs-tunable
22+
id: hatch-vcs-tunable-diff
23+
run: |
24+
echo "HATCH_VCS_TUNABLE_DIFF=${GIT_DIFF_FILTERED}" >> $GITHUB_OUTPUT
25+
hatch-vcs-tunable-analysis:
26+
runs-on: ubuntu-latest
27+
needs: [which-paths]
28+
if: ${{ needs.which-paths.outputs.HATCH_VCS_TUNABLE_DIFF }}
29+
steps:
30+
- name: Ask for news fragments
31+
if: ${{ !contains(needs.which-paths.outputs.HATCH_VCS_TUNABLE_DIFF, changelog.d) }}
32+
run: |
33+
echo 'Please add a news fragment for your change.'
34+
exit 1

.github/workflows/pull-request.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
on:
2+
pull_request:
3+
types:
4+
- opened
5+
- synchronized
6+
7+
jobs:
8+
which-paths:
9+
runs-on: ubuntu-latest
10+
outputs:
11+
HATCH_VCS_TUNABLE_DIFF: ${{ steps.hatch-vcs-tunable-diff.outputs.HATCH_VCS_TUNABLE_DIFF }}
12+
MANAGEMENT_DIFF: ${{ steps.management-diff.outputs.MANAGEMENT_DIFF }}
13+
steps:
14+
- name: Fetch repo for diffing
15+
uses: actions/checkout@v3
16+
- name: Check if vcs-tunable-analysis changed
17+
uses: actions/get-diff-action@v6
18+
with:
19+
PATTERNS: |
20+
+hatch-vcs-tunable/**/*
21+
+.github/workflows/pull-request.yml
22+
- name: Set diff output for hatch-vcs-tunable
23+
id: hatch-vcs-tunable-diff
24+
run: |
25+
echo "HATCH_VCS_TUNABLE_DIFF=${GIT_DIFF_FILTERED}" >> $GITHUB_OUTPUT
26+
- name: Check if repo management changed
27+
uses: actions/get-diff-action@v6
28+
with:
29+
PATTERNS: |
30+
-hatch-vcs-tunable/**/*
31+
- name: Set diff output for management
32+
id: management-diff
33+
run: |
34+
echo MANAGEMENT_DIFF=${GIT_DIFF_FILTERED}" >> $GITHUB_OUTPUT
35+
36+
hatch-vcs-tunable-analysis:
37+
if: ${{ needs.which-paths.outputs.HATCH_VCS_TUNABLE_DIFF }}
38+
runs-on: ubuntu-latest
39+
needs: [which-paths]
40+
steps:
41+
- name: Install python
42+
uses: actions/setup-python@v5
43+
with:
44+
python-version: 3.10
45+
- name: Set up python environment
46+
run: |
47+
python -m install pipx
48+
pipx install hatch
49+
- name: Fetch repo
50+
uses: actions/checkout@v3
51+
- name: Create default env
52+
run: hatch env create default
53+
working-directory: hatch-vcs-tunable
54+
- name: Check formatting
55+
run: hatch run format --check
56+
working-directory: hatch-vcs-tunable
57+
- name: Lint
58+
run: hatch run lint
59+
working-directory: hatch-vcs-tunable
60+
- name: Check types
61+
run: hatch run check
62+
- name: Quick tests
63+
run: hatch run test
64+
65+
hatch-vcs-tunable-tests:
66+
if: ${{ needs.which-paths.outputs.HATCH_VCS_TUNABLE_DIFF }}
67+
needs: [which-paths, hatch-vcs-tunable-analysis]
68+
runs-on: ${{ matrix.env }}
69+
strategy:
70+
fail-fast: true
71+
matrix:
72+
os: [ubuntu-latest, windows-latest, macos-latest]
73+
steps:
74+
- name: Install python
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: 3.10
78+
- name: Set up python environment
79+
run: |
80+
python -m install pipx
81+
pipx install hatch
82+
- name: Fetch repo
83+
uses: actions/checkout@v3
84+
- name: Create default env
85+
run: hatch env create test
86+
- name: Run all tests
87+
run: hatch run test:test

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
.idea
3+
*.log
4+
tmp/
5+
6+
*.py[cod]
7+
*.egg
8+
build
9+
htmlcov
10+
__pycache__/

hatch-vcs-tunable/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/_version.py
2+
dist/

hatch-vcs-tunable/CHANGES.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
7+
This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the changes for the upcoming release can be found in <https://github.com/opentrons/hatch-plugins/tree/main/hatch-vcs-tunable/changelog.d/>.
8+
9+
<!-- towncrier release notes start -->
10+
11+
## [0.0.0.dev0](https://github.com/opentrons/hatch-plugins/tree/0.0.0.dev0/hatch-vcs-tunable) - 2024-02-22
12+
13+
14+
### Added
15+
16+
- # Added new project hatch-vcs-tunable
17+
18+
`hatch-vcs-tunable` is a plugin for [Hatch](https://github.com/pypa/hatch) that extends the plugin [hatch-vcs](https://github.com/ofek/hatch-vcs) to allow for overriding some config elements with environment variables. The reason you might want to do this is if you have multiple release tracks for your package, or multiple contexts in which it is used, and want to give it different versions in those different contexts.
19+
20+
To install `hatch-vcs-tunable`, list it as a PEP-517 dependency in your `pyproject.toml`'s `build-system` section alongside `hatchling` (you have to be using `hatchling` as your builder for this plugin to work):
21+
22+
```
23+
[build-system]
24+
requires = ["hatchling", "hatch-vcs-tunable"]
25+
build-backend = "hatchling.build"
26+
```
27+
28+
From there, you can configure the plugin exactly as you would configure `hatch-vcs`, except that
29+
- The plugin name is `vcs-tunable`:
30+
``` toml
31+
[tool.hatch.build.hooks.vcs-tunable]
32+
version-file="_version.py"
33+
```
34+
35+
- You can override configuration from `pyproject.toml` using environment files at the time that you invoke your build frontend:
36+
37+
```bash
38+
HATCH_VCS_TUNABLE_TAG_PATTERN='my-project-prefix@(?P<version>)' hatch build`
39+
```
40+
41+
This allows for a system where you have different versions in different contexts. This can be useful if, for instance, you have different release tracks for a project, like an internal release and a public release, that have different versions.
42+
43+
([#1-new-project](https://github.com/opentrons/hatch-plugins/issues/1-new-project))

hatch-vcs-tunable/CONTRIBUTORS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Contributors to hatch-vcs-tunable
2+
3+
## Maintainers
4+
- [Seth Foster](https://github.com/sfoster1)
5+
6+
## Developers
7+

hatch-vcs-tunable/DEVELOPING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Development Documentation
2+
3+
`hatch-vcs-tunable`is a python package developed using [Hatch](https://github.com/pypa/hatch) as its environment manager, task runner, and build frontend. Generally, any command that inspects or interacts with the package source is done through hatch.
4+
5+
## Contributing
6+
7+
Contributions should come through pull request. If done via a fork, a maintainer will run the CI checks after a quick review. Open source contributions are welcome!
8+
9+
Pull requests should contain
10+
- A descriptive title
11+
- that is prefixed with `hatch-vcs-tunable:`, since this repository has multiple packages
12+
- A descriptive body that notes what the problem/missing feature is that the PR fixes and how the PR fixes it
13+
- A note on how the PR should be tested, if testing is required, and descriptions of how you tested it
14+
- A news fragment in `changelog.d` that adheres to [towncrier news fragment format](https://towncrier.readthedocs.io/en/stable/tutorial.html#creating-news-fragments) describing your change
15+
- If you're not already in it and you want to be, an addition of yourself to CONTRIBUTORS.md
16+
17+
## Linting/formatting/typechecking
18+
19+
Static analysis tools are run from the default hatch environment. Typechecking is via [mypy](http://mypy-lang.org/), linting and formatting is via [ruff](https://github.com/astral-sh/ruff). You can run these commands with `hatch run` without further qualification:
20+
- Typecheck: `hatch run check`
21+
- Format: `hatch run format`
22+
- Lint: `hatch run lint`
23+
- Auto lint fixes: `hatch run lint --fix`
24+
25+
These all must pass in CI before a PR can be merged.
26+
27+
## Tests
28+
29+
Tests are defined both in the default environment (in which case they will run just in whatever python environment and dependency set you happen to have installed) and in a special `test` environment endowed with matrix definitions for multiple python versions and multiple versions of the `hatch-vcs` plugin that `hatch-vcs-tunable` extends.
30+
31+
- Run quick tests: `hatch run test`
32+
- Run full test matrix: `hatch run test:test`
33+
34+
Tests must pass in CI before a PR can be merged.
35+
36+
## Maintenance and Releasing
37+
38+
Changelogs are generated using [towncrier](https://towncrier.readthedocs.io/en/stable/index.html). When opening a PR that has a newsworthy change, that PR should include a news fragment in `changelog.d`. Changelog generation happens during the release flow, which is automated via github actions that can be run by project maintainers.
39+
40+

0 commit comments

Comments
 (0)