Skip to content
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

Adopt ruff format and sp-repo-review #532

Merged
merged 8 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 35 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ci:
autoupdate_schedule: monthly
autoupdate_commit_msg: "chore: update pre-commit hooks"

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
Expand Down Expand Up @@ -31,13 +32,41 @@ repos:
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/psf/black
rev: 23.9.1
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v3.0.3"
hooks:
- id: black
- id: prettier
types_or: [yaml, html, json]
exclude: '.pre-commit-config.yaml'

- 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/pre-commit/pygrep-hooks
rev: "v1.10.0"
hooks:
- id: rst-backticks
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.3
hooks:
- id: ruff
args: ["--fix"]
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]"]
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ python:
build:
os: ubuntu-22.04
tools:
python: "3.11"
python: "3.11"
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/source/how_to_guides/write_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion jupyter_releaser/actions/generate_changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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------------------------------")
Expand Down
2 changes: 1 addition & 1 deletion jupyter_releaser/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion jupyter_releaser/mock_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 2 additions & 1 deletion jupyter_releaser/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pathlib import Path
from subprocess import PIPE, CalledProcessError, Popen
from tempfile import TemporaryDirectory
from typing import cast

import requests

Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions jupyter_releaser/tee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jupyter_releaser/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions jupyter_releaser/tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,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
Expand All @@ -228,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
Expand Down Expand Up @@ -392,7 +392,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")

Expand Down
15 changes: 12 additions & 3 deletions jupyter_releaser/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down
71 changes: 30 additions & 41 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ test = [
"pytest>=7.0",
"pytest-mock",
"pytest-xdist[psutil]",
"uvicorn"
"uvicorn",
"ruamel.yaml"
]

[project.scripts]
Expand Down Expand Up @@ -89,27 +90,26 @@ 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 = [
"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}"
]

Expand All @@ -120,7 +120,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/"
]
Expand Down Expand Up @@ -150,43 +157,22 @@ 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

[tool.black]
line-length = 100
skip-string-normalization = true
target-version = ["py37"]
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 = "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",
]
Expand Down Expand Up @@ -215,7 +201,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
Expand All @@ -236,3 +222,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", "PY005"]
Loading