Skip to content

Commit 018a91e

Browse files
committed
clean up pre-commit
1 parent 414f434 commit 018a91e

18 files changed

+143
-216
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@ on:
33
push:
44
branches: ["main"]
55
pull_request:
6-
branches: ["*"]
6+
77
jobs:
8-
# Run "pre-commit run --all-files"
8+
# Run "pre-commit run --all-files --hook-stage=manual"
99
pre-commit:
1010
runs-on: ubuntu-20.04
11-
timeout-minutes: 2
12-
11+
timeout-minutes: 5
1312
steps:
1413
- uses: actions/checkout@v2
15-
- uses: actions/setup-python@v2
16-
with:
17-
python-version: "3.10"
18-
19-
# ref: https://github.com/pre-commit/action
14+
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
2015
- uses: pre-commit/[email protected]
16+
with:
17+
extra_args: --all-files --hook-stage=manual
2118
- name: Help message if pre-commit fail
2219
if: ${{ failure() }}
2320
run: |
@@ -27,7 +24,7 @@ jobs:
2724
echo "or you can run by hand on staged files with"
2825
echo " pre-commit run"
2926
echo "or after-the-fact on already committed files with"
30-
echo " pre-commit run --all-files"
27+
echo " pre-commit run --all-files --hook-stage=manual"
3128
3229
check-links:
3330
runs-on: ubuntu-20.04
@@ -43,11 +40,11 @@ jobs:
4340
uses: ./.github/actions/check-links
4441

4542
test:
46-
runs-on: ${{ matrix.os }}-latest
43+
runs-on: ${{ matrix.os }}
4744
strategy:
4845
fail-fast: false
4946
matrix:
50-
os: [ubuntu, windows, macos]
47+
os: [ubuntu-latest, windows-latest, macos-latest]
5148
python-version: ["3.7", "3.10"]
5249
steps:
5350
- name: Checkout

.pre-commit-config.yaml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,52 @@
11
repos:
2-
- repo: https://github.com/asottile/reorder_python_imports
3-
rev: v3.0.1
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.1.0
44
hooks:
5-
- id: reorder-python-imports
5+
- id: end-of-file-fixer
6+
- id: check-case-conflict
7+
- id: check-executables-have-shebangs
8+
- id: requirements-txt-fixer
9+
- id: check-added-large-files
10+
- id: check-case-conflict
11+
- id: check-toml
12+
- id: check-yaml
13+
- id: debug-statements
14+
- id: forbid-new-submodules
15+
- id: check-builtin-literals
16+
- id: trailing-whitespace
17+
618
- repo: https://github.com/psf/black
719
rev: 22.3.0
820
hooks:
921
- id: black
22+
args: ["--line-length", "100"]
23+
24+
- repo: https://github.com/PyCQA/isort
25+
rev: 5.10.1
26+
hooks:
27+
- id: isort
28+
files: \.py$
29+
args: [--profile=black]
30+
1031
- repo: https://github.com/pre-commit/mirrors-prettier
1132
rev: v2.6.2
1233
hooks:
1334
- id: prettier
14-
- repo: https://github.com/PyCQA/flake8
15-
rev: "4.0.1"
35+
36+
- repo: https://github.com/asottile/pyupgrade
37+
rev: v2.31.1
1638
hooks:
17-
- id: flake8
18-
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v4.1.0
20-
hooks:
21-
- id: end-of-file-fixer
22-
- id: check-case-conflict
23-
- id: check-executables-have-shebangs
24-
- id: requirements-txt-fixer
25-
- repo: https://github.com/pre-commit/mirrors-pylint
26-
rev: v3.0.0a4
39+
- id: pyupgrade
40+
args: [--py37-plus]
41+
42+
- repo: https://github.com/pycqa/flake8
43+
rev: 4.0.1
2744
hooks:
28-
- id: pylint
29-
args: [--disable=all, --enable=unused-import]
45+
- id: flake8
46+
additional_dependencies:
47+
[
48+
"flake8-bugbear==20.1.4",
49+
"flake8-logging-format==0.6.0",
50+
"flake8-implicit-str-concat==0.2.0",
51+
]
52+
stages: [manual]

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pre-commit install
3535
You can also invoke the pre-commit hook manually at any time with
3636

3737
```bash
38-
pre-commit run
38+
pre-commit run --all-files --hook-stage manual
3939
```
4040

4141
Once you have done this, you can launch the main branch of Jupyter Releaser

jupyter_releaser/actions/check_links.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from jupyter_releaser.actions.common import run_action
2-
from jupyter_releaser.actions.common import setup
1+
from jupyter_releaser.actions.common import run_action, setup
32

