Skip to content

Commit

Permalink
Simplify noxfile interaction with pyproject.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
alex committed Oct 31, 2023
1 parent d643b04 commit a9d4dbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jobs:
# pypy3-3.8 and pypy3-3.9 -- both of them show up as 7.3.11.
key: ${{ matrix.PYTHON.VERSION }}-${{ steps.setup-python.outputs.python-version }}-${{ matrix.PYTHON.NOXSESSION }}-${{ env.OPENSSL_HASH }}

- run: python -m pip install -c ci-constraints-requirements.txt 'nox'
- run: python -m pip install -c ci-constraints-requirements.txt 'nox' 'tomli; python_version < "3.11"'
- name: Create nox environment
run: |
nox -v --install-only
Expand Down Expand Up @@ -196,7 +196,7 @@ jobs:
- run: |
echo "OPENSSL_FORCE_FIPS_MODE=1" >> $GITHUB_ENV
if: matrix.IMAGE.FIPS
- run: /venv/bin/python -m pip install -c ci-constraints-requirements.txt 'nox'
- run: /venv/bin/python -m pip install -c ci-constraints-requirements.txt 'nox' 'tomli; python_version < "3.11"'
- run: '/venv/bin/nox -v --install-only'
env:
CARGO_TARGET_DIR: ${{ format('{0}/src/rust/target/', github.workspace) }}
Expand Down Expand Up @@ -247,7 +247,7 @@ jobs:
cache-dependency-path: ci-constraints-requirements.txt
- run: rustup component add llvm-tools-preview

- run: python -m pip install -c ci-constraints-requirements.txt 'nox'
- run: python -m pip install -c ci-constraints-requirements.txt 'nox' 'tomli; python_version < "3.11"'

- name: Clone wycheproof
timeout-minutes: 2
Expand Down Expand Up @@ -310,7 +310,7 @@ jobs:
timeout-minutes: 2
with:
key: ${{ matrix.PYTHON.NOXSESSION }}-${{ matrix.WINDOWS.ARCH }}-${{ steps.setup-python.outputs.python-version }}
- run: python -m pip install -c ci-constraints-requirements.txt "nox"
- run: python -m pip install -c ci-constraints-requirements.txt "nox" 'tomli; python_version < "3.11"'

- uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # v2.28.0
with:
Expand Down
32 changes: 18 additions & 14 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

import nox

try:
import tomllib
except ImportError:
import tomli as tomllib # type: ignore[import-not-found,no-redef]

nox.options.reuse_existing_virtualenvs = True


Expand All @@ -27,6 +32,11 @@ def install(session: nox.Session, *args: str) -> None:
)


def load_pyproject_toml() -> dict:
with (pathlib.Path(__file__).parent / "pyproject.toml").open("rb") as f:
return tomllib.load(f)


@nox.session
@nox.session(name="tests-ssh")
@nox.session(name="tests-randomorder")
Expand Down Expand Up @@ -152,22 +162,16 @@ def docs_linkcheck(session: nox.Session) -> None:

@nox.session
def flake(session: nox.Session) -> None:
# Just install the dependencies needed for these tests - basically
# `pip install .[pep8test,test,ssh,nox]`, but without installing `.`
# TODO: Ideally there'd be a pip flag to install just our dependencies,
# but not install us.
pyproject_data = load_pyproject_toml()
install(
session,
"setuptools-rust",
"cffi>=1.12; platform_python_implementation != 'PyPy'",
"wheel",
"ruff",
"check-sdist",
"mypy",
"bcrypt",
"click",
"pytest",
"nox",
*pyproject_data["build-system"]["requires"],
*pyproject_data["project"]["optional-dependencies"]["pep8test"],
*pyproject_data["project"]["optional-dependencies"]["test"],
*pyproject_data["project"]["optional-dependencies"]["ssh"],
*pyproject_data["project"]["optional-dependencies"]["nox"],
)
install(session, "-e", "vectors/")

Expand Down Expand Up @@ -198,10 +202,10 @@ def rust(session: nox.Session) -> None:
}
)

# Just install the dependencies needed for the Rust build.rs
# TODO: Ideally there'd be a pip flag to install just our dependencies,
# but not install us.
install(session, "cffi", "setuptools")
pyproject_data = load_pyproject_toml()
install(session, *pyproject_data["build-system"]["requires"])

with session.chdir("src/rust/"):
session.run("cargo", "fmt", "--all", "--", "--check", external=True)
Expand Down

0 comments on commit a9d4dbb

Please sign in to comment.