-
Notifications
You must be signed in to change notification settings - Fork 57
feat: check for deprecated setup.cfg settings #572
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
+134
−28
Merged
Changes from all commits
Commits
Show all changes
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,3 +155,9 @@ _readthedocs | |
|
||
# Default cookiecutter output | ||
/package | ||
|
||
# VSCode | ||
/.vscode | ||
|
||
# UV output | ||
/uv.lock |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# SCFG: setup.cfg | ||
## SCFG0xx: setup.cfg checks | ||
|
||
from __future__ import annotations | ||
|
||
import configparser | ||
|
||
from .._compat.importlib.resources.abc import Traversable | ||
from . import mk_url | ||
|
||
|
||
def setupcfg(root: Traversable) -> configparser.ConfigParser | None: | ||
setupcfg_path = root.joinpath("setup.cfg") | ||
if setupcfg_path.is_file(): | ||
config = configparser.ConfigParser() | ||
with setupcfg_path.open("r") as f: | ||
config.read_file(f) | ||
return config | ||
return None | ||
|
||
|
||
class SCFG: | ||
family = "setupcfg" | ||
|
||
|
||
class SCFG001(SCFG): | ||
"Avoid deprecated setup.cfg names" | ||
|
||
url = mk_url("packaging-classic") | ||
|
||
@staticmethod | ||
def check(setupcfg: configparser.ConfigParser | None) -> str | None: | ||
if setupcfg is None: | ||
return None | ||
invalid = [] | ||
if setupcfg.has_section("metadata"): | ||
invalid += [ | ||
f"metadata.{x}" for x, _ in setupcfg.items("metadata") if "-" in x | ||
] | ||
if setupcfg.has_section("options"): | ||
invalid += [ | ||
f"options.{x}" for x, _ in setupcfg.items("options") if "-" in x | ||
] | ||
if invalid: | ||
return ( | ||
"Invalid setup.cfg options found, only underscores allowed: " | ||
+ ", ".join(invalid) | ||
) | ||
return "" | ||
|
||
|
||
def repo_review_checks() -> dict[str, SCFG]: | ||
return {p.__name__: p() for p in SCFG.__subclasses__()} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import configparser | ||
|
||
from repo_review.testing import compute_check | ||
|
||
|
||
def test_scfg001(): | ||
setupcfg = configparser.ConfigParser() | ||
setupcfg.read_string(""" | ||
[metadata] | ||
name = foo | ||
version = 1.0 | ||
description = A test package | ||
author = Me | ||
author_email = [email protected] | ||
""") | ||
assert compute_check("SCFG001", setupcfg=setupcfg).result | ||
|
||
|
||
def test_scfg001_invalid(): | ||
setupcfg = configparser.ConfigParser() | ||
setupcfg.read_string(""" | ||
[metadata] | ||
name = foo | ||
version = 1.0 | ||
description = A test package | ||
author = Me | ||
author-email = [email protected] | ||
""") | ||
answer = compute_check("SCFG001", setupcfg=setupcfg) | ||
assert not answer.result | ||
assert "metadata.author-email" in answer.err_msg | ||
|
||
|
||
def test_no_setupcfg(): | ||
assert compute_check("SCFG001", setupcfg=None).result is None |
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.
Uh oh!
There was an error while loading. Please reload this page.