43
setup()
54

jupyter_releaser/actions/draft_changelog.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
# Distributed under the terms of the Modified BSD License.
33
import os
44

5-
from jupyter_releaser.actions.common import make_group
6-
from jupyter_releaser.actions.common import run_action
7-
from jupyter_releaser.actions.common import setup
8-
from jupyter_releaser.util import CHECKOUT_NAME
9-
from jupyter_releaser.util import get_latest_tag
10-
from jupyter_releaser.util import log
5+
from jupyter_releaser.actions.common import make_group, run_action, setup
6+
from jupyter_releaser.util import CHECKOUT_NAME, get_latest_tag, log
117

128
setup()
139

jupyter_releaser/actions/draft_release.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
from pathlib import Path
66
from subprocess import CalledProcessError
77

8-
from jupyter_releaser.actions.common import make_group
9-
from jupyter_releaser.actions.common import run_action
10-
from jupyter_releaser.actions.common import setup
8+
from jupyter_releaser.actions.common import make_group, run_action, setup
119
from jupyter_releaser.changelog import extract_current
12-
from jupyter_releaser.util import CHECKOUT_NAME
13-
from jupyter_releaser.util import get_latest_tag
14-
from jupyter_releaser.util import log
15-
from jupyter_releaser.util import run
10+
from jupyter_releaser.util import CHECKOUT_NAME, get_latest_tag, log, run
1611

1712
setup()
1813

jupyter_releaser/actions/generate-changelog.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33

44
from jupyter_releaser.actions.common import run_action
55
from jupyter_releaser.changelog import get_version_entry
6-
from jupyter_releaser.util import CHECKOUT_NAME
7-
from jupyter_releaser.util import get_branch
6+
from jupyter_releaser.util import CHECKOUT_NAME, get_branch
87

98
target = os.environ.get("RH_REPOSITORY")
109
branch = os.environ.get("RH_BRANCH", "<default>")

