Skip to content

Commit

Permalink
chore: Template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Sep 27, 2024
1 parent e62d67c commit 7f808c2
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Changes here will be overwritten by Copier
_commit: 1.4.0
_commit: 1.4.1
_src_path: gh:pawamoy/copier-uv
author_email: [email protected]
author_fullname: Timothée Mazzucotelli
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ jobs:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install uv
run: pip install uv
- name: Setup uv
uses: astral-sh/setup-uv@v1
with:
enable-cache: true

- name: Install dependencies
env:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/.hypothesis/
/htmlcov/
/site/
uv.lock

# cache
.cache/
Expand Down
32 changes: 0 additions & 32 deletions devdeps.txt

This file was deleted.

4 changes: 2 additions & 2 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def changelog(ctx: Context, bump: str = "") -> None:
ctx.run(tools.git_changelog(bump=bump or None), title="Updating changelog")


@duty(pre=["check_quality", "check_types", "check_docs", "check_dependencies", "check-api"])
def check(ctx: Context) -> None: # noqa: ARG001
@duty(pre=["check-quality", "check-types", "check-docs", "check-api"])
def check(ctx: Context) -> None:
"""Check it all!"""


Expand Down
7 changes: 4 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ plugins:
show_root_heading: true
show_root_full_path: false
show_signature_annotations: true
show_source: false
show_source: true
show_symbol_type_heading: true
show_symbol_type_toc: true
signature_crossrefs: true
summary: true
- git-committers:
- git-revision-date-localized:
enabled: !ENV [DEPLOY, false]
repository: mkdocstrings/griffe2md
enable_creation_date: true
type: timeago
- minify:
minify_html: !ENV [DEPLOY, false]
- group:
Expand Down
37 changes: 36 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ source-includes = [
"scripts",
"share",
"tests",
"devdeps.txt",
"duties.py",
"mkdocs.yml",
"*.md",
Expand All @@ -71,3 +70,39 @@ source-includes = [
data = [
{path = "share/**/*", relative-to = "."},
]

[tool.uv]
dev-dependencies = [
# dev
"editables>=0.5",

# maintenance
"build>=1.2",
"git-changelog>=2.5",
"twine>=5.0; python_version < '3.13'",

# ci
"duty>=1.4",
"ruff>=0.4",
"pytest>=8.2",
"pytest-cov>=5.0",
"pytest-randomly>=3.15",
"pytest-xdist>=3.6",
"mypy>=1.10",
"types-markdown>=3.6",
"types-pyyaml>=6.0",

# docs
"black>=24.4",
"markdown-callouts>=0.4",
"markdown-exec>=1.8",
"mkdocs>=1.6",
"mkdocs-coverage>=1.0",
"mkdocs-gen-files>=0.5",
"mkdocs-git-revision-date-localized-plugin>=1.2",
"mkdocs-literate-nav>=0.6",
"mkdocs-material>=9.5",
"mkdocs-minify-plugin>=0.8",
"mkdocstrings[python]>=0.25",
"tomli>=2.0; python_version < '3.11'",
]
3 changes: 1 addition & 2 deletions scripts/gen_credits.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
pyproject = tomllib.load(pyproject_file)
project = pyproject["project"]
project_name = project["name"]
with project_dir.joinpath("devdeps.txt").open() as devdeps_file:
devdeps = [line.strip() for line in devdeps_file if line.strip() and not line.strip().startswith(("-e", "#"))]
devdeps = [dep for dep in pyproject["tool"]["uv"]["dev-dependencies"] if not dep.startswith("-e")]

PackageMetadata = Dict[str, Union[str, Iterable[str]]]
Metadata = Dict[str, PackageMetadata]
Expand Down
66 changes: 16 additions & 50 deletions scripts/make
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ from typing import Any, Iterator

PYTHON_VERSIONS = os.getenv("PYTHON_VERSIONS", "3.8 3.9 3.10 3.11 3.12 3.13").split()

exe = ""
prefix = ""


def shell(cmd: str, capture_output: bool = False, **kwargs: Any) -> str | None:
"""Run a shell command."""
Expand All @@ -37,18 +34,11 @@ def environ(**kwargs: str) -> Iterator[None]:
os.environ.update(original)


def uv_install() -> None:
def uv_install(venv: Path) -> None:
"""Install dependencies using uv."""
uv_opts = ""
if "UV_RESOLUTION" in os.environ:
uv_opts = f"--resolution={os.getenv('UV_RESOLUTION')}"
requirements = shell(f"uv pip compile {uv_opts} pyproject.toml devdeps.txt", capture_output=True)
shell("uv pip install -r -", input=requirements, text=True)
if "CI" not in os.environ:
shell("uv pip install --no-deps -e .")
else:
shell("uv pip install --no-deps .")

with environ(UV_PROJECT_ENVIRONMENT=str(venv)):
shell("uv sync")


def setup() -> None:
"""Setup the project."""
Expand All @@ -59,47 +49,27 @@ def setup() -> None:
default_venv = Path(".venv")
if not default_venv.exists():
shell("uv venv --python python")
uv_install()
uv_install(default_venv)

if PYTHON_VERSIONS:
for version in PYTHON_VERSIONS:
print(f"\nInstalling dependencies (python{version})") # noqa: T201
venv_path = Path(f".venvs/{version}")
if not venv_path.exists():
shell(f"uv venv --python {version} {venv_path}")
with environ(VIRTUAL_ENV=str(venv_path.resolve())):
uv_install()


def activate(path: str) -> None:
"""Activate a virtual environment."""
global exe, prefix # noqa: PLW0603

if (bin := Path(path, "bin")).exists():
activate_script = bin / "activate_this.py"
elif (scripts := Path(path, "Scripts")).exists():
activate_script = scripts / "activate_this.py"
exe = ".exe"
prefix = f"{path}/Scripts/"
else:
raise ValueError(f"make: activate: Cannot find activation script in {path}")

if not activate_script.exists():
raise ValueError(f"make: activate: Cannot find activation script in {path}")

exec(activate_script.read_text(), {"__file__": str(activate_script)}) # noqa: S102
with environ(UV_PROJECT_ENVIRONMENT=str(venv_path.resolve())):
uv_install(venv_path)


def run(version: str, cmd: str, *args: str, **kwargs: Any) -> None:
"""Run a command in a virtual environment."""
kwargs = {"check": True, **kwargs}
if version == "default":
activate(".venv")
subprocess.run([f"{prefix}{cmd}{exe}", *args], **kwargs) # noqa: S603, PLW1510
with environ(UV_PROJECT_ENVIRONMENT=".venv"):
subprocess.run(["uv", "run", cmd, *args], **kwargs) # noqa: S603, PLW1510
else:
activate(f".venvs/{version}")
os.environ["MULTIRUN"] = "1"
subprocess.run([f"{prefix}{cmd}{exe}", *args], **kwargs) # noqa: S603, PLW1510
with environ(UV_PROJECT_ENVIRONMENT=f".venvs/{version}", MULTIRUN="1"):
subprocess.run(["uv", "run", cmd, *args], **kwargs) # noqa: S603, PLW1510


def multirun(cmd: str, *args: str, **kwargs: Any) -> None:
Expand All @@ -124,10 +94,10 @@ def clean() -> None:
for path in paths_to_clean:
shell(f"rm -rf {path}")

cache_dirs = [".cache", ".pytest_cache", ".mypy_cache", ".ruff_cache", "__pycache__"]
for dirpath in Path(".").rglob("*"):
if any(dirpath.match(pattern) for pattern in cache_dirs) and not (dirpath.match(".venv") or dirpath.match(".venvs")):
shutil.rmtree(path, ignore_errors=True)
cache_dirs = {".cache", ".pytest_cache", ".mypy_cache", ".ruff_cache", "__pycache__"}
for dirpath in Path(".").rglob("*/"):
if dirpath.parts[0] not in (".venv", ".venvs") and dirpath.name in cache_dirs:
shutil.rmtree(dirpath, ignore_errors=True)


def vscode() -> None:
Expand All @@ -152,11 +122,7 @@ def main() -> int:
print(" 3.x Run a command in the virtual environment for Python 3.x.") # noqa: T201
print(" clean Delete build artifacts and cache files.") # noqa: T201
print(" vscode Configure VSCode to work on this project.") # noqa: T201
try:
run("default", "python", "-V", capture_output=True)
except (subprocess.CalledProcessError, ValueError):
pass
else:
if os.path.exists(".venv"):
print("\nAvailable tasks") # noqa: T201
run("default", "duty", "--list")
return 0
Expand Down

0 comments on commit 7f808c2

Please sign in to comment.