Skip to content
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

DM-46065: Update for tox-docker 5 and ruff-shared.toml #78

Merged
merged 12 commits into from
Aug 30, 2024
Merged
19 changes: 9 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: CI

env:
PYTHON_VERSION: "3.12"

"on":
merge_group: {}
pull_request: {}
Expand All @@ -26,9 +29,9 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: ${{ env.PYTHON_VERSION }}

- name: Run pre-commit
uses: pre-commit/[email protected]
Expand All @@ -37,20 +40,15 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
matrix:
python:
- "3.12"

steps:
- uses: actions/checkout@v4

- name: Run tox
uses: lsst-sqre/run-tox@v1
with:
python-version: ${{ matrix.python }}
python-version: ${{ env.PYTHON_VERSION }}
tox-envs: "docker,coverage-report,typing"
tox-plugins: "tox-docker"
tox-requirements: "requirements/tox.txt"

build:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -97,8 +95,9 @@ jobs:
- name: Run tox
uses: lsst-sqre/run-tox@v1
with:
python-version: "3.12"
python-version: ${{ env.PYTHON_VERSION }}
tox-envs: "docs,docs-linkcheck"
tox-requirements: "requirements/tox.txt"

# Only attempt documentation uploads for long-lived branches, tagged
# releases, and pull requests from ticket branches. This avoids version
Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/periodic-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

name: Periodic CI

env:
PYTHON_VERSION: "3.12"


"on":
schedule:
- cron: "0 12 * * 1"
Expand All @@ -15,29 +19,23 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10

strategy:
matrix:
python:
- "3.12"

steps:
- uses: actions/checkout@v4

# Use the oldest supported version of Python to update dependencies,
# not the matrixed Python version, since this accurately reflects
# how dependencies should later be updated.
- name: Run neophile
uses: lsst-sqre/run-neophile@v1
with:
python-version: "3.12"
mode: update
- name: Update dependencies
run: |
pip install --upgrade uv
uv venv
source .venv/bin/activate
make update-deps
shell: bash

- name: Run tests in tox
uses: lsst-sqre/run-tox@v1
with:
python-version: ${{ matrix.python }}
python-version: ${{ env.PYTHON_VERSION }}
tox-envs: "lint,typing,docker,docs,docs-linkcheck"
tox-plugins: "tox-docker"
tox-requirements: "requirements/tox.txt"
use-cache: false

- name: Report status
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repos:
- id: check-toml

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.3.2
rev: v0.6.3
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
66 changes: 38 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
# The dependencies need --allow-unsafe because kubernetes-asyncio and
# (transitively) pre-commit depends on setuptools, which is normally not
# allowed to appear in a hashed dependency file.
.PHONY: help
help:
@echo "Make targets for example"
@echo "make init - Set up dev environment"
@echo "make run - Start a local development instance"
@echo "make update - Update pinned dependencies and run make init"
@echo "make update-deps - Update pinned dependencies"
@echo "make update-deps-no-hashes - Pin dependencies without hashes"

.PHONY: init
init:
pip install --upgrade uv
uv pip install -r requirements/main.txt -r requirements/dev.txt \
-r requirements/tox.txt
uv pip install --editable .
rm -rf .tox
uv pip install --upgrade pre-commit
pre-commit install

.PHONY: run
run:
tox run -e run

.PHONY: update
update: update-deps init

.PHONY: update-deps
update-deps:
pip install --upgrade pip-tools pip setuptools
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe --generate-hashes \
pip install --upgrade uv
uv pip install --upgrade pre-commit
pre-commit autoupdate
uv pip compile --upgrade --generate-hashes \
--output-file requirements/main.txt requirements/main.in
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe --generate-hashes \
uv pip compile --upgrade --generate-hashes \
--output-file requirements/dev.txt requirements/dev.in
uv pip compile --upgrade --generate-hashes \
--output-file requirements/tox.txt requirements/tox.in

# Useful for testing against a Git version of Safir.
.PHONY: update-deps-no-hashes
update-deps-no-hashes:
pip install --upgrade pip-tools pip setuptools
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe \
pip install --upgrade uv
uv pip compile --upgrade \
--output-file requirements/main.txt requirements/main.in
pip-compile --upgrade --resolver=backtracking --build-isolation \
--allow-unsafe \
uv pip compile --upgrade \
--output-file requirements/dev.txt requirements/dev.in

.PHONY: init
init:
pip install --editable .
pip install --upgrade -r requirements/main.txt -r requirements/dev.txt
rm -rf .tox
pip install --upgrade tox tox-docker scriv pre-commit
pre-commit install

.PHONY: update
update: update-deps init

.PHONY: run
run:
tox run -e=run
uv pip compile --upgrade \
--output-file requirements/tox.txt requirements/tox.in
20 changes: 20 additions & 0 deletions changelog.d/20240830_164744_jsick_DM_46065.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Delete the sections that don't apply -->

### Backwards-incompatible changes

-

### New features

-

### Bug fixes

-

### Other changes

- Adopt uv and tox-uv for pinning and installing dependencies
- Pin the tox dependencies with a `requirements/tox.[in|txt]` file
- Adapt configuration for tox-docker version 5's randomized connection ports
- Adopt [ruff-shared.toml](https://github.com/lsst/templates/blob/main/project_templates/fastapi_safir_app/example/ruff-shared.toml) for common SQuaRE ruff configuration.
2 changes: 1 addition & 1 deletion docs/user-guide/github-app-config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ When you do this, you can create the secret keys that Times Square needs to auth
These are provided to Times Square as environment variables:

- :envvar:`TS_GITHUB_APP_ID`: The GitHub App ID. This is shown on the GitHub App's :guilabel:`General` page under the :guilabel:`About` heading.
- :envvar:`TS_GITHUB_APP_PRIVATE_KEY`: The GitHub App's private key. This is shown on the GitHub App's :guilabel:`General` page under :guilabel:`Client secrets`.
- :envvar:`TS_GITHUB_APP_PRIVATE_KEY`: The GitHub App's private key. This is shown on the GitHub App's :guilabel:`General`.
- :envvar:`TS_GITHUB_WEBHOOK_SECRET`: The webhook secret you created in the GitHub App's :guilabel:`General` page under :guilabel:`Webhooks`.
- :envvar:`TS_GITHUB_ORGS`: A comma-separated list of the GitHub organizations that Times Square should operate on. For a private GitHub App, this should be the organization that owns the app. See also: :ref:`multiple-github-orgs`.

Expand Down
88 changes: 3 additions & 85 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,78 +103,15 @@ skip_fragments = "_template.md.jinja"
# Reference for settings: https://beta.ruff.rs/docs/settings/
# Reference for rules: https://beta.ruff.rs/docs/rules/
[tool.ruff]
exclude = [
"docs/**",
extend = "ruff-shared.toml"
extend-exclude = [
"tests/data/**",
]
line-length = 79
target-version = "py312"

[tool.ruff.lint]
ignore = [
"ANN101", # self should not have a type annotation
"ANN102", # cls should not have a type annotation
"ANN401", # sometimes Any is the right type
"ARG001", # unused function arguments are often legitimate
"ARG002", # unused method arguments are often legitimate
"ARG005", # unused lambda arguments are often legitimate
"BLE001", # we want to catch and report Exception in background tasks
"C414", # nested sorted is how you sort by multiple keys with reverse
"D102", # sometimes we use docstring inheritence
"D104", # don't see the point of documenting every package
"D105", # our style doesn't require docstrings for magic methods
"D106", # Pydantic uses a nested Config class that doesn't warrant docs
"D205", # our documentation style allows a folded first line
"EM101", # justification (duplicate string in traceback) is silly
"EM102", # justification (duplicate string in traceback) is silly
"FBT003", # positional booleans are normal for Pydantic field defaults
"FIX002", # point of a TODO comment is that we're not ready to fix it
"G004", # forbidding logging f-strings is appealing, but not our style
"RET505", # disagree that omitting else always makes code more readable
"PLR0911", # often many returns is clearer and simpler style
"PLR0913", # factory pattern uses constructors with many arguments
"PLR2004", # too aggressive about magic values
"PLW0603", # yes global is discouraged but if needed, it's needed
"S105", # good idea but too many false positives on non-passwords
"S106", # good idea but too many false positives on non-passwords
"S107", # good idea but too many false positives on non-passwords
"S603", # not going to manually mark every subprocess call as reviewed
"S607", # using PATH is not a security vulnerability
"SIM102", # sometimes the formatting of nested if statements is clearer
"SIM117", # sometimes nested with contexts are clearer
"TCH001", # we decided to not maintain separate TYPE_CHECKING blocks
"TCH002", # we decided to not maintain separate TYPE_CHECKING blocks
"TCH003", # we decided to not maintain separate TYPE_CHECKING blocks
"TID252", # if we're going to use relative imports, use them always
"TRY003", # good general advice but lint is way too aggressive
"TRY301", # sometimes raising exceptions inside try is the best flow
"TD003", # don't need issue link for todos

# The following settings should be disabled when using ruff format
# per https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
"E114",
"E117",
"D206",
"D300",
"Q000",
"Q001",
"Q002",
"Q003",
"COM812",
"COM819",
"ISC001",
"ISC002",
]
select = ["ALL"]

[tool.ruff.lint.per-file-ignores]
"src/timessquare/config.py" = [
"FBT001", # Pydantic validators take boolean arguments
]
"src/timessquare/handlers/**" = [
"D103", # FastAPI handlers should not have docstrings
]
"tests/**" = [
"C901", # tests are allowed to be complex, sometimes that's convenient
"D101", # tests don't need docstrings
Expand All @@ -190,22 +127,3 @@ select = ["ALL"]
[tool.ruff.lint.isort]
known-first-party = ["timessquare", "tests"]
split-on-trailing-comma = false

# These are too useful as attributes or methods to allow the conflict with the
# built-in to rule out their use.
[tool.ruff.lint.flake8-builtins]
builtins-ignorelist = [
"all",
"any",
"help",
"id",
"list",
"type",
]

[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.lint.pydocstyle]
convention = "numpy"
3 changes: 1 addition & 2 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@ sqlalchemy[mypy]
holdup
respx
types-PyYAML
types-redis
documenteer[guide]>=1.0.0a1
documenteer[guide]>=1.0
httpx-sse == 0.4.0
Loading
Loading