jupyter_releaser/changelog.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ def get_version_entry(
132132
entry = "\n".join(entry).strip()
133133

134134
# Remove empty documentation entry if only automated changelogs were there
135-
if (
136-
"# Documentation improvements" in entry
137-
and not "# Documentation improvements\n\n-" in entry
138-
):
135+
if "# Documentation improvements" in entry and "# Documentation improvements\n\n-" not in entry:
139136
entry = re.sub(r"#+ Documentation improvements\n\n", "", entry)
140137

141138
output = f"""
@@ -201,7 +198,7 @@ def insert_entry(changelog, entry, version=None):
201198
pr = re.search(r"\[#\d+\]", line)
202199
if not pr:
203200
continue
204-
for old_line in prev_entry.splitlines():
201+
for old_line in old_lines:
205202
if pr.group() in old_line:
206203
lines[ind] = old_line
207204
changelog = changelog.replace(prev_entry, "\n".join(lines))
@@ -278,10 +275,10 @@ def check_entry(
278275
break
279276
if skip:
280277
continue
281-
if not f"[#{pr}]" in final_entry: # pragma: no cover
278+
if f"[#{pr}]" not in final_entry: # pragma: no cover
282279
raise ValueError(f"Missing PR #{pr} in changelog")
283280
for pr in final_prs:
284-
if not f"[#{pr}]" in raw_entry: # pragma: no cover
281+
if f"[#{pr}]" not in raw_entry: # pragma: no cover
285282
raise ValueError(f"PR #{pr} does not belong in changelog for {version}")
286283

287284
if output:

jupyter_releaser/cli.py

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,23 @@
77

88
import click
99

10-
from jupyter_releaser import changelog
11-
from jupyter_releaser import lib
12-
from jupyter_releaser import npm
13-
from jupyter_releaser import python
14-
from jupyter_releaser import util
10+
from jupyter_releaser import changelog, lib, npm, python, util
1511

1612

1713
class ReleaseHelperGroup(click.Group):
1814
"""Click group tailored to jupyter-releaser"""
1915

20-
_needs_checkout_dir = dict()
16+
_needs_checkout_dir = {}
2117

2218
def invoke(self, ctx):
2319
"""Handle jupyter-releaser config while invoking a command"""
2420
# Get the command name and make sure it is valid
2521
cmd_name = ctx.protected_args[0]
26-
if not cmd_name in self.commands:
22+
if cmd_name not in self.commands:
2723
super().invoke(ctx)
2824

2925
if cmd_name == "list-envvars":
30-
envvars = dict()
26+
envvars = {}
3127
for cmd_name in self.commands:
3228
for param in self.commands[cmd_name].params:
3329
if isinstance(param, click.Option):
@@ -126,9 +122,7 @@ def list_commands(self, ctx):
126122

127123

128124
@click.group(cls=ReleaseHelperGroup)
129-
@click.option(
130-
"--force", default=False, help="Force a command to run even when skipped by config"
131-
)
125+
@click.option("--force", default=False, help="Force a command to run even when skipped by config")
132126
def main(force):
133127
"""Jupyter Releaser scripts"""
134128
pass
@@ -145,9 +139,7 @@ def main(force):
145139
]
146140

147141
version_cmd_options = [
148-
click.option(
149-
"--version-cmd", envvar="RH_VERSION_COMMAND", help="The version command"
150-
)
142+
click.option("--version-cmd", envvar="RH_VERSION_COMMAND", help="The version command")
151143
]
152144

153145

@@ -161,9 +153,7 @@ def main(force):
161153
click.option("--auth", envvar="GITHUB_ACCESS_TOKEN", help="The GitHub auth token"),
162154
]
163155

164-
username_options = [
165-
click.option("--username", envvar="GITHUB_ACTOR", help="The git username")
166-
]
156+
username_options = [click.option("--username", envvar="GITHUB_ACTOR", help="The git username")]
167157

168158
dist_dir_options = [
169159
click.option(
@@ -195,15 +185,11 @@ def main(force):
195185
]
196186

197187
dry_run_options = [
198-
click.option(
199-
"--dry-run", is_flag=True, envvar="RH_DRY_RUN", help="Run as a dry run"
200-
)
188+
click.option("--dry-run", is_flag=True, envvar="RH_DRY_RUN", help="Run as a dry run")
201189
]
202190

203191

204-
git_url_options = [
205-
click.option("--git-url", help="A custom url for the git repository")
206-
]
192+
git_url_options = [click.option("--git-url", help="A custom url for the git repository")]
207193

208194

209195
changelog_path_options = [
@@ -370,9 +356,7 @@ def draft_changelog(
370356

371357
@main.command()
372358
@add_options(changelog_options)
373-
@click.option(
374-
"--output", envvar="RH_CHANGELOG_OUTPUT", help="The output file for changelog entry"
375-
)
359+
@click.option("--output", envvar="RH_CHANGELOG_OUTPUT", help="The output file for changelog entry")
376360
@use_checkout_dir()
377361
def check_changelog(
378362
ref,
@@ -414,9 +398,7 @@ def build_python(dist_dir, python_packages):
414398
f"Skipping build-python in {python_package} since there are no python package files"
415399
)
416400
else:
417-
python.build_dist(
418-
Path(os.path.relpath(".", python_package)) / dist_dir, clean=clean
419-
)
401+
python.build_dist(Path(os.path.relpath(".", python_package)) / dist_dir, clean=clean)
420402
clean = False
421403
os.chdir(prev_dir)
422404

@@ -433,9 +415,7 @@ def check_python(dist_dir, check_imports, pydist_check_cmd):
433415
util.log(f"Skipping non-python dist file {dist_file}")
434416
continue
435417

436-
python.check_dist(
437-
dist_file, python_imports=check_imports, check_cmd=pydist_check_cmd
438-
)
418+
python.check_dist(dist_file, python_imports=check_imports, check_cmd=pydist_check_cmd)
439419

440420

441421
@main.command()
@@ -528,13 +508,9 @@ def check_links(ignore_glob, ignore_links, cache_file, links_expire):
528508
help="Whether to skip tagging npm workspace packages",
529509
)
530510
@use_checkout_dir()
531-
def tag_release(
532-
dist_dir, release_message, tag_format, tag_message, no_git_tag_workspace
533-
):
511+
def tag_release(dist_dir, release_message, tag_format, tag_message, no_git_tag_workspace):
534512
"""Create release commit and tag"""
535-
lib.tag_release(
536-
dist_dir, release_message, tag_format, tag_message, no_git_tag_workspace
537-
)
513+
lib.tag_release(dist_dir, release_message, tag_format, tag_message, no_git_tag_workspace)
538514

539515

540516
@main.command()
@@ -698,9 +674,7 @@ def publish_release(auth, release_url):
698674
@add_options(dry_run_options)
699675
@click.argument("release-url")
700676
@use_checkout_dir()
701-
def forwardport_changelog(
702-
auth, ref, branch, repo, username, changelog_path, dry_run, release_url
703-
):
677+
def forwardport_changelog(auth, ref, branch, repo, username, changelog_path, dry_run, release_url):
704678
"""Forwardport Changelog Entries to the Default Branch"""
705679
lib.forwardport_changelog(
706680
auth, ref, branch, repo, username, changelog_path, dry_run, release_url

0 commit comments

Comments
 (0)