8000 feat: Use pyproject.toml instead of setup.cfg + pinned dependencies + ruff as linter. by PabloHiro · Pull Request #1325 · ansible/receptor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Use pyproject.toml instead of setup.cfg + pinned dependencies + ruff as linter. #1325

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

Merged
merged 2 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 10 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ receptor: $(shell find pkg -type f -name '*.go') ./cmd/receptor-cl/receptor.go
clean:
@rm -fv .container-flag*
@rm -fv .VERSION
@rm -fv receptorctl/.VERSION
@rm -fv receptor-python-worker/.VERSION
@rm -rfv dist/
@rm -fv $(KUBECTL_BINARY)
@rm -fv packaging/container/receptor
Expand Down Expand Up @@ -96,7 +98,7 @@ kubectl:
lint:
@golint cmd/... pkg/... example/...

receptorctl-lint: receptor receptorctl/.VERSION
receptorctl-lint: receptor
@cd receptorctl && nox -s lint

format:
Expand Down Expand Up @@ -169,7 +171,7 @@ test: receptor
-race \
-timeout 5m

receptorctl-test: receptorctl/.VERSION receptor
receptorctl-test: receptor
@cd receptorctl && nox -s tests

testloop: receptor
Expand All @@ -184,27 +186,21 @@ version:
@echo $(VERSION) > .VERSION
@echo ".VERSION created for $(VERSION)"

receptorctl/.VERSION:
echo $(VERSION) > $@

RECEPTORCTL_WHEEL = receptorctl/dist/receptorctl-$(VERSION:v%=%)-py3-none-any.whl
$(RECEPTORCTL_WHEEL): receptorctl/README.md receptorctl/.VERSION $(shell find receptorctl/receptorctl -type f -name '*.py')
@cd receptorctl && python3 -m build --wheel
$(RECEPTORCTL_WHEEL): $(shell find receptorctl/receptorctl -type f -name '*.py')
@cd receptorctl && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RECEPTORCTL=$(VERSION) python3 -m build --wheel

receptorctl_wheel: $(RECEPTORCTL_WHEEL)

RECEPTORCTL_SDIST = receptorctl/dist/receptorctl-$(VERSION:v%=%).tar.gz
$(RECEPTORCTL_SDIST): receptorctl/README.md receptorctl/.VERSION $(shell find receptorctl/receptorctl -type f -name '*.py')
@cd receptorctl && python3 -m build --sdist
$(RECEPTORCTL_SDIST): $(shell find receptorctl/receptorctl -type f -name '*.py')
@cd receptorctl && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RECEPTORCTL=$(VERSION) python3 -m build --sdist

receptorctl_sdist: $(RECEPTORCTL_SDIST)

receptor-python-worker/.VERSION:
echo $(VERSION) > $@

RECEPTOR_PYTHON_WORKER_WHEEL = receptor-python-worker/dist/receptor_python_worker-$(VERSION:v%=%)-py3-none-any.whl
$(RECEPTOR_PYTHON_WORKER_WHEEL): receptor-python-worker/README.md receptor-python-worker/.VERSION $(shell find receptor-python-worker/receptor_python_worker -type f -name '*.py')
@cd receptor-python-worker && python3 -m build --wheel
$(RECEPTOR_PYTHON_WORKER_WHEEL): $(shell find receptor-python-worker/receptor_python_worker -type f -name '*.py')
@cd receptor-python-worker && SETUPTOOLS_SCM_PRETEND_VERSION_FOR_RECEPTOR_PYTHON_WORKER=$(VERSION) python3 -m build --wheel

# Container command can be docker or podman
CONTAINERCMD ?= podman
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# ones.
extensions = [
"sphinx.ext.autosectionlabel",
"pbr.sphinxext",
]

autosectionlabel_prefix_document = True
Expand Down
16 changes: 15 additions & 1 deletion receptor-python-worker/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
[project]
name = "receptor-python-worker"
authors = [{name = "Red Hat", email = "info@ansible.com"}]
description = "The receptor-python-worker command is called by Receptor to supervise the operation of a Python worker plugin."
readme = "README.md"
license = "Apache-2.0"
dynamic = ["version"]

[build-system]
requires = ["setuptools"]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
fallback_version = "0.0.0"

[project.scripts]
receptor-python-worker = "receptor_python_worker:run"
20 changes: 0 additions & 20 deletions receptor-python-worker/setup.cfg

This file was deleted.

2 changes: 0 additions & 2 deletions receptorctl/.coveragerc

This file was deleted.

5 changes: 0 additions & 5 deletions receptorctl/.pip-tools.toml

This file was deleted.

3 changes: 0 additions & 3 deletions receptorctl/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
recursive-include receptorctl *.py
include .VERSION
exclude .gitignore
exclude noxfile.py
exclude build-requirements.txt
exclude test-requirements.txt
8 changes: 1 addition & 7 deletions receptorctl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ Before you submit a PR, you should install `nox` and verify your changes.
You can run `nox` with no arguments to execute all checks and tests.
Alternatively, you can run only certain tasks as outlined in the following sections.

> By default nox sessions install pinned dependencies from the `requirements` directory.

You can use unpinned dependencies as follows:

```bash
PINNED=false nox -s lint
```
> By default nox sessions install pinned dependencies from `pyproject.toml`.

## Checking changes to Receptorctl

Expand Down
70 changes: 14 additions & 56 deletions receptorctl/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,20 @@
python_versions = ["3.8", "3.9", "3.10", "3.11", "3.12"]

LINT_FILES: tuple[str, ...] = (*iglob("**/*.py"),)
PINNED = os.environ.get("PINNED", "true").lower() in {"1", "true"}

requirements_directory = Path("requirements").resolve()

requirements_files = [requirements_input_file_path.stem for requirements_input_file_path in requirements_directory.glob("*.in")]


def install(session: nox.Session, *args, req: str, **kwargs):
if PINNED:
pip_constraint = requirements_directory / f"{req}.txt"
kwargs.setdefault("env", {})["PIP_CONSTRAINT"] = pip_constraint
session.log(f"export PIP_CONSTRAINT={pip_constraint!r}")
session.install("-r", f"{requirements_directory}/{req}.in", *args, **kwargs)


def version(session: nox.Session):
"""
Create a .VERSION file.
"""
try:
official_version = session.run_install(
"git",
"describe",
"--exact-match",
"--tags",
external=True,
stderr=subprocess.DEVNULL,
)
except nox.command.CommandFailed:
official_version = None
print("Using the closest annotated tag instead of an exact match.")

if official_version:
version = official_version.strip()
else:
tag = session.run_install("git", "describe", "--tags", "--always", silent=True, external=True)
rev = session.run_install("git", "rev-parse", "--short", "HEAD", silent=True, external=True)
version = tag.split("-")[0] + "+" + rev

Path(".VERSION").write_text(version)
def install(session: nox.Session, *args, **kwargs):
session.install(".[test]", *args, **kwargs)


@nox.session(python=LATEST_PYTHON_VERSION)
def coverage(session: nox.Session):
"""
Run receptorctl tests with code coverage
"""
install(session, req="tests")
version(session)
install(session)
session.install("-e", ".")
session.run(
"pytest",
Expand All @@ -78,8 +43,7 @@ def tests(session: nox.Session):
"""
Run receptorctl tests
"""
install(session, req="tests")
version(session)
install(session)
session.install("-e", ".")
session.run("pytest", "-v", "tests", *session.posargs)

Expand All @@ -89,26 +53,26 @@ def check_style(session: nox.Session):
"""
Check receptorctl Python code style
"""
install(session, req="lint")
session.run("flake8", *session.posargs, *LINT_FILES)
install(session)
session.run("ruff", "check", *session.posargs, *LINT_FILES)


@nox.session
def check_format(session: nox.Session):
"""
Check receptorctl Python file formatting without making changes
"""
install(session, req="lint")
session.run("black", "--check", *session.posargs, *LINT_FILES)
install(session)
session.run("ruff", "format", "--check", *session.posargs, *LINT_FILES)


@nox.session
def format(session: nox.Session):
"""
Format receptorctl Python files
"""
install(session, req="lint")
session.run("black", *session.posargs, *LINT_FILES)
install(session)
session.run("ruff", "format", *session.posargs, *LINT_FILES)


@nox.session
Expand All @@ -121,23 +85,17 @@ def lint(session: nox.Session):


@nox.session(name="pip-compile", python=["3.12"])
@nox.parametrize(["req"], arg_values_list=requirements_files, ids=requirements_files)
def pip_compile(session: nox.Session, req: str):
def pip_compile(session: nox.Session):
"""Generate lock files from input files or upgrade packages in lock files."""
# fmt: off
session.install(
"-r", str(requirements_directory / "pip-tools.in"),
"-c", str(requirements_directory / "pip-tools.txt"),
)
# fmt: on
install(session)

# Use --upgrade by default unless a user passes -P.
upgrade_related_cli_flags = ("-P", "--upgrade-package", "--no-upgrade")
has_upgrade_related_cli_flags = any(arg.startswith(upgrade_related_cli_flags) for arg in session.posargs)
injected_extra_cli_args = () if has_upgrade_related_cli_flags else ("--upgrade",)

output_file = os.path.relpath(Path(requirements_directory / f"{req}.txt"))
input_file = os.path.relpath(Path(requirements_directory / f"{req}.in"))
output_file = os.path.relpath(Path(requirements_directory / "requirements.txt"))
input_file = "pyproject.toml"

session.run(
"pip-compile",
Expand Down
51 changes: 48 additions & 3 deletions receptorctl/pyproject.toml
8000
Original file line number Diff line number Diff line change
@@ -1,6 +1,51 @@
[project]
name = "receptorctl"
authors = [{name = "Red Hat", email = "info@ansible.com"}]
description = "Receptorctl is a front-end CLI and importable Python library that interacts with Receptor over its control socket interface."
readme = "README.md"
dynamic = ["version"]
dependencies = [
"python-dateutil>=2.8.1",
"click>=8.1.3, <8.2.0",
"PyYAML>=5.4.1",
]

[project.license]
text = "Apache-2.0"

[project.urls]
Homepage = "https://ansible.readthedocs.io/projects/receptor/"
Documentation = "https://ansible.readthedocs.io/projects/receptor/en/latest/"
Repository = "https://github.com/ansible/receptor"
Issues = "https://github.com/ansible/receptor/issues"

[build-system]
requires = ["setuptools"]
requires = ["setuptools>=75.3.2", "setuptools-scm>=7.1.0"]
build-backend = "setuptools.build_meta"

[tool.black]
exclude = "(build|.eggs)"
[tool.setuptools_scm]
fallback_version = "0.0.0"

[project.optional-dependencies]
test = [
"coverage",
"pip-tools>=7",
"pytest",
"pytest-cov",
"ruff",
]

[project.scripts]
receptorctl = "receptorctl:run"

[tool.ruff]
line-length = 100

[tool.pip-tools]
resolver = "backtracking"
allow-unsafe = true
strip-extras = true
quiet = true

[tool.coverage.run]
omit = ["tests/*"]
16 changes: 4 additions & 12 deletions receptorctl/receptorctl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ def status(ctx, printjson):
ads = status.pop("Advertisements", None)
if ads:
print_message()
print_message(
f"{'Node':<{longest_node}} Service Type Last Seen Tags"
)
print_message(f"{'Node':<{longest_node}} Service Type Last Seen Tags")
for ad in ads:
time = dateutil.parser.parse(ad["Time"])
if ad["ConnType"] == 0:
Expand Down Expand Up @@ -238,9 +236,7 @@ def print_worktypes(header, isSecure):
@click.pass_context
@click.argument("node")
@click.option("--count", default=4, help="Number of pings to send", show_default=True)
@click.option(
"--delay", default=1.0, help="Time to wait between pings", show_default=True
)
@click.option("--delay", default=1.0, help="Time to wait between pings", show_default=True)
def ping(ctx, node, count, delay):
rc = get_rc(ctx)
ping_error = False
Expand All @@ -251,9 +247,7 @@ def ping(ctx, node, count, delay):
else:
ping_error = True
if "From" in results and "TimeStr" in results:
print_error(
f"{results['Error']} from {results['From']} in {results['TimeStr']}"
)
print_error(f"{results['Error']} from {results['From']} in {results['TimeStr']}")
else:
print_error(f"{results['Error']}")
if i < count - 1:
Expand Down Expand Up @@ -299,9 +293,7 @@ def traceroute(ctx, node):
@click.pass_context
@click.argument("node")
@click.argument("service")
@click.option(
"--raw", "-r", default=False, is_flag=True, help="Set terminal to raw mode"
)
@click.option("--raw", "-r", default=False, is_flag=True, help="Set terminal to raw mode")
@click.option(
"--tls-client",
"tlsclient",
Expand Down
Loading
0