-
Notifications
You must be signed in to change notification settings - Fork 49
Switch linting and formatting to ruff #1292
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,29 +3,28 @@ LANGUAGES=de | |
| GLUE_PLUGINS=$(notdir $(wildcard pulp-glue/pulp_glue/*)) | ||
| CLI_PLUGINS=$(notdir $(wildcard pulpcore/cli/*)) | ||
|
|
||
| .PHONY: info | ||
| info: | ||
| @echo Pulp glue | ||
| @echo plugins: $(GLUE_PLUGINS) | ||
| @echo Pulp CLI | ||
| @echo plugins: $(CLI_PLUGINS) | ||
|
|
||
| .PHONY: build | ||
| build: | ||
| cd pulp-glue; pyproject-build -n | ||
| pyproject-build -n | ||
|
|
||
| black: format | ||
|
|
||
| .PHONY: format | ||
| format: | ||
| isort . | ||
| cd pulp-glue; isort . | ||
| black . | ||
| ruff format | ||
| ruff check --fix | ||
|
|
||
| .PHONY: lint | ||
| lint: | ||
| find tests .ci -name '*.sh' -print0 | xargs -0 shellcheck -x | ||
| isort -c --diff . | ||
| cd pulp-glue; isort -c --diff . | ||
| black --diff --check . | ||
| flake8 | ||
| ruff format --check --diff | ||
| ruff check --diff | ||
| .ci/scripts/check_click_for_mypy.py | ||
| MYPYPATH=pulp-glue mypy | ||
| cd pulp-glue; mypy | ||
|
|
@@ -35,21 +34,27 @@ tests/cli.toml: | |
| cp [email protected] $@ | ||
| @echo "In order to configure the tests to talk to your test server, you might need to edit $@ ." | ||
|
|
||
| .PHONY: test | ||
| test: | tests/cli.toml | ||
| python3 -m pytest -v tests pulp-glue/tests cookiecutter/pulp_filter_extension.py | ||
|
|
||
| .PHONY: livetest | ||
| livetest: | tests/cli.toml | ||
| python3 -m pytest -v tests pulp-glue/tests -m live | ||
|
|
||
| .PHONY: unittest | ||
| unittest: | ||
| python3 -m pytest -v tests pulp-glue/tests cookiecutter/pulp_filter_extension.py -m "not live" | ||
|
|
||
| .PHONY: unittest_glue | ||
| unittest_glue: | ||
| python3 -m pytest -v pulp-glue/tests -m "not live" | ||
|
|
||
| .PHONY: docs | ||
| docs: | ||
| pulp-docs build | ||
|
|
||
| .PHONY: servedocs | ||
| servedocs: | ||
| pulp-docs serve -w CHANGES.md -w pulp-glue/pulp_glue -w pulp_cli/generic.py | ||
|
|
||
|
|
@@ -61,6 +66,7 @@ pulpcore/cli/%/locale/messages.pot: pulpcore/cli/%/*.py | |
| xgettext -d $* -o $@ pulpcore/cli/$*/*.py | ||
| sed -i 's/charset=CHARSET/charset=UTF-8/g' $@ | ||
|
|
||
| .PHONY: extract_messages | ||
| extract_messages: $(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/messages.pot) $(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/messages.pot) | ||
|
|
||
| $(foreach LANGUAGE,$(LANGUAGES),pulp-glue/pulp_glue/%/locale/$(LANGUAGE)/LC_MESSAGES/messages.po): pulp-glue/pulp_glue/%/locale/messages.pot | ||
|
|
@@ -76,6 +82,7 @@ $(foreach LANGUAGE,$(LANGUAGES),pulpcore/cli/%/locale/$(LANGUAGE)/LC_MESSAGES/me | |
| %.mo: %.po | ||
| msgfmt -o $@ $< | ||
|
|
||
| .PHONY: compile_messages | ||
| compile_messages: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.mo)) | ||
| .PHONY: build info black lint test docs servedocs | ||
|
|
||
| .PRECIOUS: $(foreach LANGUAGE,$(LANGUAGES),$(foreach GLUE_PLUGIN,$(GLUE_PLUGINS),pulp-glue/pulp_glue/$(GLUE_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po)) $(foreach LANGUAGE,$(LANGUAGES),$(foreach CLI_PLUGIN,$(CLI_PLUGINS),pulpcore/cli/$(CLI_PLUGIN)/locale/$(LANGUAGE)/LC_MESSAGES/messages.po)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/calc_constraints.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| #!/bin/python3 | ||
| # /// script | ||
| # requires-python = ">=3.10" | ||
| # dependencies = [ | ||
| # "packaging>=25.0,<25.1", | ||
| # "tomli>=2.3.0,<2.4.0;python_version<'3.11'", | ||
| # ] | ||
| # /// | ||
|
|
||
| import argparse | ||
| import fileinput | ||
| import sys | ||
|
|
||
| from packaging.requirements import Requirement | ||
| from packaging.version import Version | ||
|
|
||
| try: | ||
| import tomllib | ||
| except ImportError: | ||
| import tomli as tomllib | ||
|
|
||
|
|
||
| def split_comment(line): | ||
| split_line = line.split("#", maxsplit=1) | ||
| try: | ||
| comment = " # " + split_line[1].strip() | ||
| except IndexError: | ||
| comment = "" | ||
| return split_line[0].strip(), comment | ||
|
|
||
|
|
||
| def to_upper_bound(req): | ||
| try: | ||
| requirement = Requirement(req) | ||
| except ValueError: | ||
| return f"# UNPARSABLE: {req}" | ||
| else: | ||
| for spec in requirement.specifier: | ||
| if spec.operator == "~=": | ||
| return f"# NO BETTER CONSTRAINT: {req}" | ||
| if spec.operator == "<=": | ||
| operator = "==" | ||
| max_version = spec.version | ||
| return f"{requirement.name}{operator}{max_version}" | ||
| if spec.operator == "<": | ||
| operator = "~=" | ||
| version = Version(spec.version) | ||
| if version.micro != 0: | ||
| max_version = f"{version.major}.{version.minor}.{version.micro - 1}" | ||
| elif version.minor != 0: | ||
| max_version = f"{version.major}.{version.minor - 1}" | ||
| elif version.major != 0: | ||
| max_version = f"{version.major - 1}.0" | ||
| else: | ||
| return f"# NO BETTER CONSTRAINT: {req}" | ||
| return f"{requirement.name}{operator}{max_version}" | ||
| return f"# NO UPPER BOUND: {req}" | ||
|
|
||
|
|
||
| def to_lower_bound(req): | ||
| try: | ||
| requirement = Requirement(req) | ||
| except ValueError: | ||
| return f"# UNPARSABLE: {req}" | ||
| else: | ||
| for spec in requirement.specifier: | ||
| if spec.operator == ">=": | ||
| if requirement.name == "pulpcore": | ||
| # Currently an exception to allow for pulpcore bugfix releases. | ||
| # TODO Semver libraries should be allowed too. | ||
| operator = "~=" | ||
| else: | ||
| operator = "==" | ||
| min_version = spec.version | ||
| return f"{requirement.name}{operator}{min_version}" | ||
| return f"# NO LOWER BOUND: {req}" | ||
|
|
||
|
|
||
| def main(): | ||
| """Calculate constraints for the lower bound of dependencies where possible.""" | ||
| parser = argparse.ArgumentParser( | ||
| prog=sys.argv[0], | ||
| description="Calculate constraints for the lower or upper bound of dependencies where " | ||
| "possible.", | ||
| ) | ||
| parser.add_argument("-u", "--upper", action="store_true") | ||
| parser.add_argument("filename", nargs="*") | ||
| args = parser.parse_args() | ||
|
|
||
| modifier = to_upper_bound if args.upper else to_lower_bound | ||
|
|
||
| req_files = [filename for filename in args.filename if not filename.endswith("pyproject.toml")] | ||
| pyp_files = [filename for filename in args.filename if filename.endswith("pyproject.toml")] | ||
| if req_files: | ||
| with fileinput.input(files=req_files) as req_file: | ||
| for line in req_file: | ||
| if line.strip().startswith("#"): | ||
| # Shortcut comment only lines | ||
| print(line.strip()) | ||
| else: | ||
| req, comment = split_comment(line) | ||
| new_req = modifier(req) | ||
| print(new_req + comment) | ||
| for filename in pyp_files: | ||
| with open(filename, "rb") as fp: | ||
| pyproject = tomllib.load(fp) | ||
| for req in pyproject["project"]["dependencies"]: | ||
| new_req = modifier(req) | ||
| print(new_req) | ||
| optional_dependencies = pyproject["project"].get("optional-dependencies") | ||
| if optional_dependencies: | ||
| for opt in optional_dependencies.values(): | ||
| for req in opt: | ||
| new_req = modifier(req) | ||
| print(new_req) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
9 changes: 8 additions & 1 deletion
9
cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/check_cli_dependencies.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
cookiecutter/ci/{{ cookiecutter.__project_name }}/.ci/scripts/check_click_for_mypy.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like that in-file dependency for scripts.