Skip to content

Commit

Permalink
Merge pull request #89 from vkottler/dev/3.0.4
Browse files Browse the repository at this point in the history
3.0.4 - Make format targets more robust
  • Loading branch information
vkottler authored Jul 5, 2024
2 parents 77469fa + f7525dd commit 0c8262d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 25 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
env:
TWINE_PASSWORD: ${{secrets.TWINE_PASSWORD}}
GITHUB_API_TOKEN: ${{secrets.API_TOKEN}}
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}

jobs:
build:
Expand All @@ -18,7 +19,6 @@ jobs:
strategy:
matrix:
python-version:
- "3.11"
- "3.12"
system:
- ubuntu-latest
Expand Down Expand Up @@ -70,29 +70,33 @@ jobs:

- run: mk docs
if: |
matrix.python-version == '3.11'
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
- run: mk python-test
env:
PY_TEST_EXTRA_ARGS: --cov-report=xml

- uses: codecov/codecov-action@v3.1.5
with:
fail_ci_if_error: true
verbose: true
token: ${{secrets.CODECOV_TOKEN}}

- run: mk pypi-upload-ci
env:
TWINE_USERNAME: __token__
if: |
matrix.python-version == '3.11'
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
&& env.TWINE_PASSWORD != ''
&& github.ref_name == 'master'
- run: |
mk python-release owner=vkottler \
repo=yambs version=3.0.3
repo=yambs version=3.0.4
if: |
matrix.python-version == '3.11'
matrix.python-version == '3.12'
&& matrix.system == 'ubuntu-latest'
&& env.GITHUB_API_TOKEN != ''
&& github.ref_name == 'master'
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Vaughn Kottler
Copyright (c) 2024 Vaughn Kottler

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
=====================================
generator=datazen
version=3.1.4
hash=934a1cb8be74864c521e3c3d3875e01d
hash=a4fbd061471e04dda4fbf58664532b82
=====================================
-->

# yambs ([3.0.3](https://pypi.org/project/yambs/))
# yambs ([3.0.4](https://pypi.org/project/yambs/))

[![python](https://img.shields.io/pypi/pyversions/yambs.svg)](https://pypi.org/project/yambs/)
![Build Status](https://github.com/vkottler/yambs/workflows/Python%20Package/badge.svg)
Expand All @@ -29,7 +29,6 @@

This package is tested with the following Python minor versions:

* [`python3.11`](https://docs.python.org/3.11/)
* [`python3.12`](https://docs.python.org/3.12/)

## Platform Support
Expand Down
2 changes: 1 addition & 1 deletion local/configs/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author_info:
username: vkottler

# CI matrix.
versions: ["3.11", "3.12"]
versions: ["3.12"]
systems:
- macos-latest
- windows-latest
2 changes: 1 addition & 1 deletion local/variables/package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
major: 3
minor: 0
patch: 3
patch: 4
entry: mbs
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@ build-backend = "setuptools.build_meta:__legacy__"

[project]
name = "yambs"
version = "3.0.3"
version = "3.0.4"
description = "Yet another meta build-system."
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.12"
authors = [
{name = "Vaughn Kottler", email = "vaughnkottler@gmail.com"}
]
maintainers = [
{name = "Vaughn Kottler", email = "vaughnkottler@gmail.com"}
]
classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=ce50fe613526c5b8b8b7fd8527e3566d
# hash=daf54da52332deabbf12efbfd83e041e
# =====================================

"""
Expand All @@ -28,7 +28,6 @@
"version": VERSION,
"description": DESCRIPTION,
"versions": [
"3.11",
"3.12",
],
}
Expand Down
4 changes: 2 additions & 2 deletions yambs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# =====================================
# generator=datazen
# version=3.1.4
# hash=1229207e5be7a4167912254256ebd6a2
# hash=7e05959b0ce8dc1dedf4e30ecad6a07f
# =====================================

"""
Expand All @@ -10,4 +10,4 @@

DESCRIPTION = "Yet another meta build-system."
PKG_NAME = "yambs"
VERSION = "3.0.3"
VERSION = "3.0.4"
43 changes: 37 additions & 6 deletions yambs/generate/ninja/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

# built-in
from itertools import batched
from os import linesep
from pathlib import Path
from typing import Iterable, TextIO
Expand Down Expand Up @@ -30,6 +31,27 @@ def render_format(
write_format_target(path_fd, paths, suffix, root)


def final_format_targets(
stream: TextIO, by_kind: dict[str, list[str]]
) -> None:
"""Create final, highest-level format targets."""

for target, deps in by_kind.items():
if deps:
stream.write(linesep)

line = f"build {target}: phony "
offset = " " * len(line)

stream.write(line)
stream.write(deps[0])
for dep in deps[1:]: # pragma: nocover
write_continuation(stream, offset)
stream.write(dep)

stream.write(linesep)


def write_format_target(
stream: TextIO, paths: Iterable[Path], suffix: str, root: Path = None
) -> None:
Expand All @@ -48,22 +70,31 @@ def write_format_target(
stream.write("rule clang-format-check" + linesep)
stream.write(f" command = {cmd} -n --Werror $in" + linesep)

paths = list(paths)
if paths:
for sfx in ["", "-check"]:
targets = [("format", ""), ("format-check", "-check")]
by_kind: dict[str, list[str]] = {"format": [], "format-check": []}

# Write format rules in groups of files to ensure command-line invocations
# don't get too long.
for idx, group in enumerate(batched(paths, 64)):
for kind, sfx in targets:
stream.write(linesep)
line = f"build format{sfx}: clang-format{sfx} "
target = f"format-{idx}{sfx}"
by_kind[kind].append(target)
line = f"build {target}: clang-format{sfx} "
offset = " " * len(line)

stream.write(line)
stream.write(
str(paths[0] if root is None else rel(paths[0], base=root))
str(group[0] if root is None else rel(group[0], base=root))
)

for source in paths[1:]:
for source in group[1:]:
write_continuation(stream, offset)
stream.write(
str(source if root is None else rel(source, base=root))
)

stream.write(linesep)

# Create final target.
final_format_targets(stream, by_kind)

0 comments on commit 0c8262d

Please sign in to comment.