Skip to content

Commit dfd1c67

Browse files
committed
Switch formatting and linting to ruff
1 parent fd5b75b commit dfd1c67

22 files changed

Lines changed: 65 additions & 191 deletions

.ci/bootstrap_catdog.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -euv
3+
set -eu
44

55
GITHUB_EVENT_NAME="${GITHUB_EVENT_NAME:-not_pull_request}"
66
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]
@@ -23,8 +23,8 @@ sed -i "s/disabled_redis_runners: \[\]/disabled_redis_runners: [s3]/g" ../pulp_c
2323
cd ../pulp_catdog
2424

2525
# ignore unused imports
26-
flake8 .ci || exit 1 # check ci files before ignoring imports
27-
sed -i -e '/^ignore/s/$/,F401/' .flake8
26+
ruff check .ci || exit 1 # check ci files before ignoring imports
27+
echo $'[tool.ruff.lint]\nignore = [ "F401" ]' >> pyproject.toml
2828

2929
# include post_before_script to generate migrations
3030
cp ../plugin_template/.ci/post_before_script.sh .github/workflows/scripts

.ci/post_before_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
set -euv
3+
set -eu
44

55
cmd_prefix pulpcore-manager makemigrations
66
cmd_user_prefix pulpcore-manager migrate

.flake8

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ jobs:
3030
- name: "Lint plugin_template"
3131
working-directory: "plugin_template"
3232
run: |
33-
pip3 install black~=26.3 flake8
34-
black --version
35-
black --check --diff plugin-template utils.py
36-
flake8 plugin-template utils.py
33+
pip3 install ruff
34+
ruff format --check --diff plugin-template utils.py
35+
ruff check --diff plugin-template utils.py
3736
- name: "Bootstrap catdog plugin"
3837
working-directory: "plugin_template"
3938
run: |
@@ -49,16 +48,13 @@ jobs:
4948
run: |
5049
yamllint -s -d '{extends: relaxed, rules: {line-length: disable}}' .github/workflows
5150
52-
# run black separately from flake8 to get a diff
53-
- name: "Run black"
51+
- name: "Check formatting"
5452
run: |
55-
black --version
56-
black --check --diff .
53+
ruff format --check --diff
5754
58-
# Lint code.
59-
- name: "Run flake8"
55+
- name: "Lint code"
6056
run: |
61-
flake8
57+
ruff check --diff
6258
6359
- name: "Check for common gettext problems"
6460
run: |

README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ You can edit them according to your needs to control subsequent calls to `plugin
3636
The following settings are stored in `template_config.yml`.
3737

3838
```bash
39-
black Boolean, whether to use black to format python source files.
40-
41-
flake8 Boolean, whether to use flake8 to lint python source files.
42-
4339
check_commit_message Include inspection of commit message for a reference to an issue in
4440
pulp.plan.io.
4541

@@ -118,9 +114,6 @@ The following settings are stored in `template_config.yml`.
118114
layers in Containerfile configuring the base Pulp image. `<scenario>` is one
119115
of "azure", "s3", "gcp".
120116

121-
pydocstyle Boolean, whether to have flake8 use pydocstyle to check for compliance with
122-
Python docstring conventions.
123-
124117
release_user The GitHub user that is associated with the RELEASE_TOKEN secret on GitHub.
125118
The username and token are used to push the Changelog and version bump commits
126119
created by the release workflow. The default is 'pulpbot'.

plugin-template

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# /// script
33
# requires-python = ">=3.11"
44
# dependencies = [
5-
# "black~=26.3",
6-
# "jamldump>=1.2.0,<1.3.0",
7-
# "jinja2>=3.1.6,<3.2.0",
5+
# "jamldump>=1.2.0,<1.3",
6+
# "jinja2>=3.1.6,<3.2",
87
# "packaging>=26.0,<27",
9-
# "pyyaml>=6.0.3,<6.1.0",
8+
# "pyyaml>=6.0.3,<6.1",
109
# "requests~=2.32.3",
11-
# "requests-cache>=1.3.0,<1.4.0",
12-
# "tomlkit>=0.14.0,<0.14.1",
10+
# "requests-cache>=1.3.0,<1.4",
11+
# "ruff>=0.15.11,<0.16",
12+
# "tomlkit>=0.14.0,<0.15",
1313
# ]
1414
# ///
1515

@@ -29,7 +29,6 @@ from jinja2 import Environment, FileSystemLoader
2929
import utils
3030

