Skip to content

Instantly share code, notes, and snippets.

@MtkN1
Created April 4, 2024 14:06
Show Gist options
  • Save MtkN1/41f36491dbf7162043d89d73a9d87dec to your computer and use it in GitHub Desktop.
Save MtkN1/41f36491dbf7162043d89d73a9d87dec to your computer and use it in GitHub Desktop.
nox for Rye (it works, sort of)
import nox
import os
from pathlib import Path
PYTHON_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]
VENV_BACKEND = "uv"
def ensurepath():
rye_home = os.getenv("RYE_HOME")
rye_py = Path(rye_home) if rye_home else Path.home() / ".rye" / "py"
for py_dir in rye_py.iterdir():
bin_dir = py_dir / "bin"
os.environ["PATH"] = f"{bin_dir}:{os.environ['PATH']}"
ensurepath()
@nox.session()
def fetch(session: nox.Session):
for require_version in PYTHON_VERSIONS:
session.run("rye", "fetch", require_version, external=True)
ensurepath()
@nox.session(python=PYTHON_VERSIONS, venv_backend=VENV_BACKEND)
def tests(session: nox.Session):
session.install("-r", "requirements-dev.lock")
session.run("pytest")
@nox.session(venv_backend=VENV_BACKEND)
def lint(session: nox.Session):
session.install("-r", "requirements-dev.lock")
session.run("ruff", "check")
@MtkN1
Copy link
Author

MtkN1 commented Sep 16, 2024

@vincentchov There were a few missing prerequisites for this snippet to function correctly. You'll need to add a few dependencies:

$ rye add --dev pytest nox uv ruff

With these dependencies installed, the snippet should work as expected.

However, nowadays, using uv>=0.4 directly is a better approach than relying on this specific snippet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment