Skip to content

Commit b7fec70

Browse files
authored
Update ruff config (#542)
* Update ruff config * update test paths * fix path * python 3.12 compat * address warning
1 parent 8be3098 commit b7fec70

File tree

19 files changed

+126
-121
lines changed

19 files changed

+126
-121
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
fail-fast: false
4141
matrix:
4242
os: [ubuntu-latest, windows-latest, macos-latest]
43-
python-version: ["3.8", "3.11"]
43+
python-version: ["3.8", "3.12"]
4444
steps:
4545
- uses: actions/checkout@v4
4646
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
- id: trailing-whitespace
2222

2323
- repo: https://github.com/python-jsonschema/check-jsonschema
24-
rev: 0.27.2
24+
rev: 0.27.3
2525
hooks:
2626
- id: check-github-workflows
2727

@@ -33,7 +33,7 @@ repos:
3333
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]
3434

3535
- repo: https://github.com/pre-commit/mirrors-prettier
36-
rev: "v3.0.3"
36+
rev: "v3.1.0"
3737
hooks:
3838
- id: prettier
3939
types_or: [yaml, html, json]
@@ -44,7 +44,7 @@ repos:
4444
hooks:
4545
- id: mypy
4646
files: "^jupyter_releaser"
47-
exclude: "jupyter_releaser/tests"
47+
exclude: "tests"
4848
stages: [manual]
4949
args: ["--install-types", "--non-interactive"]
5050
additional_dependencies:
@@ -70,7 +70,7 @@ repos:
7070
- id: rst-inline-touching-normal
7171

7272
- repo: https://github.com/astral-sh/ruff-pre-commit
73-
rev: v0.1.6
73+
rev: v0.1.8
7474
hooks:
7575
- id: ruff
7676
args: ["--fix", "--show-fixes"]

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# -- Project information -----------------------------------------------------
2121

2222
project = "Jupyter Releaser"
23-
copyright = "2021, Project Jupyter" # noqa
23+
copyright = "2021, Project Jupyter"
2424
author = "Project Jupyter"
2525

2626
# The full version, including alpha/beta/rc tags.
@@ -42,7 +42,7 @@
4242
]
4343

4444
try:
45-
import enchant # type:ignore # noqa
45+
import enchant # noqa: F401
4646

4747
extensions += ["sphinxcontrib.spelling"]
4848
except ImportError:

jupyter_releaser/changelog.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_version_entry(
5858
since_last_stable=None,
5959
until=None,
6060
auth=None,
61-
resolve_backports=False,
61+
resolve_backports=False, # noqa: ARG001
6262
dry_run=False,
6363
):
6464
"""Get a changelog for the changes since the last tag on the given branch.
@@ -143,14 +143,12 @@ def get_version_entry(
143143
if "# Documentation improvements" in entry and "# Documentation improvements\n\n-" not in entry:
144144
entry = re.sub(r"#+ Documentation improvements\n\n", "", entry)
145145

146-
output = f"""
146+
return f"""
147147
## {version}
148148
149149
{entry}
150150
""".strip()
151151

152-
return output
153-
154152