3131
DEFAULT_SETTINGS = {
32-
"black": True,
3332
"check_commit_message": True,
3433
"check_gettext": True,
3534
"check_manifest": True,
@@ -46,10 +45,9 @@ DEFAULT_SETTINGS = {
4645
"disabled_redis_runners": [],
4746
"docker_fixtures": False,
4847
"extra_files": [],
49-
"flake8_ignore": [],
50-
"flake8": True,
5148
"github_org": "pulp",
5249
"latest_release_branch": None,
50+
"lint_ignore": [],
5351
"lint_requirements": True,
5452
"os_required_packages": [],
5553
"parallel_test_workers": 8,
@@ -130,7 +128,6 @@ DEFAULT_SETTINGS = {
130128
},
131129
},
132130
},
133-
"pydocstyle": True,
134131
"release_email": "pulp-infra@redhat.com",
135132
"release_user": "pulpbot",
136133
"stalebot_days_until_close": 30,
@@ -170,6 +167,7 @@ DEPRECATED_FILES = {
170167
".ci/scripts/update_github.sh",
171168
".ci/scripts/update_redmine.sh",
172169
".ci/scripts/upper_bound.py",
170+
".flake8",
173171
".github/template_gitref",
174172
".github/workflows/kanban.yml",
175173
".github/workflows/changelog.yml",
@@ -188,6 +186,7 @@ DEPRECATED_FILES = {
188186
".github/workflows/scripts/publish_plugin_pypi.sh",
189187
".travis",
190188
".travis.yml",
189+
"dev_requirements.txt",
191190
"flake8.cfg",
192191
"CHANGES/.TEMPLATE.rst",
193192
],
@@ -321,10 +320,20 @@ def load_config(plugin_config_path: Path, verbose: bool) -> tuple[dict[str, t.An
321320
# Migrate api_root to (scenario) setting
322321
if config["pulp_settings"] is None:
323322
config["pulp_settings"] = {}
324-
config["pulp_settings"].setdefault("api_root", config.get("api_root", "/pulp/"))
323+
write_new_config = True
324+
if "api_root" not in config["pulp_settings"]:
325+
config["pulp_settings"]["api_root"] = "/pulp/"
326+
write_new_config = True
325327
if config["pulp_settings_s3"] is None:
326328
config["pulp_settings_s3"] = {}
327-
config["pulp_settings_s3"].setdefault("api_root", "/rerouted/djnd/")
329+
write_new_config = True
330+
if "api_root" not in config["pulp_settings_s3"]:
331+
config["pulp_settings_s3"]["api_root"] = "/rerouted/djnd/"
332+
write_new_config = True
333+
# Migrate flake8_ignore
334+
if "flake8_ignore" in config:
335+
config["lint_ignore"] = config.pop("flake8_ignore")
336+
write_new_config = True
328337
# remove deprecated options
329338
for key in set(config.keys()) - set(DEFAULT_SETTINGS.keys()):
330339
config.pop(key)
@@ -385,7 +394,6 @@ def write_template_section(
385394
"current_version": utils.current_version(plugin_root_dir),
386395
"pulpdocs_branch": PULPDOCS_BRANCH,
387396
"is_pulpdocs_member": config["plugin_name"] in utils.get_pulpdocs_members(PULPDOCS_BRANCH),
388-
"black_requirement": utils.black_requirement(),
389397
"config": config,
390398
**config,
391399
}
@@ -501,11 +509,10 @@ def remove_deprecated_files(plugin_root_dir: Path, sections: list[str]) -> None:
501509

502510

503511
def reformat_files(plugin_root_dir: Path, config: dict[str, t.Any]) -> None:
504-
if config["black"]:
505-
try:
506-
subprocess.run(["black", "--quiet", "."], cwd=plugin_root_dir)
507-
except FileNotFoundError:
508-
pass
512+
try:
513+
subprocess.run(["ruff", "format"], cwd=plugin_root_dir)
514+
except FileNotFoundError:
515+
pass
509516

510517

511518
if __name__ == "__main__":

pyproject.toml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,6 @@ title_format = "{version} ({project_date})"
66
template = "CHANGES/.TEMPLATE.rst"
77
issue_format = "`#{issue} <https://github.com/pulp/plugin_template/issues/{issue}>`__"
88

9-
[tool.black]
9+
[tool.ruff]
1010
line-length = 100
11-
target-version = ["py36", "py37", "py38"]
12-
exclude = '''
13-
/(
14-
\.eggs
15-
| \.git
16-
| \.venv
17-
| _build
18-
| build
19-
| dist
20-
| migrations
21-
| docs
22-
)/
23-
'''
11+
extend-exclude = ["templates"]

requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# This (black) is copied into templates/github/lint_requirement.txt.j2
2-
black~=26.3 # Pin style to the year. https://black.readthedocs.io/en/stable/faq.html#how-stable-is-black-s-style
31
jamldump>=1.2.0,<1.3.0
42
jinja2
53
packaging>=26.0,<27
64
pyyaml
75
requests~=2.32.3
86
requests_cache
7+
ruff
98
tomlkit

scripts/update_ci.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ fi
2020

2121
PLUGIN_NAME="$(python ../plugin_template/scripts/get_template_config_value.py plugin_name)"
2222
CI_UPDATE_DOCS="$(python ../plugin_template/scripts/get_template_config_value.py ci_update_docs)"
23-
USE_BLACK="$(python ../plugin_template/scripts/get_template_config_value.py black)"
2423

2524
if [[ "${CI_UPDATE_DOCS}" == "True" ]]; then
2625
DOCS=("--docs")

templates/bootstrap/pyproject.toml.j2

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,16 @@ underlines = ["", "", ""]
8282
name = "Misc"
8383
showcontent = false
8484
85-
{% if black %}
86-
[tool.black]
87-
line-length = 100
88-
target-version = ["py39", "py310", "py311", "py312"]
89-
exclude = '''
90-
/(
91-
\.eggs
92-
| \.git
93-
| \.venv
94-
| _build
95-
| build
96-
| dist
97-
| migrations
98-
| docs
99-
| protobuf
100-
)/
101-
'''
102-
{% endif %}
103-
10485
{% if check_manifest %}
10586
[tool.check-manifest]
10687
ignore = [
10788
".git-blame-ignore-revs",
10889
"AGENTS.md",
10990
"CHANGES/**",
11091
"CLAUDE.md",
111-
"dev_requirements.txt",
11292
"doc_requirements.txt",
11393
"lint_requirements.txt",
11494
"docs/**",
115-
".flake8",
11695
"template_config.yml",
11796
".coveragerc",
11897
".dependabot/config.yml",

0 commit comments

Comments
 (0)