Skip to content

Commit

Permalink
Merge pull request #24 from pypa/refactor-nox-workflow
Browse files Browse the repository at this point in the history
Refactor testing
  • Loading branch information
chrysle committed Feb 4, 2024
2 parents b0a98d0 + aae5868 commit a4b1224
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 55 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/nox.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: nox
on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

jobs:
nox:
strategy:
Expand All @@ -15,8 +20,7 @@ jobs:
with:
python-version: ${{ matrix.python }}
- run: python3 --version && python --version
- run: pip install --upgrade pip setuptools
- run: pip install nox pytest virtualenv
- run: pip install -r requirements.txt pytest
- run: pytest . || true # See pytest's warnings
- run: nox --python ${{ matrix.python }}
# - run: nox --python ${{ matrix.python }} --report report.json && python report_to_table.py
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace packages.
To run the scenarios:

```
$ pip install --upgrade setuptools virtualenv nox
$ pip install -r requirements.txt
$ nox --report report.json
```

Expand Down
2 changes: 2 additions & 0 deletions constraints.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
setuptools >= 68.2.2
wheel >= 0.42.0
83 changes: 37 additions & 46 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,84 +17,75 @@

HERE = os.path.abspath(os.path.dirname(__file__))

# -- REQUIRES: nox >= 2018.10.17
# SEE: https://nox.readthedocs.io/en/stable/index.html
# -- REQUIRES: nox >= 2023.04.22
# SEE: https://nox.thea.codes/en/stable/index.html
USE_PYTHON_VERSIONS_DEFAULT = ["3.8", "3.10", "3.12"]
USE_PYTHON_VERSIONS = os.environ.get("NOXFILE_PYTHON_VERSIONS", "").split()
if not USE_PYTHON_VERSIONS:
USE_PYTHON_VERSIONS = USE_PYTHON_VERSIONS_DEFAULT


install_commands = (
('pip', 'install', '.'),
('pip', 'install', '-e', '.'),
('python', 'setup.py', 'install'),
('python', 'setup.py', 'develop'))
install_commands = (("pip", "install", "."), ("pip", "install", "-e", "."))


def install_packages(session, package_a, package_b, command_a, command_b):
session.install(
"--upgrade",
"setuptools",
"pip",
"wheel",
env={"PIP_CONSTRAINT": f"{HERE}/constraints.txt"},
)
session.chdir(package_a)
session.run('rm', '-rf', 'dist', 'build', '*.egg-info')
session.run("rm", "-rf", "dist", "build", "*.egg-info")
session.run(*command_a)
session.chdir(HERE)
session.chdir(package_b)
session.run('rm', '-rf', 'dist', 'build', '*.egg-info')
session.run("rm", "-rf", "dist", "build", "*.egg-info")
session.run(*command_b)
session.chdir(HERE)


@nox.session(python=USE_PYTHON_VERSIONS)
@nox.parametrize('command_a', install_commands)
@nox.parametrize('command_b', install_commands)
@nox.parametrize("command_a", install_commands)
@nox.parametrize("command_b", install_commands)
def session_pkgutil(session, command_a, command_b):
session.install('--upgrade', 'setuptools', 'pip')
install_packages(
session, 'pkgutil/pkg_a', 'pkgutil/pkg_b',
command_a, command_b)
session.run('python', 'verify_packages.py')
install_packages(session, "pkgutil/pkg_a", "pkgutil/pkg_b", command_a, command_b)
session.run("python", "verify_packages.py")


@nox.session(python=USE_PYTHON_VERSIONS)
@nox.parametrize('command_a', install_commands)
@nox.parametrize('command_b', install_commands)
@nox.parametrize("command_a", install_commands)
@nox.parametrize("command_b", install_commands)
def session_pkg_resources(session, command_a, command_b):
session.install('--upgrade', 'setuptools', 'pip')
install_packages(
session, 'pkg_resources/pkg_a', 'pkg_resources/pkg_b',
command_a, command_b)
session.run('python', 'verify_packages.py')
session, "pkg_resources/pkg_a", "pkg_resources/pkg_b", command_a, command_b
)
session.run("python", "verify_packages.py")


@nox.session(python=USE_PYTHON_VERSIONS)
@nox.parametrize('command_a', install_commands)
@nox.parametrize('command_b', install_commands)
@nox.parametrize("command_a", install_commands)
@nox.parametrize("command_b", install_commands)
def session_pep420(session, command_a, command_b):
session.install('--upgrade', 'setuptools', 'pip')
install_packages(
session, 'native/pkg_a', 'native/pkg_b',
command_a, command_b)
session.run('python', 'verify_packages.py')
install_packages(session, "native/pkg_a", "native/pkg_b", command_a, command_b)
session.run("python", "verify_packages.py")


@nox.session(python=USE_PYTHON_VERSIONS)
@nox.parametrize('command_a', install_commands)
@nox.parametrize('command_b', install_commands)
def session_cross_pkg_resources_pkgutil(
session, command_a, command_b):
session.install('--upgrade', 'setuptools', 'pip')
@nox.parametrize("command_a", install_commands)
@nox.parametrize("command_b", install_commands)
def session_cross_pkg_resources_pkgutil(session, command_a, command_b):
install_packages(
session, 'pkg_resources/pkg_a', 'pkgutil/pkg_b',
command_a, command_b)
session.run('python', 'verify_packages.py')
session, "pkg_resources/pkg_a", "pkgutil/pkg_b", command_a, command_b
)
session.run("python", "-m", "pip", "list")
session.run("python", "verify_packages.py")


@nox.session(python=USE_PYTHON_VERSIONS)
@nox.parametrize('command_a', install_commands)
@nox.parametrize('command_b', install_commands)
def session_cross_pep420_pkgutil(
session, command_a, command_b):
session.install('--upgrade', 'setuptools', 'pip')
install_packages(
session, 'native/pkg_a', 'pkgutil/pkg_b',
command_a, command_b)
session.run('python', 'verify_packages.py')
@nox.parametrize("command_a", install_commands)
@nox.parametrize("command_b", install_commands)
def session_cross_pep420_pkgutil(session, command_a, command_b):
install_packages(session, "native/pkg_a", "pkgutil/pkg_b", command_a, command_b)
session.run("python", "verify_packages.py")
6 changes: 3 additions & 3 deletions pkgutil/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ The directories `pkg_a` and `pkg_b` in this subdirectory contain two different p
The names of these directories have no effect on the installed package.

Each of these directories should at least contain:
1. `setup.py`.
1. A configuration file, in this case `setup.py`.
2. A directory, whose name determines the namespace name.

In this example `example_pkg` is the name of the namespace. This directory should contain:
Expand Down Expand Up @@ -58,8 +58,8 @@ From the root directory, running the following command will install a package ca
```bash
cd pkgutil/pkg_a

pip install .
python -m pip install .

# Test the install by printing the `name` from the `__init__.py` file.
python -c "import example_pkg.a as a; print a.name"
python -c "import example_pkg.a as a; print(a.name)"
```
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -- PYTHON PACKAGE REQUIREMENTS:
# USE: pip install -r <THIS_FILE>

setuptools
virtualenv
nox >= 2018.10.17
nox >= 2023.04.22

0 comments on commit a4b1224

Please sign in to comment.