Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(action): do not depend on pipx in Nox action #768

Merged
merged 7 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- uses: actions/checkout@v4
- uses: ./
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_default_tests

action-all-tests:
runs-on: windows-latest
steps:
Expand All @@ -43,3 +44,12 @@ jobs:
with:
python-versions: "3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, pypy-2.7, pypy-3.7, pypy-3.8, pypy-3.9, pypy-3.10"
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_all_tests

action-macos14-tests:
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: ./
with:
python-versions: "3.10, 3.11, 3.12, pypy-3.8, pypy-3.9, pypy-3.10"
- run: nox --non-interactive --error-on-missing-interpreter --session github_actions_macos_14
44 changes: 42 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,45 @@ runs:
allow-prereleases: true

- name: "Install nox"
run: pipx install --python "${{ steps.allpython.outputs.python-path }}" '${{ github.action_path }}'
shell: bash
run: |
import os
import shutil
import sys
import venv

from pathlib import Path
from subprocess import run


class EnvBuilder(venv.EnvBuilder):
def __init__(self):
super().__init__()

def setup_scripts(self, context):
pass

def post_setup(self, context):
super().post_setup(context)
self.bin_path = Path(context.env_exe).parent
run([sys.executable, "-m", "pip", "--python", context.env_exe, "install", r"${{ github.action_path }}"], check=True)


print("::group::Install nox")
nox_bin_path = Path(r"${{ runner.temp }}") / "nox"
if nox_bin_path.exists():
shutil.rmtree(nox_bin_path)
venv_path = Path(r"${{ runner.temp }}") / "nox-venv"
if venv_path.exists():
shutil.rmtree(venv_path)
builder = EnvBuilder()
builder.create(venv_path)
nox_path = [path for path in builder.bin_path.glob("nox*") if path.stem == "nox"][0]
nox_bin_path.mkdir()
try:
os.symlink(nox_path, nox_bin_path / nox_path.name)
except OSError:
shutil.copyfile(nox_path, nox_bin_path / nox_path.name)
with open(os.environ["GITHUB_PATH"], "at") as f:
f.write(f"{nox_bin_path}\n")
print("::endgroup::")
shell: "${{ steps.localpython.outputs.python-path }} -u {0}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
shell: "${{ steps.localpython.outputs.python-path }} -u {0}"
shell: "${{ steps.allpython.outputs.python-path }} -u {0}"

Not sure using the last activated one makes sense, but it’s what was done before. Seems like only activating 3.6 would be valid, but we must run from 3.7+, for example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henryiii, the last activated one is always 3.11:

# we want to install python 3.11 last to ease nox set-up
if "3.11" in cpython_versions_filtered:
index = cpython_versions_filtered.index("3.11")
index = versions.index(cpython_versions[index])
cpython_nox = versions.pop(index)
versions.append(cpython_nox)
else:
# add this to install nox
versions.append("3.11")

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn’t we use localpython?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at some point, and that's probably still the case, setup-python was allowed to delete some python install to install a more specific one: e.g. you have the latest 3.11.y pre-installed, but specify 3.11.x in the nox action then, 3.11.y is deleted and localpython won't work anymore.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense. Should we bump to 3.12 now?

17 changes: 16 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def github_actions_default_tests(session: nox.Session) -> None:
_check_python_version(session)


# The following sessions are only to be run in CI to check the nox GHA action
@nox.session(
python=[
"3.7",
Expand All @@ -192,3 +191,19 @@ def github_actions_default_tests(session: nox.Session) -> None:
def github_actions_all_tests(session: nox.Session) -> None:
"""Check all versions installed by the nox GHA Action"""
_check_python_version(session)


@nox.session(
python=[
"3.10",
"3.11",
"3.12",
"pypy3.8",
"pypy3.9",
"pypy3.10",
]
)
def github_actions_macos_14(session: nox.Session) -> None:
"""Check default versions installed by the nox GHA Action"""
assert sys.version_info[:2] == (3, 11)
_check_python_version(session)
Loading