From bc1cc15c5c303b319621a2b33e83d5de010e8fd8 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 15:45:13 -0500 Subject: [PATCH 1/8] adopt ruff format --- .pre-commit-config.yaml | 6 ++-- docs/source/conf.py | 1 + jupyter_releaser/mock_github.py | 10 +++++-- jupyter_releaser/tests/test_cli.py | 46 ++++++++++++++++++++++-------- pyproject.toml | 20 ++++++------- 5 files changed, 53 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b9f9b354..770bab8f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-case-conflict - id: check-ast @@ -32,12 +32,12 @@ repos: [mdformat-gfm, mdformat-frontmatter, mdformat-footnote] - repo: https://github.com/psf/black - rev: 23.9.1 + rev: 23.10.1 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.292 + rev: v0.1.3 hooks: - id: ruff args: ["--fix"] diff --git a/docs/source/conf.py b/docs/source/conf.py index e008e7a7..286782ff 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -77,6 +77,7 @@ # Add an Edit this Page button html_theme_options = { "use_edit_page_button": True, + "navigation_with_keys": False, } # Output for github to be used in links diff --git a/jupyter_releaser/mock_github.py b/jupyter_releaser/mock_github.py index f4a2d5aa..1a87c7db 100644 --- a/jupyter_releaser/mock_github.py +++ b/jupyter_releaser/mock_github.py @@ -48,7 +48,7 @@ def write_to_file(name, data): for key in data: value = data[key] if isinstance(value, BaseModel): - if hasattr(value, 'model_dump_json'): + if hasattr(value, "model_dump_json"): value = json.loads(value.model_dump_json()) else: value = json.loads(value.json()) @@ -171,7 +171,9 @@ async def create_a_release(owner: str, repo: str, request: Request) -> Release: @app.patch("/repos/{owner}/{repo}/releases/{release_id}") -async def update_a_release(owner: str, repo: str, release_id: int, request: Request) -> Release: +async def update_a_release( + owner: str, repo: str, release_id: int, request: Request +) -> Release: """https://docs.github.com/en/rest/releases/releases#update-a-release""" data = await request.json() model = releases[str(release_id)] @@ -182,7 +184,9 @@ async def update_a_release(owner: str, repo: str, release_id: int, request: Requ @app.post("/repos/{owner}/{repo}/releases/{release_id}/assets") -async def upload_a_release_asset(owner: str, repo: str, release_id: int, request: Request) -> None: +async def upload_a_release_asset( + owner: str, repo: str, release_id: int, request: Request +) -> None: """https://docs.github.com/en/rest/releases/assets#upload-a-release-asset""" base_url = get_mock_github_url() model = releases[str(release_id)] diff --git a/jupyter_releaser/tests/test_cli.py b/jupyter_releaser/tests/test_cli.py index a0a08cf5..145b1fed 100644 --- a/jupyter_releaser/tests/test_cli.py +++ b/jupyter_releaser/tests/test_cli.py @@ -127,7 +127,9 @@ def test_bump_version(npm_package, runner): def test_bump_version_bad_version(py_package, runner): runner(["prep-git", "--git-url", py_package]) with pytest.raises(CalledProcessError): - runner(["bump-version", "--version-spec", "a1.0.1"], env=dict(GITHUB_ACTIONS="")) + runner( + ["bump-version", "--version-spec", "a1.0.1"], env=dict(GITHUB_ACTIONS="") + ) def test_bump_version_tag_exists(py_package, runner): @@ -341,7 +343,9 @@ def test_draft_changelog_dry_run(npm_package, mocker, runner, git_prep): del os.environ["RH_SINCE_LAST_STABLE"] -def test_draft_changelog_lerna(workspace_package, mocker, runner, mock_github, git_prep): +def test_draft_changelog_lerna( + workspace_package, mocker, runner, mock_github, git_prep +): mock_changelog_entry(workspace_package, runner, mocker) runner(["draft-changelog", "--version-spec", VERSION_SPEC]) @@ -378,7 +382,9 @@ def test_check_python_different_names( monkeypatch.setenv("RH_CHECK_IMPORTS", "foobar") -def test_check_python_resource_path(monkeypatch, py_package, runner, build_mock, git_prep): +def test_check_python_resource_path( + monkeypatch, py_package, runner, build_mock, git_prep +): monkeypatch.setenv("RH_PYDIST_RESOURCE_PATHS", "foo/bar/baz.txt") # Convert the package to use a package dir. @@ -392,7 +398,7 @@ def test_check_python_resource_path(monkeypatch, py_package, runner, build_mock, path.write_text("hello", encoding="utf-8") pyproject = Path(util.CHECKOUT_NAME / util.PYPROJECT) - pyproject_text = pyproject.read_text('utf-8') + pyproject_text = pyproject.read_text("utf-8") pyproject_text = pyproject_text.replace("foo.py", "foo/__init__.py") pyproject.write_text(pyproject_text, "utf-8") @@ -516,7 +522,9 @@ def test_extract_dist_py(py_package, runner, mocker, mock_github, tmp_path, git_ os.name == "nt" and sys.version_info < (3, 8), reason="See https://bugs.python.org/issue26660", ) -def test_extract_dist_multipy(py_multipackage, runner, mocker, mock_github, tmp_path, git_prep): +def test_extract_dist_multipy( + py_multipackage, runner, mocker, mock_github, tmp_path, git_prep +): git_repo = py_multipackage[0]["abs_path"] changelog_entry = mock_changelog_entry(git_repo, runner, mocker) @@ -564,7 +572,9 @@ def test_extract_dist_npm(npm_dist, runner, mocker, mock_github, tmp_path): assert "after-extract-release" in log -@pytest.mark.skipif(os.name == "nt", reason="pypiserver does not start properly on Windows") +@pytest.mark.skipif( + os.name == "nt", reason="pypiserver does not start properly on Windows" +) def test_publish_assets_py(py_package, runner, mocker, git_prep, mock_github): # Create the dist files changelog_entry = mock_changelog_entry(py_package, runner, mocker) @@ -612,11 +622,15 @@ def wrapped(cmd, **kwargs): mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped) - runner(["publish-assets", "--npm-cmd", "npm publish --dry-run", "--dist-dir", dist_dir]) + runner( + ["publish-assets", "--npm-cmd", "npm publish --dry-run", "--dist-dir", dist_dir] + ) assert called == 3, called -def test_publish_assets_npm_exists(npm_dist, runner, mocker, mock_github, draft_release): +def test_publish_assets_npm_exists( + npm_dist, runner, mocker, mock_github, draft_release +): os.environ["RH_RELEASE_URL"] = draft_release dist_dir = npm_dist / util.CHECKOUT_NAME / "dist" called = 0 @@ -646,7 +660,9 @@ def wrapped(cmd, **kwargs): assert called == 3, called -def test_publish_assets_npm_all_exists(npm_dist, runner, mocker, mock_github, draft_release): +def test_publish_assets_npm_all_exists( + npm_dist, runner, mocker, mock_github, draft_release +): os.environ["RH_RELEASE_URL"] = draft_release dist_dir = npm_dist / util.CHECKOUT_NAME / "dist" called = 0 @@ -753,7 +769,9 @@ def wrapped(cmd, **kwargs): assert "after-build-python" in log -def test_forwardport_changelog_no_new(npm_package, runner, mocker, mock_github, git_prep): +def test_forwardport_changelog_no_new( + npm_package, runner, mocker, mock_github, git_prep +): release = create_draft_release("bar") os.environ["RH_RELEASE_URL"] = release.html_url @@ -772,7 +790,9 @@ def test_forwardport_changelog_no_new(npm_package, runner, mocker, mock_github, assert "after-forwardport-changelog" in log -def test_forwardport_changelog_has_new(npm_package, runner, mocker, mock_github, git_prep): +def test_forwardport_changelog_has_new( + npm_package, runner, mocker, mock_github, git_prep +): release = create_draft_release("bar") os.environ["RH_RELEASE_URL"] = release.html_url @@ -783,7 +803,9 @@ def test_forwardport_changelog_has_new(npm_package, runner, mocker, mock_github, util.run("git push origin backport_branch", cwd=util.CHECKOUT_NAME) util.run(f"git checkout {current}") mock_changelog_entry(npm_package, runner, mocker) - util.run(f'git commit -a -m "Add changelog entry {VERSION_SPEC}"', cwd=util.CHECKOUT_NAME) + util.run( + f'git commit -a -m "Add changelog entry {VERSION_SPEC}"', cwd=util.CHECKOUT_NAME + ) util.run(f"git tag v{VERSION_SPEC}", cwd=util.CHECKOUT_NAME) util.run(f"git checkout {current}", cwd=util.CHECKOUT_NAME) util.run("git push origin backport_branch --tags", cwd=util.CHECKOUT_NAME) diff --git a/pyproject.toml b/pyproject.toml index 42328378..52b5b611 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,21 +95,20 @@ test = "mypy --install-types --non-interactive {args:jupyter_releaser}" [tool.hatch.envs.lint] dependencies = [ - "black==23.3.0", "mdformat>0.7", "mdformat-gfm>=0.3.5", - "ruff==0.0.287" + "ruff==0.1.3" ] detached = true [tool.hatch.envs.lint.scripts] style = [ "ruff {args:.}", - "black --check --diff {args:.}", + "ruff format {args:.}", "mdformat --check {args:docs *.md}" ] fmt = [ - "black {args:.}", "ruff --fix {args:.}", + "ruff format {args:.}", "mdformat {args:docs *.md}" ] @@ -177,16 +176,13 @@ module = [ ] ignore_missing_imports = true -[tool.black] -line-length = 100 -skip-string-normalization = true -target-version = ["py37"] - [tool.ruff] -target-version = "py37" +target-version = "py38" line-length = 100 + +[tool.ruff.lint] select = [ - "A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "ISC", "N", + "A", "B", "C", "DTZ", "E", "EM", "F", "FBT", "I", "ICN", "N", "PLC", "PLE", "PLR", "PLW", "Q", "RUF", "S", "SIM", "T", "TID", "UP", "W", "YTT", ] @@ -215,7 +211,7 @@ unfixable = [ "RUF100", ] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] # B011 Do not call assert False since python -O removes these calls # F841 local variable 'foo' is assigned to but never used # C408 Unnecessary `dict` call From f94cdd12029d686321be76b09592455a8edc2d14 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 15:47:18 -0500 Subject: [PATCH 2/8] fix spelling --- .pre-commit-config.yaml | 14 ++++--- docs/source/how_to_guides/write_config.md | 2 +- jupyter_releaser/mock_github.py | 8 +--- jupyter_releaser/tests/conftest.py | 2 +- jupyter_releaser/tests/test_cli.py | 48 ++++++----------------- 5 files changed, 25 insertions(+), 49 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 770bab8f..6765fdd2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,6 +24,12 @@ repos: hooks: - id: check-github-workflows + - repo: https://github.com/codespell-project/codespell + rev: "v2.2.6" + hooks: + - id: codespell + args: ["-L", "sur,nd"] + - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 hooks: @@ -31,13 +37,9 @@ repos: additional_dependencies: [mdformat-gfm, mdformat-frontmatter, mdformat-footnote] - - repo: https://github.com/psf/black - rev: 23.10.1 - hooks: - - id: black - - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.3 hooks: - id: ruff - args: ["--fix"] + args: ["--fix", "--show-fixes"] + - id: ruff-format diff --git a/docs/source/how_to_guides/write_config.md b/docs/source/how_to_guides/write_config.md index b0bf08bd..75840d8c 100644 --- a/docs/source/how_to_guides/write_config.md +++ b/docs/source/how_to_guides/write_config.md @@ -10,7 +10,7 @@ by running `jupyter-releaser list-envvars`. ## Default Values, Options, Skip, and Hooks -The default values can also be overriden using a config file. +The default values can also be overridden using a config file. Options can be overridden using the `options` section. diff --git a/jupyter_releaser/mock_github.py b/jupyter_releaser/mock_github.py index 1a87c7db..3fff4296 100644 --- a/jupyter_releaser/mock_github.py +++ b/jupyter_releaser/mock_github.py @@ -171,9 +171,7 @@ async def create_a_release(owner: str, repo: str, request: Request) -> Release: @app.patch("/repos/{owner}/{repo}/releases/{release_id}") -async def update_a_release( - owner: str, repo: str, release_id: int, request: Request -) -> Release: +async def update_a_release(owner: str, repo: str, release_id: int, request: Request) -> Release: """https://docs.github.com/en/rest/releases/releases#update-a-release""" data = await request.json() model = releases[str(release_id)] @@ -184,9 +182,7 @@ async def update_a_release( @app.post("/repos/{owner}/{repo}/releases/{release_id}/assets") -async def upload_a_release_asset( - owner: str, repo: str, release_id: int, request: Request -) -> None: +async def upload_a_release_asset(owner: str, repo: str, release_id: int, request: Request) -> None: """https://docs.github.com/en/rest/releases/assets#upload-a-release-asset""" base_url = get_mock_github_url() model = releases[str(release_id)] diff --git a/jupyter_releaser/tests/conftest.py b/jupyter_releaser/tests/conftest.py index 139fc26e..0674b4f4 100644 --- a/jupyter_releaser/tests/conftest.py +++ b/jupyter_releaser/tests/conftest.py @@ -160,7 +160,7 @@ def run(*args, **kwargs): if result.exit_code != 0: if result.stderr_bytes: print("Captured stderr\n", result.stderr, "\n\n") - print("Catpured stdout\n", result.stdout, "\n\n") + print("Captured stdout\n", result.stdout, "\n\n") assert result.exception is not None raise result.exception diff --git a/jupyter_releaser/tests/test_cli.py b/jupyter_releaser/tests/test_cli.py index 145b1fed..ec13ccef 100644 --- a/jupyter_releaser/tests/test_cli.py +++ b/jupyter_releaser/tests/test_cli.py @@ -127,9 +127,7 @@ def test_bump_version(npm_package, runner): def test_bump_version_bad_version(py_package, runner): runner(["prep-git", "--git-url", py_package]) with pytest.raises(CalledProcessError): - runner( - ["bump-version", "--version-spec", "a1.0.1"], env=dict(GITHUB_ACTIONS="") - ) + runner(["bump-version", "--version-spec", "a1.0.1"], env=dict(GITHUB_ACTIONS="")) def test_bump_version_tag_exists(py_package, runner): @@ -220,7 +218,7 @@ def test_build_changelog_existing(py_package, mocker, runner): runner(["build-changelog", "--changelog-path", changelog_file]) text = changelog_path.read_text(encoding="utf-8") - text = text.replace("defining contributions", "Definining contributions") + text = text.replace("defining contributions", "Defining contributions") changelog_path.write_text(text, encoding="utf-8") # Commit the change @@ -230,7 +228,7 @@ def test_build_changelog_existing(py_package, mocker, runner): runner(["build-changelog", "--changelog-path", changelog_file]) text = changelog_path.read_text(encoding="utf-8") - assert "Definining contributions" in text, text + assert "Defining contributions" in text, text assert "defining contributions" not in text, text assert len(re.findall(changelog.START_MARKER, text)) == 1 @@ -343,9 +341,7 @@ def test_draft_changelog_dry_run(npm_package, mocker, runner, git_prep): del os.environ["RH_SINCE_LAST_STABLE"] -def test_draft_changelog_lerna( - workspace_package, mocker, runner, mock_github, git_prep -): +def test_draft_changelog_lerna(workspace_package, mocker, runner, mock_github, git_prep): mock_changelog_entry(workspace_package, runner, mocker) runner(["draft-changelog", "--version-spec", VERSION_SPEC]) @@ -382,9 +378,7 @@ def test_check_python_different_names( monkeypatch.setenv("RH_CHECK_IMPORTS", "foobar") -def test_check_python_resource_path( - monkeypatch, py_package, runner, build_mock, git_prep -): +def test_check_python_resource_path(monkeypatch, py_package, runner, build_mock, git_prep): monkeypatch.setenv("RH_PYDIST_RESOURCE_PATHS", "foo/bar/baz.txt") # Convert the package to use a package dir. @@ -522,9 +516,7 @@ def test_extract_dist_py(py_package, runner, mocker, mock_github, tmp_path, git_ os.name == "nt" and sys.version_info < (3, 8), reason="See https://bugs.python.org/issue26660", ) -def test_extract_dist_multipy( - py_multipackage, runner, mocker, mock_github, tmp_path, git_prep -): +def test_extract_dist_multipy(py_multipackage, runner, mocker, mock_github, tmp_path, git_prep): git_repo = py_multipackage[0]["abs_path"] changelog_entry = mock_changelog_entry(git_repo, runner, mocker) @@ -572,9 +564,7 @@ def test_extract_dist_npm(npm_dist, runner, mocker, mock_github, tmp_path): assert "after-extract-release" in log -@pytest.mark.skipif( - os.name == "nt", reason="pypiserver does not start properly on Windows" -) +@pytest.mark.skipif(os.name == "nt", reason="pypiserver does not start properly on Windows") def test_publish_assets_py(py_package, runner, mocker, git_prep, mock_github): # Create the dist files changelog_entry = mock_changelog_entry(py_package, runner, mocker) @@ -622,15 +612,11 @@ def wrapped(cmd, **kwargs): mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped) - runner( - ["publish-assets", "--npm-cmd", "npm publish --dry-run", "--dist-dir", dist_dir] - ) + runner(["publish-assets", "--npm-cmd", "npm publish --dry-run", "--dist-dir", dist_dir]) assert called == 3, called -def test_publish_assets_npm_exists( - npm_dist, runner, mocker, mock_github, draft_release -): +def test_publish_assets_npm_exists(npm_dist, runner, mocker, mock_github, draft_release): os.environ["RH_RELEASE_URL"] = draft_release dist_dir = npm_dist / util.CHECKOUT_NAME / "dist" called = 0 @@ -660,9 +646,7 @@ def wrapped(cmd, **kwargs): assert called == 3, called -def test_publish_assets_npm_all_exists( - npm_dist, runner, mocker, mock_github, draft_release -): +def test_publish_assets_npm_all_exists(npm_dist, runner, mocker, mock_github, draft_release): os.environ["RH_RELEASE_URL"] = draft_release dist_dir = npm_dist / util.CHECKOUT_NAME / "dist" called = 0 @@ -769,9 +753,7 @@ def wrapped(cmd, **kwargs): assert "after-build-python" in log -def test_forwardport_changelog_no_new( - npm_package, runner, mocker, mock_github, git_prep -): +def test_forwardport_changelog_no_new(npm_package, runner, mocker, mock_github, git_prep): release = create_draft_release("bar") os.environ["RH_RELEASE_URL"] = release.html_url @@ -790,9 +772,7 @@ def test_forwardport_changelog_no_new( assert "after-forwardport-changelog" in log -def test_forwardport_changelog_has_new( - npm_package, runner, mocker, mock_github, git_prep -): +def test_forwardport_changelog_has_new(npm_package, runner, mocker, mock_github, git_prep): release = create_draft_release("bar") os.environ["RH_RELEASE_URL"] = release.html_url @@ -803,9 +783,7 @@ def test_forwardport_changelog_has_new( util.run("git push origin backport_branch", cwd=util.CHECKOUT_NAME) util.run(f"git checkout {current}") mock_changelog_entry(npm_package, runner, mocker) - util.run( - f'git commit -a -m "Add changelog entry {VERSION_SPEC}"', cwd=util.CHECKOUT_NAME - ) + util.run(f'git commit -a -m "Add changelog entry {VERSION_SPEC}"', cwd=util.CHECKOUT_NAME) util.run(f"git tag v{VERSION_SPEC}", cwd=util.CHECKOUT_NAME) util.run(f"git checkout {current}", cwd=util.CHECKOUT_NAME) util.run("git push origin backport_branch --tags", cwd=util.CHECKOUT_NAME) From 6ddee6880b59d5c49dec04c5277099167d71c590 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 15:54:51 -0500 Subject: [PATCH 3/8] adopt sp-repo-review --- .pre-commit-config.yaml | 36 +++++++++++++++++++++++++++----- pyproject.toml | 46 ++++++++++++++++------------------------- 2 files changed, 49 insertions(+), 33 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6765fdd2..12f2648f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,6 @@ ci: autoupdate_schedule: monthly + autoupdate_commit_msg: "chore: update pre-commit hooks" repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -24,18 +25,37 @@ repos: hooks: - id: check-github-workflows + - repo: https://github.com/executablebooks/mdformat + rev: 0.7.17 + hooks: + - id: mdformat + additional_dependencies: + [mdformat-gfm, mdformat-frontmatter, mdformat-footnote] + + - repo: https://github.com/pre-commit/mirrors-prettier + rev: "v3.0.3" + hooks: + - id: prettier + types_or: [yaml, html, json] + + - repo: https://github.com/adamchainz/blacken-docs + rev: "1.16.0" + hooks: + - id: blacken-docs + additional_dependencies: [black==23.7.0] + - repo: https://github.com/codespell-project/codespell rev: "v2.2.6" hooks: - id: codespell args: ["-L", "sur,nd"] - - repo: https://github.com/executablebooks/mdformat - rev: 0.7.17 + - repo: https://github.com/pre-commit/pygrep-hooks + rev: "v1.10.0" hooks: - - id: mdformat - additional_dependencies: - [mdformat-gfm, mdformat-frontmatter, mdformat-footnote] + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.3 @@ -43,3 +63,9 @@ repos: - id: ruff args: ["--fix", "--show-fixes"] - id: ruff-format + + - repo: https://github.com/scientific-python/cookie + rev: "2023.10.27" + hooks: + - id: sp-repo-review + additional_dependencies: ["repo-review[cli]"] diff --git a/pyproject.toml b/pyproject.toml index 52b5b611..4f5a2261 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,9 +89,9 @@ nowarn = "test -W default {args}" [tool.hatch.envs.typing] features = ["test"] -dependencies = ["mypy>=0.990"] +dependencies = ["mypy~=1.6"] [tool.hatch.envs.typing.scripts] -test = "mypy --install-types --non-interactive {args:jupyter_releaser}" +test = "mypy --install-types --non-interactive {args}" [tool.hatch.envs.lint] dependencies = [ @@ -119,7 +119,14 @@ after-populate-release = "bash ./.github/scripts/bump_tag.sh" post-version-spec = "dev" [tool.pytest.ini_options] -addopts = "-raXs --durations 10 --color=yes --doctest-modules -p no:pastebin -p no:nose" +minversion = "6.0" +xfail_strict = true +log_cli_level = "info" +addopts = [ + "-raXs", "--durations=10", "--color=yes", "--doctest-modules", + "--showlocals", "--strict-markers", "--strict-config", + "-p=no:pastebin", "-p=no:nose" +] testpaths = [ "jupyter_releaser/tests/" ] @@ -149,32 +156,12 @@ relative_files = true source = ["jupyter_releaser"] [tool.mypy] -check_untyped_defs = true -disallow_any_generics = false -disallow_incomplete_defs = true -disallow_untyped_decorators = true -no_implicit_optional = true -no_implicit_reexport = false -pretty = true -show_error_context = true +files = "jupyter_releaser" +python_version = "3.8" +strict = true show_error_codes = true -strict_equality = true -strict_optional = true -warn_unused_configs = true -warn_redundant_casts = true -warn_return_any = false -warn_unused_ignores = true - -[[tool.mypy.overrides]] -module = [ - "toml.*", - "jsonschema", - "ghapi.*", - "github_activity", - "pkginfo", - "pypandoc", -] -ignore_missing_imports = true +enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] +warn_unreachable = true [tool.ruff] target-version = "py38" @@ -232,3 +219,6 @@ ignore-nested-functions=true ignore-nested-classes=true fail-under=100 exclude = ["jupyter_releaser/tests"] + +[tool.repo-review] +ignore = ["PY004", "PY007","PP301", "PC140", "PP308", "GH102"] From e9b27cbed6b37e270ad850976055a887734a8539 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 16:00:01 -0500 Subject: [PATCH 4/8] adopt sp-repo-review --- jupyter_releaser/actions/generate_changelog.py | 2 +- jupyter_releaser/changelog.py | 2 +- jupyter_releaser/python.py | 3 ++- jupyter_releaser/tee.py | 4 ++-- jupyter_releaser/util.py | 8 ++++---- pyproject.toml | 2 ++ 6 files changed, 12 insertions(+), 9 deletions(-) diff --git a/jupyter_releaser/actions/generate_changelog.py b/jupyter_releaser/actions/generate_changelog.py index 2677157b..37e942e1 100644 --- a/jupyter_releaser/actions/generate_changelog.py +++ b/jupyter_releaser/actions/generate_changelog.py @@ -28,7 +28,7 @@ output = get_version_entry(ref, branch, target, "current", since=since, until=until) if convert_to_rst.lower() == "true": - from pypandoc import convert_text + from pypandoc import convert_text # type:ignore[import-not-found] output = convert_text(output, "rst", "markdown") log("\n\n------------------------------") diff --git a/jupyter_releaser/changelog.py b/jupyter_releaser/changelog.py index ffc02357..c9d43a23 100644 --- a/jupyter_releaser/changelog.py +++ b/jupyter_releaser/changelog.py @@ -4,7 +4,7 @@ import re from pathlib import Path -from github_activity import generate_activity_md +from github_activity import generate_activity_md # type:ignore[import-untyped] from jupyter_releaser import util diff --git a/jupyter_releaser/python.py b/jupyter_releaser/python.py index a85a9c19..5e4360e4 100644 --- a/jupyter_releaser/python.py +++ b/jupyter_releaser/python.py @@ -12,6 +12,7 @@ from pathlib import Path from subprocess import PIPE, CalledProcessError, Popen from tempfile import TemporaryDirectory +from typing import cast import requests @@ -142,7 +143,7 @@ def fetch_pypi_api_token() -> "str": sink.seek(0) api_token = json.loads(sink.read().decode("utf-8")).get("token", "") - return api_token + return cast(str, api_token) def get_pypi_token(release_url, python_package): diff --git a/jupyter_releaser/tee.py b/jupyter_releaser/tee.py index 2934a41a..e182ca89 100644 --- a/jupyter_releaser/tee.py +++ b/jupyter_releaser/tee.py @@ -37,7 +37,7 @@ try: from shlex import join except ImportError: - from subprocess import list2cmdline as join # type:ignore + from subprocess import list2cmdline as join # type:ignore[assignment] STREAM_LIMIT = 2**23 # 8MB instead of default 64kb, override it if you need @@ -70,7 +70,7 @@ async def _stream_subprocess(args: str, **kwargs: Any) -> CompletedProcess: # n # commands. # * SHELL is not always defined # * /bin/bash does not exit on alpine, /bin/sh seems bit more portable - if "executable" not in kwargs and isinstance(args, str) and " " in args: + if "executable" not in kwargs and isinstance(args, str) and " " in args: # type:ignore[redundant-expr] platform_settings["executable"] = os.environ.get("SHELL", "/bin/sh") # pass kwargs we know to be supported diff --git a/jupyter_releaser/util.py b/jupyter_releaser/util.py index d08d44ac..83d3891c 100644 --- a/jupyter_releaser/util.py +++ b/jupyter_releaser/util.py @@ -23,7 +23,7 @@ import requests import toml -from ghapi import core +from ghapi import core # type:ignore[import-untyped] from importlib_resources import files from jsonschema import Draft4Validator as Validator from packaging.version import Version @@ -386,7 +386,7 @@ def latest_draft_release(gh, branch=None): continue created = release.created_at d_created = datetime.strptime(created, r"%Y-%m-%dT%H:%M:%SZ") # noqa - if newest_time is None or d_created > newest_time: + if newest_time is None or d_created > newest_time: # type:ignore[unreachable] newest_time = d_created newest_release = release if not newest_release: @@ -688,7 +688,7 @@ def get_remote_name(dry_run): return "origin" if _local_remote: - try: + try: # type:ignore[unreachable] run(f"git remote add test {_local_remote}") except Exception: # noqa pass @@ -725,7 +725,7 @@ def ensure_mock_github(): python = sys.executable.replace(os.sep, "/") try: import fastapi # noqa - import univcorn # type: ignore # noqa + import univcorn # type:ignore[import-not-found] # noqa except ImportError: run(f"'{python}' -m pip install fastapi uvicorn") diff --git a/pyproject.toml b/pyproject.toml index 4f5a2261..bcd5bce0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -160,8 +160,10 @@ files = "jupyter_releaser" python_version = "3.8" strict = true show_error_codes = true +disable_error_code = [ "no-untyped-call", "no-untyped-def"] enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"] warn_unreachable = true +exclude = ["jupyter_releaser/tests"] [tool.ruff] target-version = "py38" From a878a3dd802b2504d4571388a01543743b88aeb5 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 16:01:50 -0500 Subject: [PATCH 5/8] cleanup --- .github/workflows/test.yml | 4 ++-- .readthedocs.yml | 2 +- pyproject.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d2b763d8..92c6c47d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,8 +20,8 @@ jobs: steps: - uses: actions/checkout@v4 - uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1 - - name: Run Linters - run: | + - name: Run Linters + run: | hatch run typing:test hatch run lint:style pipx run interrogate -v jupyter_releaser diff --git a/.readthedocs.yml b/.readthedocs.yml index 099c1265..1862a1bb 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -11,4 +11,4 @@ python: build: os: ubuntu-22.04 tools: - python: "3.11" + python: "3.11" diff --git a/pyproject.toml b/pyproject.toml index bcd5bce0..a0ad8090 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -223,4 +223,4 @@ fail-under=100 exclude = ["jupyter_releaser/tests"] [tool.repo-review] -ignore = ["PY004", "PY007","PP301", "PC140", "PP308", "GH102"] +ignore = ["PY004", "PY007","PP301", "PC140", "PP308", "GH102", "PY005"] From 5c0f0cd57296f418988dcacc968f13626f7d5d09 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 16:03:59 -0500 Subject: [PATCH 6/8] fix test running --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a0ad8090..a60f121e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -125,7 +125,7 @@ log_cli_level = "info" addopts = [ "-raXs", "--durations=10", "--color=yes", "--doctest-modules", "--showlocals", "--strict-markers", "--strict-config", - "-p=no:pastebin", "-p=no:nose" + "-p", "no:pastebin", "-p", "no:nose" ] testpaths = [ "jupyter_releaser/tests/" From 4bf8c3de67b8942b5b9e681c00e72ad4e58d5e98 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 16:47:35 -0500 Subject: [PATCH 7/8] make sp-repo-review manual --- .pre-commit-config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 12f2648f..51db10cf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -66,6 +66,7 @@ repos: - repo: https://github.com/scientific-python/cookie rev: "2023.10.27" + stages: [manual] hooks: - id: sp-repo-review additional_dependencies: ["repo-review[cli]"] From 026da7cc9851c7b856cbf82e9a5bbb8473c29fbc Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Sun, 29 Oct 2023 19:07:06 -0500 Subject: [PATCH 8/8] fix handling of pre-commit --- .pre-commit-config.yaml | 2 +- jupyter_releaser/tests/util.py | 15 ++++++++++++--- pyproject.toml | 3 ++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 51db10cf..383d9174 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,6 +37,7 @@ repos: hooks: - id: prettier types_or: [yaml, html, json] + exclude: '.pre-commit-config.yaml' - repo: https://github.com/adamchainz/blacken-docs rev: "1.16.0" @@ -66,7 +67,6 @@ repos: - repo: https://github.com/scientific-python/cookie rev: "2023.10.27" - stages: [manual] hooks: - id: sp-repo-review additional_dependencies: ["repo-review[cli]"] diff --git a/jupyter_releaser/tests/util.py b/jupyter_releaser/tests/util.py index 9475aeae..8b665495 100644 --- a/jupyter_releaser/tests/util.py +++ b/jupyter_releaser/tests/util.py @@ -6,6 +6,7 @@ from pathlib import Path from ghapi.core import GhApi +from ruamel.yaml import YAML from jupyter_releaser import changelog, cli, util from jupyter_releaser.util import run @@ -201,11 +202,19 @@ def write_files(git_repo, sub_packages=None, package_name="foo", module_name=Non here = Path(__file__).parent text = here.parent.parent.joinpath(".pre-commit-config.yaml").read_text(encoding="utf-8") - readme = git_repo / "README.md" - readme.write_text(README_TEMPLATE, encoding="utf-8") + # Remove sp-repo-review and don't check yaml files. + yaml = YAML(typ="safe") + table = yaml.load(text) + for item in list(table["repos"]): + if item["repo"] == "https://github.com/scientific-python/cookie": + table["repos"].remove(item) pre_commit = git_repo / ".pre-commit-config.yaml" - pre_commit.write_text(text, encoding="utf-8") + with open(str(pre_commit), "w") as fid: + yaml.dump(table, fid) + + readme = git_repo / "README.md" + readme.write_text(README_TEMPLATE, encoding="utf-8") sub_packages = [] if multi: diff --git a/pyproject.toml b/pyproject.toml index a60f121e..c26f54ef 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,8 @@ test = [ "pytest>=7.0", "pytest-mock", "pytest-xdist[psutil]", - "uvicorn" + "uvicorn", + "ruamel.yaml" ] [project.scripts]