Skip to content

Commit

Permalink
Clean up handling of minimum and prerelease versions (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Nov 22, 2022
1 parent ceb8352 commit a09372e
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 89 deletions.
76 changes: 48 additions & 28 deletions .github/actions/base-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,65 @@ inputs:
description: "The python version"
node_version:
description: "The node version"
dependency_type:
default: "standard"
description: "The dependency installation type: standard, pre, minimum"
runs:
using: "composite"
steps:
- name: Set Versions
- name: Set up environment
shell: bash
run: |
echo "PYTHON_VERSION=${{ inputs.python_version || matrix.python-version || '3.10' }}" >> $GITHUB_ENV
echo "NODE_VERSION=${{ inputs.node_version || matrix.node-version || '16.x' }}" >> $GITHUB_ENV
PYTHON_VERSION="${{ inputs.python_version || matrix.python-version }}"
NODE_VERSION=${{ inputs.node_version || matrix.node-version || '16.x' }}
DEPENDENCY_TYPE=${{ inputs.dependency_type }}
# Handle default python value based on dependency type.
if [ $DEPENDENCY_TYPE == "pre" ]; then
DEFAULT_PYTHON="3.11"
elif [ $DEPENDENCY_TYPE == "minimum" ]; then
DEFAULT_PYTHON="3.8"
else
DEFAULT_PYTHON="3.10"
fi
echo "DEFAULT_PYTHON is $DEFAULT_PYTHON"
PYTHON_VERSION="${PYTHON_VERSION:-$DEFAULT_PYTHON}"
echo "PYTHON_VERSION=$PYTHON_VERSION" >> $GITHUB_ENV
echo "NODE_VERSION=$NODE_VERSION" >> $GITHUB_ENV
echo "CACHE_PREFIX=${{ runner.os }}-${{ github.workflow}}-${{ github.job }}" >> $GITHUB_ENV
echo "DEPENDENCY_TYPE=$DEPENDENCY_TYPE" >> $GITHUB_ENV
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
architecture: "x64"
cache: 'pip'
cache-dependency-path: |
**/setup.cfg
**/setup.py
**/pyproject.toml
**/requirements*.txt
- name: Install node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: Get pip cache dir
id: pip-cache
# Cache yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: Cache pip
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Cache yarn
uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ env.CACHE_PREFIX }}-pip-${{ env.PYTHON_VERSION }}-${{ hashFiles('setup.cfg', 'setup.py', '**/requirements.txt') }}
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ env.CACHE_PREFIX }}-yarn-${{ env.NODE_VERSION }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ env.CACHE_PREFIX }}-pip-${{ env.PYTHON_VERSION }}
${{ env.CACHE_PREFIX }}-yarn-${{ env.NODE_VERSION }}
- name: Cache checked links
if: ${{ matrix.group == 'link_check' }}
Expand All @@ -58,20 +83,6 @@ runs:
restore-keys: |
${{ env.CACHE_PREFIX }}-conda-
# Cache yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
shell: bash
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Cache yarn
uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ env.CACHE_PREFIX }}-yarn-${{ env.NODE_VERSION }}-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ env.CACHE_PREFIX }}-yarn-${{ env.NODE_VERSION }}
- name: Enable long paths on Windows
if: startsWith(runner.os, 'Windows')
run: Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1
Expand All @@ -81,10 +92,19 @@ runs:
shell: bash
run: |
echo "::group::Upgrade packaging dependencies"
python -m pip install --upgrade pip setuptools wheel pytest-github-actions-annotate-failures
python -m pip install --upgrade pip
pipx install hatch
echo "::endgroup::"
- name: Handle dependency type
shell: bash
run: |
if [ $DEPENDENCY_TYPE == 'pre' ]; then
echo "PIP_PRE=1" >> $GITHUB_ENV
elif [ $DEPENDENCY_TYPE == 'minimum' ]; then
source ${{ github.action_path }}/setup_constraints.sh
fi
- name: Print Diagnostics
shell: bash
run: |
Expand Down
10 changes: 10 additions & 0 deletions .github/actions/base-setup/setup_constraints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
python -m venv $HOME/.venv
source $HOME/.venv/bin/activate
pip install build packaging pkginfo
mkdir $HOME/dist
python -m build --outdir $HOME/dist --wheel .

SCRIPT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
python $SCRIPT_DIR/../install-minimums/create_constraints_file.py $HOME/constraints.txt $HOME/dist/*.whl
echo "PIP_CONSTRAINT=$HOME/constraints.txt" >> $GITHUB_ENV
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,35 @@ jobs:
- name: Check Hatch Version
run: hatch --version

base_setup_minimum:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/base-setup
with:
dependency_type: minimum
- run: |
pip install -e ".[test]"
# NOTE: keep this version in sync with README
python --version
python --version | grep "3.8"
cat $PIP_CONSTRAINT
cat $PIP_CONSTRAINT | grep "jupyter-core=="
base_setup_pre:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/base-setup
with:
dependency_type: pre
- run: |
pip install -e ".[test]"
# NOTE: keep this version in sync with README
python --version
python --version | grep "3.11"
env | grep "PIP_PRE"
pre_commit:
runs-on: ubuntu-latest
steps:
Expand Down
101 changes: 46 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,49 @@ jobs:
run: pytest
```
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.8", which can be overridden with
`python_version`. Note that the environment variable also works if
you use virtual environments like `hatch`.

```yaml
minimum_version:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
with:
dependency_type: minimum
- name: Install
run: pip install -e ".[test]"
- name: Test
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::

```yaml
prereleases:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Base Setup
uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
with:
dependency_type: pre
- name: Install
run: pip install -e ".[test]"
- name: Test
run: pytest
```

## Check Links

Use this action to check the links in your repo using `pytest-check-links`.
Expand Down Expand Up @@ -152,6 +195,9 @@ 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 vaild. 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.

Expand Down Expand Up @@ -179,61 +225,6 @@ jobs:
run: pytest -vv -W default
```

If you use virtual environments for testing as as with `hatch`, you can
create the constraints file and then use it in the env like this:

```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.7" # Test against minimum Python version as well
- name: Install minimum versions
uses: jupyterlab/maintainer-tools/.github/actions/install-minimums@v1
with:
only_create_file: 1
- name: Run the unit tests
run: |
hatch run test:test
```

Note that you can run a test against prereleases like the following:

```yaml
name: Prerelease Dependencies
on:
push:
branches: ["main"]
pull_request:
jobs:
test_prereleases:
name: Test Prereleases
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v3
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
with:
python_version: "3.11"
- name: Run the tests
run: |
PIP_PRE=1 hatch run test:nowarn || hatch run test:nowarn --lf
```

## Test SDist

Use this pair of actions to build an sdist for your package, and then test it
Expand Down
9 changes: 3 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ name = "foobar"
authors = [{name = "Sir Robin", email = "robin@camelot.uk"}]
dynamic = ["description", "version"]
readme = "README.md"

[tool.jupyter-packaging.builder]
factory = "jupyter_packaging.npm_builder"
dependencies = ["jupyter_core>=4.10.0"]
optional-dependencies.test = ["pytest"]

[tool.jupyter-releaser]
skip = ["check-links", "publish-assets"]

[tool.jupyter-releaser.hooks]
after-populate-release = ["bash ./.github/scripts/bump_tag.sh"]
hooks.after-populate-release = ["bash ./.github/scripts/bump_tag.sh"]

[tool.hatch.version]
source = "nodejs"
Expand Down

0 comments on commit a09372e

Please sign in to comment.