Skip to content

Commit

Permalink
Use local package overrides to run tests
Browse files Browse the repository at this point in the history
Also use safer uv invocation calls.

Refs: astral-sh/uv#4824
  • Loading branch information
kdeldycke committed Jul 24, 2024
1 parent 34342dc commit cad54d7
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 61 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/autofix.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ name: Autofix
jobs:

autofix:
uses: kdeldycke/workflows/.github/workflows/autofix.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/autofix.yaml@v4.3.3
2 changes: 1 addition & 1 deletion .github/workflows/autolock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ name: Autolock
jobs:

autolock:
uses: kdeldycke/workflows/.github/workflows/autolock.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/autolock.yaml@v4.3.3
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ name: Changelog & versions
jobs:

changelog:
uses: kdeldycke/workflows/.github/workflows/changelog.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/changelog.yaml@v4.3.3
12 changes: 3 additions & 9 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ name: Docs
jobs:

docs:
uses: kdeldycke/workflows/.github/workflows/docs.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/docs.yaml@v4.3.3

update-docs:
needs: docs
Expand All @@ -29,20 +29,14 @@ jobs:
python-version: "3.12"
- name: Install uv
run: |
python -m pip install -r https://raw.githubusercontent.com/kdeldycke/workflows/v4.3.1/requirements/uv.txt
python -m pip install -r https://raw.githubusercontent.com/kdeldycke/workflows/v4.3.3/requirements/uv.txt
- name: Install project
run: |
uv --no-progress venv --system
uv --no-progress pip install --all-extras --requirement pyproject.toml .
- name: Generate dynamic doc
run: |
uv --no-progress run python -m click_extra.docs_update
- name: Reset uv.lock
# Exclude `uv.lock` file which might be auto-updated by calls to `uv run`.
# See: https://github.com/peter-evans/create-pull-request#controlling-committed-files
# https://github.com/astral-sh/uv/issues/5185
run: |
git checkout -- uv.lock
uv --no-progress run --frozen -- python -m click_extra.docs_update
- uses: peter-evans/create-pull-request@v6.1.0
with:
assignees: ${{ github.actor }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/label-sponsors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ name: Label sponsors
jobs:

label-sponsors:
uses: kdeldycke/workflows/.github/workflows/label-sponsors.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/label-sponsors.yaml@v4.3.3
2 changes: 1 addition & 1 deletion .github/workflows/labeller-content-based.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ name: Labeller (content-based)
jobs:

labeller:
uses: kdeldycke/workflows/.github/workflows/labeller-file-based.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/labeller-file-based.yaml@v4.3.3
2 changes: 1 addition & 1 deletion .github/workflows/labeller-file-based.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ name: Labeller (file-based)
jobs:

labeller:
uses: kdeldycke/workflows/.github/workflows/labeller-file-based.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/labeller-file-based.yaml@v4.3.3
2 changes: 1 addition & 1 deletion .github/workflows/labels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ name: Labels
jobs:

labels:
uses: kdeldycke/workflows/.github/workflows/labels.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/labels.yaml@v4.3.3
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ name: Lint
jobs:

lint:
uses: kdeldycke/workflows/.github/workflows/lint.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/lint.yaml@v4.3.3
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ name: Build & release
jobs:

release:
uses: kdeldycke/workflows/.github/workflows/release.yaml@v4.3.1
uses: kdeldycke/workflows/.github/workflows/release.yaml@v4.3.3
secrets:
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
43 changes: 9 additions & 34 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,46 +164,21 @@ jobs:

- name: Install uv
run: |
python -m pip install -r https://raw.githubusercontent.com/kdeldycke/workflows/v4.3.1/requirements/uv.txt
python -m pip install -r https://raw.githubusercontent.com/kdeldycke/workflows/v4.3.3/requirements/uv.txt
- name: Install project
run: |
uv --no-progress venv --system
uv --no-progress pip install --all-extras --requirement ./pyproject.toml .
- name: Override dependency to click@${{ matrix.click-version }}
if: matrix.click-version != 'released'
run: |
echo "click @ git+https://github.com/pallets/click.git@${{ matrix.click-version }}" >> ./overrides.txt
- name: Override dependency to cloup@${{ matrix.cloup-version }}
if: matrix.cloup-version != 'released'
run: |
echo "cloup @ git+https://github.com/janluke/cloup.git@${{ matrix.cloup-version }}" >> ./overrides.txt
- name: Amend pyproject.toml with overrides
if: hashFiles('overrides.txt')
shell: python
# XXX We need to add dependencies overrides to pyproject.toml because `uv run` below does not supports the
# --override option. See: https://github.com/astral-sh/uv/issues/4824
run: |
from pathlib import Path
overrides = Path("./overrides.txt").read_text().splitlines()
pyproject = Path("./pyproject.toml")
content = pyproject.read_text()
content += (
"\n[tool.uv]\noverride-dependencies = [\n "
+ ',\n '.join('"' + override + '"' for override in overrides)
+ "\n]\n"
)
print(f"New pyproject.toml content:\n{content}")
pyproject.write_text(content)
- name: Unittests
run: |
uv --no-progress run pytest
run: >
uv --no-progress run
${{ matrix.click-version != 'released'
&& format('--with "git+https://github.com/pallets/click.git@{0}"', matrix.click-version) }}
${{ matrix.cloup-version != 'released'
&& format('--with "git+https://github.com/janluke/cloup.git@{0}"', matrix.cloup-version) }}
--
pytest
- name: Codecov upload
uses: codecov/codecov-action@v4.5.0
Expand Down
18 changes: 9 additions & 9 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,17 @@ $ source .venv/bin/activate
$ uv pip install --all-extras ./pyproject.toml
(...)
$ uv run python -m pip install dbt-core
$ uv run -- python -m pip install dbt-core
(...)
$ uv run python -m pip install aws-sam-cli
$ uv run -- python -m pip install aws-sam-cli
(...)
```
That way I had the latest Click Extra, `dbt` and `aws-sam-cli` installed in the same virtual environment:
```shell-session
$ uv run dbt --version
$ uv run -- dbt --version
Core:
- installed: 1.6.1
- latest: 1.6.2 - Update available!
Expand All @@ -310,7 +310,7 @@ Plugins:
```
```shell-session
$ uv run sam --version
$ uv run -- sam --version
SAM CLI, version 1.97.0
```
````
Expand Down Expand Up @@ -340,7 +340,7 @@ if __name__ == "__main__":
And this simple script gets rendered into:

```shell-session
$ uv run python ./wrap.py
$ uv run -- python ./wrap.py
Usage: wrap.py [OPTIONS] COMMAND [ARGS]...
Options:
Expand Down Expand Up @@ -374,7 +374,7 @@ You can compare the output of the `aws_sam` subcommand with its original one:
`````{tab-set}
````{tab-item} aws_sam subcommand in wrap.py
```shell-session
$ uv run python ./wrap.py aws_sam --help
$ uv run -- python ./wrap.py aws_sam --help
Usage: wrap.py aws_sam [OPTIONS] COMMAND [ARGS]...
AWS Serverless Application Model (SAM) CLI
Expand Down Expand Up @@ -438,7 +438,7 @@ Examples:
````{tab-item} Vanilla sam CLI
```shell-session
$ uv run sam --help
$ uv run -- sam --help
Usage: sam [OPTIONS] COMMAND [ARGS]...
AWS Serverless Application Model (SAM) CLI
Expand Down Expand Up @@ -505,9 +505,9 @@ Here is the highlighted differences to make them even more obvious:

```diff
@@ -1,5 +1,5 @@
-$ uv run python ./wrap.py aws_sam --help
-$ uv run -- python ./wrap.py aws_sam --help
-Usage: wrap.py aws_sam [OPTIONS] COMMAND [ARGS]...
+$ uv run sam --help
+$ uv run -- sam --help
+Usage: sam [OPTIONS] COMMAND [ARGS]...

AWS Serverless Application Model (SAM) CLI
Expand Down

0 comments on commit cad54d7

Please sign in to comment.