Skip to content

Commit

Permalink
chore: Template upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Oct 11, 2024
1 parent 3108ada commit 48ad843
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 115 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.6
_src_path: gh:pawamoy/copier-uv
author_email: dev@pawamoy.fr
author_fullname: Timothée Mazzucotelli
Expand Down
23 changes: 15 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ jobs:
- name: Fetch all tags
run: git fetch --depth=1 --tags

- name: Set up Graphviz
- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v2

- name: Set up Python
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

- name: Install uv
run: pip install uv
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: pyproject.toml

- name: Install dependencies
run: make setup
Expand Down Expand Up @@ -117,14 +120,18 @@ jobs:
- name: Fetch all tags
run: git fetch --depth=1 --tags

- name: Set up Python
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- name: Install uv
run: pip install uv
- name: Setup uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: pyproject.toml
cache-suffix: py${{ matrix.python-version }}

- name: Install dependencies
env:
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,30 @@ jobs:
- name: Fetch all tags
run: git fetch --depth=1 --tags
- name: Setup Python
uses: actions/setup-python@v4
- name: Install build
if: github.repository_owner == 'pawamoy-insiders'
run: python -m pip install build
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Setup uv
uses: astral-sh/setup-uv@v3
- name: Build dists
if: github.repository_owner == 'pawamoy-insiders'
run: python -m build
run: uv tool run --from build pyproject-build
- name: Upload dists artifact
uses: actions/upload-artifact@v4
if: github.repository_owner == 'pawamoy-insiders'
with:
name: griffe-insiders
path: ./dist/*
- name: Install git-changelog
if: github.repository_owner != 'pawamoy-insiders'
run: pip install git-changelog
- name: Prepare release notes
if: github.repository_owner != 'pawamoy-insiders'
run: git-changelog --release-notes > release-notes.md
run: uv tool run git-changelog --release-notes > release-notes.md
- name: Create release with assets
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: github.repository_owner == 'pawamoy-insiders'
with:
files: ./dist/*
- name: Create release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: github.repository_owner != 'pawamoy-insiders'
with:
body_path: release-notes.md
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/.pdm-build/
/htmlcov/
/site/
uv.lock

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

This file was deleted.

9 changes: 7 additions & 2 deletions duties.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ 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-api"])
@duty(pre=["check-quality", "check-types", "check-docs", "check-api"])
def check(ctx: Context) -> None:
"""Check it all!
Expand Down Expand Up @@ -310,7 +310,12 @@ def docs_deploy(ctx: Context) -> None:
ctx.run(lambda: False, title="Not deploying docs without Material for MkDocs Insiders!")
origin = ctx.run("git config --get remote.origin.url", silent=True, allow_overrides=False)
if "pawamoy-insiders/griffe" in origin:
ctx.run("git remote add upstream git@github.com:mkdocstrings/griffe", silent=True, nofail=True)
ctx.run(
"git remote add upstream git@github.com:mkdocstrings/griffe",
silent=True,
nofail=True,
allow_overrides=False,
)
ctx.run(
tools.mkdocs.gh_deploy(remote_name="upstream", force=True),
title="Deploying documentation",
Expand Down
45 changes: 44 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ source-includes = [
"scripts",
"share",
"tests",
"devdeps.txt",
"duties.py",
"mkdocs.yml",
"*.md",
Expand All @@ -79,3 +78,47 @@ 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",
"jsonschema>=4.17",
"pysource-codegen>=0.4",
"pysource-minimize>=0.5",
"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",
"code2flow>=2.5",
"griffe-inherited-docstrings>=1.0",
"markdown-callouts>=0.4",
"markdown-exec[ansi]>=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",
"mkdocs-section-index>=0.3",
"mkdocs-redirects>=1.2",
"mkdocstrings[python]>=0.25",
"pydeps>=1.12",
"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
72 changes: 22 additions & 50 deletions scripts/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

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

_exe = ""
_prefix = ""
_commands = []


Expand All @@ -39,45 +37,25 @@ def _environ(**kwargs: str) -> Iterator[None]:
os.environ.update(original)


def _uv_install() -> None:
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 .")


def _activate(path: str) -> None:
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
def _uv_install(venv: Path) -> None:
with _environ(UV_PROJECT_ENVIRONMENT=str(venv)):
if "CI" in os.environ:
_shell("uv sync --no-editable")
else:
_shell("uv sync")


def _run(version: str, cmd: str, *args: str, **kwargs: Any) -> None:
def _run(version: str, cmd: str, *args: str, no_sync: bool = False, **kwargs: Any) -> None:
kwargs = {"check": True, **kwargs}
uv_run = ["uv", "run"]
if no_sync:
uv_run.append("--no-sync")
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 _command(name: str) -> Callable[[Callable[..., None]], Callable[..., None]]:
Expand Down Expand Up @@ -111,14 +89,10 @@ def help(*args: str) -> None:
if len(args) > 1:
_run("default", "duty", "--help", args[1])
else:
print("Available commands")
print("Available commands", flush=True)
for cmd in _commands:
print(f" {cmd.__cmdname__:21} {cmd.__doc__.splitlines()[0]}") # type: ignore[attr-defined,union-attr]
try:
_run("default", "python", "-V", capture_output=True)
except (subprocess.CalledProcessError, ValueError):
pass
else:
print(f" {cmd.__cmdname__:21} {cmd.__doc__.splitlines()[0]}", flush=True) # type: ignore[attr-defined,union-attr]
if Path(".venv").exists():
print("\nAvailable tasks", flush=True)
run("duty", "--list")

Expand Down Expand Up @@ -163,7 +137,7 @@ 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:
Expand All @@ -172,7 +146,7 @@ def setup() -> None:
if not venv_path.exists():
_shell(f"uv venv --python {version} {venv_path}")
with _environ(VIRTUAL_ENV=str(venv_path.resolve())):
_uv_install()
_uv_install(venv_path)


@_command("run")
Expand Down Expand Up @@ -264,11 +238,9 @@ def clean() -> None:
_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)
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)


@_command("vscode")
Expand Down

0 comments on commit 48ad843

Please sign in to comment.