Skip to content
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
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 weekday
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
12 changes: 9 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ env:
PYTHONDONTWRITEBYTECODE: 1

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

check_links:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -145,7 +151,7 @@ jobs:
- check_links
- test
- docs
- pre_commit
- lint
- check_local_actions
- test_minimum_versions
- test_prereleases
Expand Down
73 changes: 13 additions & 60 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ci:
autoupdate_schedule: monthly

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand All @@ -15,24 +18,10 @@ 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
Expand All @@ -41,49 +30,13 @@ repos:
additional_dependencies:
[mdformat-gfm, mdformat-frontmatter, mdformat-footnote]

- repo: https://github.com/asottile/pyupgrade
rev: v3.3.0
hooks:
- id: pyupgrade
args: [--py38-plus]

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

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.991
hooks:
- id: mypy
args: ["--config-file", "pyproject.toml"]
additional_dependencies:
[
pytest,
click,
importlib_resources,
types-requests,
fastapi,
mdformat,
]
stages: [manual]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: check-github-workflows
name: "Check GitHub Workflows"
files: ^\.github/workflows/
types: [yaml]
- id: black

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.19.2
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.165
hooks:
- id: check-github-workflows
name: "Check Example Workflows"
files: ^example-workflows/
types: [yaml]
- id: ruff
args: ["--fix"]
24 changes: 12 additions & 12 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ def draft_changelog(
owner, repo_name = repo.split("/")
gh = util.get_gh_object(dry_run=dry_run, owner=owner, repo=repo_name, token=auth)

data = dict(
version_spec=version_spec,
ref=ref,
branch=branch,
repo=repo,
since=since,
since_last_stable=since_last_stable,
version=version,
post_version_spec=post_version_spec,
post_version_message=post_version_message,
expected_sha=current_sha,
)
data = {
"version_spec": version_spec,
"ref": ref,
"branch": branch,
"repo": repo,
"since": since,
"since_last_stable": since_last_stable,
"version": version,
"post_version_spec": post_version_spec,
"post_version_message": post_version_message,
"expected_sha": current_sha,
}
with tempfile.TemporaryDirectory() as d:
metadata_path = Path(d) / util.METADATA_JSON
with open(metadata_path, "w") as fid:
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 @@ -480,7 +480,7 @@ def test_delete_release(npm_dist, runner, mock_github, git_prep, draft_release):


@pytest.mark.skipif(
os.name == "nt" and sys.version_info.major == 3 and sys.version_info.minor < 8,
os.name == "nt" and sys.version_info < (3, 8),
reason="See https://bugs.python.org/issue26660",
)
def test_extract_dist_py(py_package, runner, mocker, mock_github, tmp_path, git_prep):
Expand All @@ -506,7 +506,7 @@ def test_extract_dist_py(py_package, runner, mocker, mock_github, tmp_path, git_


@pytest.mark.skipif(
os.name == "nt" and sys.version_info.major == 3 and sys.version_info.minor < 8,
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):
Expand Down Expand Up @@ -540,7 +540,7 @@ def test_extract_dist_multipy(py_multipackage, runner, mocker, mock_github, tmp_


@pytest.mark.skipif(
os.name == "nt" and sys.version_info.major == 3 and sys.version_info.minor < 8,
os.name == "nt" and sys.version_info < (3, 8),
reason="See https://bugs.python.org/issue26660",
)
def test_extract_dist_npm(npm_dist, runner, mocker, mock_github, tmp_path):
Expand Down
2 changes: 1 addition & 1 deletion jupyter_releaser/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_get_empty_changelog(py_package, mocker):
auth=None,
)

assert not ("...None" in resp)
assert "...None" not in resp


def test_splice_github_entry(py_package, mocker):
Expand Down
8 changes: 5 additions & 3 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def fetch_release_asset(target_dir, asset, auth):
"""Fetch a release asset into a target directory."""
log(f"Fetching {asset.name}...")
url = asset.url
headers = dict(Authorization=f"token {auth}", Accept="application/octet-stream")
headers = {"Authorization": f"token {auth}", "Accept": "application/octet-stream"}
path = Path(target_dir) / asset.name
with requests.get(url, headers=headers, stream=True) as r:
r.raise_for_status()
Expand All @@ -494,7 +494,7 @@ def fetch_release_asset_data(asset, auth):
"""Fetch the data for a release asset."""
log(f"Fetching data for {asset.name}...")
url = asset.url
headers = dict(Authorization=f"token {auth}", Accept="application/octet-stream")
headers = {"Authorization": f"token {auth}", "Accept": "application/octet-stream"}

sink = BytesIO()
with requests.get(url, headers=headers, stream=True) as r:
Expand Down Expand Up @@ -602,7 +602,9 @@ def prepare_environment(fetch_draft_release=True):
log("User was admin!")
except Exception as e:
log(str(e))
raise RuntimeError("Could not get user permission level, assuming user was not admin!")
raise RuntimeError(
"Could not get user permission level, assuming user was not admin!"
) from None

# Get the latest draft release if none is given.
release_url = os.environ.get("RH_RELEASE_URL")
Expand Down
114 changes: 89 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,22 @@ docs = [
"sphinx-click",
]
test = [
"coverage",
"fastapi",
"pre-commit",
"pytest>=7.0",
"pytest-cov",
"pytest-mock",
"pytest-xdist[psutil]",
"uvicorn"
"coverage",
"fastapi",
"pre-commit",
"pytest>=7.0",
"pytest-cov",
"pytest-mock",
"pytest-xdist[psutil]",
"uvicorn"
]
lint = [
"black>=22.6.0",
"mdformat>0.7",
"mdformat-gfm>=0.3.5",
"ruff>=0.0.156"
]
typing = ["mypy>=0.990"]

[project.scripts]
jupyter-releaser = "jupyter_releaser.cli:main"
Expand All @@ -88,6 +95,25 @@ dependencies = ["coverage", "pytest-cov"]
test = "python -m pytest -vv --cov jupyter_releaser --cov-branch --cov-report term-missing:skip-covered {args}"
nowarn = "test -W default {args}"

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

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

[tool.jupyter-releaser.hooks]
after-populate-release = "bash ./.github/scripts/bump_tag.sh"

Expand Down Expand Up @@ -148,23 +174,61 @@ module = [
]
ignore_missing_imports = true

[tool.flake8]
ignore = "E501, W503, E402"
builtins = "c, get_config"
exclude = [
".cache",
".github",
"docs",
"setup.py",
[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"
]
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
"jupyter_releaser/tests/*: B011", "F841",
unfixable = [
# Don't touch print statements
"T201",
# Don't touch noqa lines
"RUF100",
]

[tool.ruff.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
# E402 Module level import not at top of file
# T201 `print` found
# B007 Loop control variable `i` not used within the loop body.
# N802 Function name `assertIn` should be lowercase
"jupyter_releaser/tests/*" = ["B011", "F841", "C408", "E402", "T201", "B007", "N802"]