155153
def build_entry(
156154
ref, branch, repo, auth, changelog_path, since, since_last_stable, resolve_backports
@@ -295,13 +293,13 @@ def insert_entry(
295293
return format(changelog)
296294

297295

298-
def format(changelog: str) -> str: # noqa A001
296+
def format(changelog: str) -> str:
299297
"""Clean up changelog formatting"""
300298
changelog = re.sub(r"\n\n+", r"\n\n", changelog)
301299
return re.sub(r"\n\n+$", r"\n", changelog)
302300

303301

304-
def check_entry( # noqa
302+
def check_entry(
305303
ref,
306304
branch,
307305
repo,

jupyter_releaser/cli.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
class ReleaseHelperGroup(click.Group):
1616
"""Click group tailored to jupyter-releaser"""
1717

18-
_needs_checkout_dir: t.Dict[str, bool] = {} # noqa
18+
_needs_checkout_dir: t.Dict[str, bool] = {} # noqa: RUF012
1919

20-
def invoke(self, ctx): # noqa
20+
def invoke(self, ctx):
2121
"""Handle jupyter-releaser config while invoking a command"""
2222
# Get the command name and make sure it is valid
2323
cmd_name = ctx.protected_args[0]
@@ -96,12 +96,11 @@ def invoke(self, ctx): # noqa
9696
ctx.args.append(arg)
9797
ctx.args.append(val)
9898
continue
99-
else:
100-
val = ctx.args[ctx.args.index(arg) + 1]
101-
if "token" in name.lower():
102-
val = "***"
103-
util.log(f"Using cli arg for {name}: '{val}'")
104-
continue
99+
val = ctx.args[ctx.args.index(arg) + 1]
100+
if "token" in name.lower():
101+
val = "***"
102+
util.log(f"Using cli arg for {name}: '{val}'")
103+
continue
105104

106105
util.log(f"Using default value for {name}: '{param.default}'")
107106

@@ -141,16 +140,15 @@ def invoke(self, ctx): # noqa
141140

142141
os.chdir(orig_dir)
143142

144-
def list_commands(self, ctx):
143+
def list_commands(self, ctx): # noqa: ARG002
145144
"""List commands in insertion order"""
146145
return self.commands.keys()
147146

148147

149148
@click.group(cls=ReleaseHelperGroup)
150149
@click.option("--force", default=False, help="Force a command to run even when skipped by config")
151-
def main(force):
150+
def main(force): # noqa: ARG001
152151
"""Jupyter Releaser scripts"""
153-
pass
154152

155153

156154
# Extracted common options
@@ -357,7 +355,6 @@ def inner(func):
357355
def list_envvars():
358356
"""List the environment variables"""
359357
# This is implemented in ReleaseHelperGroup.invoke
360-
pass
361358

362359

363360
@main.command()
@@ -709,7 +706,7 @@ def publish_release(auth, dry_run, release_url, silent):
709706
"--expected-sha", help="The expected sha of the branch HEAD", envvar="RH_EXPECTED_SHA"
710707
)
711708
@use_checkout_dir()
712-
def ensure_sha(ref, branch, repo, dry_run, expected_sha):
709+
def ensure_sha(ref, branch, repo, dry_run, expected_sha): # noqa: ARG001
713710
"""Ensure that a sha has not changed."""
714711
util.ensure_sha(dry_run, expected_sha, branch)
715712

@@ -735,7 +732,7 @@ def forwardport_changelog(auth, ref, branch, repo, username, changelog_path, dry
735732
@add_options(changelog_path_options)
736733
@add_options(dry_run_options)
737734
@use_checkout_dir()
738-
def publish_changelog(auth, ref, branch, repo, changelog_path, dry_run):
735+
def publish_changelog(auth, ref, branch, repo, changelog_path, dry_run): # noqa: ARG001
739736
"""Remove changelog placeholder entries."""
740737
lib.publish_changelog(branch, repo, auth, changelog_path, dry_run)
741738

jupyter_releaser/lib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ def tag_release(dist_dir, release_message, tag_format, tag_message, no_git_tag_w
230230

231231

232232
def populate_release(
233-
ref,
233+
ref, # noqa: ARG001
234234
branch,
235-
repo,
235+
repo, # noqa: ARG001
236236
version_cmd,
237237
auth,
238238
changelog_path,
@@ -355,7 +355,7 @@ def extract_release(auth, dist_dir, dry_run, release_url):
355355
os.chdir(orig_dir)
356356

357357

358-
def publish_assets( # noqa
358+
def publish_assets(
359359
auth,
360360
dist_dir,
361361
npm_token,
@@ -396,7 +396,7 @@ def publish_assets( # noqa
396396

397397
res = python_package.split(":")
398398
python_package_path = res[0]
399-
python_package_name = res[1].replace("-", "_") if len(res) == 2 else "" # noqa
399+
python_package_name = res[1].replace("-", "_") if len(res) == 2 else ""
400400

401401
if release_url and len(glob(f"{dist_dir}/*.whl")):
402402
twine_token = python.get_pypi_token(release_url, python_package_path)
@@ -474,7 +474,7 @@ def publish_release(auth, dry_run, release_url, silent):
474474
util.actions_output("release_url", release.html_url)
475475

476476

477-
def prep_git(ref, branch, repo, auth, username, url): # noqa
477+
def prep_git(ref, branch, repo, auth, username, url):
478478
"""Set up git"""
479479
repo = repo or util.get_repo()
480480

@@ -570,7 +570,7 @@ def extract_changelog(dry_run, auth, changelog_path, release_url, silent=False):
570570
changelog.update_changelog(changelog_path, changelog_text, silent=silent)
571571

572572

573-
def forwardport_changelog(auth, ref, branch, repo, username, changelog_path, dry_run, release_url):
573+
def forwardport_changelog(auth, ref, branch, repo, username, changelog_path, dry_run, release_url): # noqa: ARG001
574574
"""Forwardport Changelog Entries to the Default Branch"""
575575
# Set up the git repo with the branch
576576
match = util.parse_release_url(release_url)

jupyter_releaser/mock_github.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def write_to_file(name, data):
6060
class Asset(BaseModel):
6161
"""An asset model."""
6262

63-
id: int # noqa
63+
id: int
6464
name: str
6565
content_type: str
6666
size: int
@@ -86,7 +86,7 @@ class Release(BaseModel):
8686
published_at: str = ""
8787
draft: bool
8888
body: str = ""
89-
id: int # noqa
89+
id: int
9090
node_id: str = ""
9191
author: str = ""
9292
html_url: str
@@ -124,7 +124,7 @@ class Tag(BaseModel):
124124
"""A tag model."""
125125

126126
ref: str
127-
object: TagObject # noqa
127+
object: TagObject
128128

129129

130130
releases: Dict[str, "Release"] = load_from_file("releases", Release)

jupyter_releaser/npm.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
PACKAGE_JSON = util.PACKAGE_JSON
1616

1717

18+
# Python 3.12+ gives a deprecation warning if TarFile.extraction_filter is None.
19+
# https://docs.python.org/3.12/library/tarfile.html#tarfile-extraction-filter
20+
if hasattr(tarfile, "fully_trusted_filter"):
21+
tarfile.TarFile.extraction_filter = staticmethod(tarfile.fully_trusted_filter) # type:ignore[assignment]
22+
23+
1824
def build_dist(package, dist_dir):
1925
"""Build npm dist file(s) from a package"""
2026
# Clean the dist folder of existing npm tarballs

jupyter_releaser/python.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
PYPROJECT = util.PYPROJECT
2222
SETUP_PY = util.SETUP_PY
2323

24-
PYPI_GH_API_TOKEN_URL = "https://pypi.org/_/oidc/github/mint-token" # noqa
24+
PYPI_GH_API_TOKEN_URL = "https://pypi.org/_/oidc/github/mint-token" # noqa: S105
2525

2626

2727
def build_dist(dist_dir, clean=True):
@@ -70,7 +70,7 @@ def check_dist(
7070
# run the test command in the venv
7171
with TemporaryDirectory() as td:
7272
env_path = util.normalize_path(osp.abspath(td))
73-
if os.name == "nt": # noqa # pragma: no cover
73+
if os.name == "nt": # pragma: no cover # noqa: SIM108
7474
bin_path = f"{env_path}/Scripts/"
7575
else:
7676
bin_path = f"{env_path}/bin"
@@ -185,7 +185,7 @@ def start_local_pypi():
185185
"""Start a local PyPI server"""
186186
temp_dir = TemporaryDirectory()
187187
cmd = f"pypi-server run -p 8081 -P . -a . -o -v {temp_dir.name}"
188-
proc = Popen(shlex.split(cmd), stdout=PIPE) # noqa
188+
proc = Popen(shlex.split(cmd), stdout=PIPE) # noqa: S603
189189
# Wait for the server to start
190190
while True:
191191
assert proc.stdout is not None

jupyter_releaser/tee.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ async def _read_stream(stream: StreamReader, callback: Callable[..., Any]) -> No
5252
break
5353

5454

55-
async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess: # noqa
55+
async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess:
5656
platform_settings: Dict[str, Any] = {}
5757
if platform.system() == "Windows":
5858
platform_settings["env"] = os.environ
@@ -61,10 +61,10 @@ async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess: # n
6161
tee = kwargs.get("tee", True)
6262
stdout = kwargs.get("stdout", sys.stdout)
6363
if stdout == subprocess.DEVNULL or not tee:
64-
stdout = open(os.devnull, "w") # noqa
64+
stdout = open(os.devnull, "w") # noqa: SIM115
6565
stderr = kwargs.get("stderr", sys.stderr)
6666
if stderr == subprocess.DEVNULL or not tee:
67-
stderr = open(os.devnull, "w") # noqa
67+
stderr = open(os.devnull, "w") # noqa: SIM115
6868

6969
# We need to tell subprocess which shell to use when running shell-like
7070
# commands.
@@ -91,7 +91,7 @@ async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess: # n
9191
out: List[str] = []
9292
err: List[str] = []
9393

94-
def tee_func(line: bytes, sink: List[str], pipe: Optional[Any]) -> None:
94+
def tee_func(line: bytes, sink: List[str], pipe: Optional[Any]) -> None: # noqa: ARG001
9595
line_str = line.decode("utf-8").rstrip()
9696
sink.append(line_str)
9797
if not kwargs.get("quiet", False):
@@ -137,7 +137,7 @@ def run(args: Union[str, List[str]], **kwargs: Any) -> CompletedProcess:
137137
quiet: False - Avoid printing output
138138
show_cwd: False - Prints the current working directory.
139139
"""
140-
if isinstance(args, str): # noqa
140+
if isinstance(args, str): # noqa: SIM108
141141
cmd = args
142142
else:
143143
# run was called with a list instead of a single item but asyncio

0 commit comments

Comments
 (0)