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 and address lint #165

Merged
merged 1 commit into from
Dec 7, 2022
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
2 changes: 1 addition & 1 deletion .github/actions/check-links/check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def check_links(ignore_glob, ignore_links, links_expire):
log(e.output.decode("utf-8"))
fails += 1
if fails == 3:
raise RuntimeError("Found three failed links, bailing")
raise RuntimeError("Found three failed links, bailing") from e
if fails:
raise RuntimeError(f"Encountered failures in {fails} file(s)")

Expand Down
6 changes: 4 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
version: 2
updates:
# Set update schedule for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
# Check for updates to GitHub Actions every week
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
13 changes: 9 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,17 @@ jobs:
python --version | grep "3.11"
hatch run check_pre

pre_commit:
test_lint:
name: Test Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/base-setup
- uses: ./.github/actions/pre-commit
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- name: Run Linters
run: |
hatch run typing:test
hatch run lint:style
pipx run 'validate-pyproject[all]' pyproject.toml

check_links:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -277,7 +282,7 @@ jobs:
if: always()
needs:
- base_setup
- pre_commit
- test_lint
- check_links
- binder_link
- pr_script
Expand Down
42 changes: 11 additions & 31 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ci:
skip: [check-jsonschema]
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -18,43 +18,23 @@ repos:
- id: check-builtin-literals
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.10.1
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
hooks:
- id: validate-pyproject
stages: [manual]
- id: check-github-workflows

- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat

- repo: https://github.com/john-hen/Flake8-pyproject
rev: 1.2.2
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: Flake8-pyproject
alias: flake8
additional_dependencies:
["flake8-bugbear==22.6.22", "flake8-implicit-str-concat==0.2.0"]
- id: black

- repo: https://github.com/sirosen/check-jsonschema
rev: 0.19.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.165
hooks:
- id: check-jsonschema
name: "Check GitHub Workflows"
files: ^\.github/workflows/
types: [yaml]
args: ["--schemafile", "https://json.schemastore.org/github-workflow"]
- id: ruff
args: ["--fix"]
113 changes: 94 additions & 19 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ authors = [{name = "Sir Robin", email = "robin@camelot.uk"}]
dynamic = ["description", "version"]
readme = "README.md"
dependencies = ["jupyter_core>=4.12,!=5.0.*"]
optional-dependencies.test = ["pytest"]

[project.optional-dependencies]
test = ["pytest>=7.0"]
lint = ["black>=22.6.0", "mdformat>0.7", "ruff>=0.0.156"]
typing = ["mypy>=0.990"]

[tool.jupyter-releaser]
skip = ["check-links", "publish-assets"]
skip = ["publish-assets"]
hooks.after-populate-release = ["bash ./.github/scripts/bump_tag.sh"]

[tool.hatch.version]
Expand All @@ -21,26 +25,97 @@ source = "nodejs"
check_minimum = "python -c 'from jupyter_core import __version__; assert __version__ == \"4.12.0\"'"
check_pre = "python -c 'import os; assert os.environ[\"PIP_PRE\"] == \"1\"'"

[tool.hatch.envs.typing]
features = ["typing"]
dependencies = ["mypy>=0.990"]
[tool.hatch.envs.typing.scripts]
test = "mypy --install-types --non-interactive {args:.}"

[tool.hatch.envs.lint]
features = ["lint"]
[tool.hatch.envs.lint.scripts]
style = [
"ruff {args:.}",
"black --check --diff {args:.}",
"mdformat --check {args:*.md}"
]
fmt = [
"black {args:.}",
"ruff --fix {args:.}",
"mdformat {args:*.md}"
]

[tool.pytest.ini_options]
testpaths = ["foobar.py"]

[tool.flake8]
ignore = "E501, W503, E402"
builtins = "c, get_config"
exclude = [
".cache",
".github",
"docs",
"setup.py",
[tool.mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_decorators = true
explicit_package_bases = true
namespace_packages = true
no_implicit_optional = true
no_implicit_reexport = true
pretty = true
show_error_context = true
show_error_codes = true
strict_equality = true
strict_optional = true
warn_unused_configs = true
warn_redundant_casts = true
warn_return_any = true
warn_unused_ignores = true

[tool.black]
line-length = 100
skip-string-normalization = true
target-version = ["py37"]

[tool.ruff]
target-version = "py37"
line-length = 100
select = [
"A", "B", "C", "E", "F", "FBT", "I", "N", "Q", "RUF", "S", "T",
"UP", "W", "YTT",
]
enable-extensions = "G"
extend-ignore = [
"G001", "G002", "G004", "G200", "G201", "G202",
# black adds spaces around ':'
"E203",
ignore = [
# Allow non-abstract empty methods in abstract base classes
"B027",
# Ignore McCabe complexity
"C901",
# Allow boolean positional values in function calls, like `dict.get(... True)`
"FBT003",
# Use of `assert` detected
"S101",
# Line too long
"E501",
# Relative imports are banned
"I252",
# Boolean ... in function definition
"FBT001", "FBT002",
# Module level import not at top of file
"E402",
# A001/A002/A003 .. is shadowing a python builtin
"A001", "A002", "A003",
# Possible hardcoded password
"S105", "S106",
# Q000 Single quotes found but double quotes preferred
"Q000",
# N806 Variable `B` in function should be lowercase
"N806",
# T201 `print` found
"T201",
# N802 Function name `CreateWellKnownSid` should be lowercase
"N802", "N803",
# C408 Unnecessary `dict` call (rewrite as a literal)
"C408",
# N801 Class name `directional_link` should use CapWords convention
"N801",
]
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
"tests/*: B011", "F841",
unfixable = [
# Don't touch print statements
"T201",
# Don't touch noqa lines
"RUF100",
]