Skip to content

Commit

Permalink
Use uv for Package Constraints (jupyterlab#225)
Browse files Browse the repository at this point in the history
* Use uv for dependency_type managemange

* fixups

* cleanup

* fix test

* fix test

* cleanup
  • Loading branch information
blink1073 authored Mar 25, 2024
1 parent 1d24a7a commit e9d32bd
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 162 deletions.
10 changes: 7 additions & 3 deletions .github/actions/base-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ runs:
# Handle default python value based on dependency type.
if [ $DEPENDENCY_TYPE == "pre" ]; then
DEFAULT_PYTHON="3.11"
DEFAULT_PYTHON="3.12"
elif [ $DEPENDENCY_TYPE == "minimum" ]; then
DEFAULT_PYTHON="3.8"
elif [ $DEPENDENCY_TYPE != "standard" ]; then
Expand Down Expand Up @@ -114,6 +114,7 @@ runs:
set -eux
echo "::group::Upgrade packaging dependencies"
python -m pip install --upgrade pip
pipx install uv
if [ "$RUNNER_OS" != "Windows" ]; then
pipx install hatch --python $(which python)
else
Expand All @@ -125,11 +126,14 @@ runs:
shell: bash
run: |
set -eux
FLAGS=""
if [ $DEPENDENCY_TYPE == 'pre' ]; then
echo "PIP_PRE=1" >> $GITHUB_ENV
FLAGS="--prerelease=allow"
elif [ $DEPENDENCY_TYPE == 'minimum' ]; then
source ${{ github.action_path }}/setup_constraints.sh
FLAGS="--resolution=lowest-direct"
fi
uv pip compile $FLAGS pyproject.toml -o $HOME/constraints.txt
echo "PIP_CONSTRAINT=$HOME/constraints.txt" >> $GITHUB_ENV
- name: Print Diagnostics
shell: bash
Expand Down
11 changes: 0 additions & 11 deletions .github/actions/base-setup/setup_constraints.sh

This file was deleted.

45 changes: 0 additions & 45 deletions .github/actions/install-minimums/action.yml

This file was deleted.

35 changes: 0 additions & 35 deletions .github/actions/install-minimums/create_constraints_file.py

This file was deleted.

32 changes: 1 addition & 31 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
pip install -e ".[test]"
# NOTE: keep this version in sync with README
python --version
python --version | grep "3.11"
python --version | grep "3.12"
hatch run check_pre
test_lint:
Expand Down Expand Up @@ -148,35 +148,6 @@ jobs:
pre_commit: true
target: "https://github.com/jupyterlab/maintainer-tools/pull/39"

install_minimums:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"] # Test against minimum Python version as well
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Base Setup
uses: ./.github/actions/base-setup
- name: Clone a repo
run: git clone --depth=1 https://github.com/jupyter/nbformat.git
- name: Install minimum versions
uses: ./.github/actions/install-minimums
with:
working-directory: nbformat
- name: Run the unit tests
working-directory: nbformat
run: pytest -vv
- name: Only create file
uses: ./.github/actions/install-minimums
with:
only_create_file: 1
constraints_file_path: "./constraints-test.txt"
- name: Ensure constraints file
run: |
cat ./constraints-test.txt
echo $PIP_CONSTRAINT | grep "constraints-test.txt"
update_snapshots-manual-server:
runs-on: ubuntu-latest
env:
Expand Down Expand Up @@ -311,7 +282,6 @@ jobs:
- check_links
- binder_link
- pr_script
- install_minimums
- downstream_defaults
- downstream_overrides
- update_snapshots-manual-server
Expand Down
43 changes: 7 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
If you want to use your minimum dependencies, you can use the following
option, which will create a constraints file and set the `PIP_CONSTRAINT`
environment variable, so that installations will use that file.
By default the Python version will be "3.11", which can be overridden with
By default the Python version will be "3.7", which can be overridden with
`python_version`. Note that the environment variable also works if
you use virtual environments like `hatch`.

Expand All @@ -68,9 +68,12 @@ you use virtual environments like `hatch`.
run: pytest
```

If you want to run against prereleases and the latest stable Python,
use the following, which will install Python 3.11 and set the
`PIP_PRE` environment variable::
If you want to use your minimum dependencies, you can use the following
option, which will create a constraints file and set the `PIP_CONSTRAINT`
environment variable, so that installations will use that file.
By default the Python version will be "3.12", which can be overridden with
`python_version`. Note that the environment variable also works if
you use virtual environments like `hatch`.

```yaml
prereleases:
Expand Down Expand Up @@ -193,38 +196,6 @@ jobs:

To test against a prerelease use `package_download_extra_args: "--pre"`.
## Test Against Dependency Minimum Version
**DEPRECATED**. Use `dependency_type: minimum` in the `base-setup` action
instead.

Use this action to test that your minimum dependency version constraints are valid. Note: you may want to also use the minimum supported version of Python
since the minimum versions might not have wheels on newer Pythons. Note that you should use `pytest -W default` if you are using `filterwarnings` and relying on newer versions of the library to have removed warnings.

```yaml
name: Minimum Dependencies
on:
push:
branches: ["main"]
pull_request:
jobs:
test_minimums:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
with:
python_version: "3.8" # Test against minimum Python version as well
- name: Install minimum versions
uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1
- name: Run the unit tests
run: pytest -vv -W default
```

## Test SDist
Use this pair of actions to build an sdist for your package, and then test it
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source = "nodejs"

[tool.hatch.envs.default.scripts]
check_minimum = "python -c 'from jupyter_core import __version__; assert __version__ == \"4.12.0\"'"
check_pre = "python -c 'import os; assert os.environ[\"PIP_PRE\"] == \"1\"'"
check_pre = "python -c 'import os; assert os.environ[\"PIP_CONSTRAINT\"]'"

[tool.hatch.envs.typing]
dependencies = ["pre-commit"]
Expand Down

0 comments on commit e9d32bd

Please sign in to comment.