Skip to content

Commit b6dfae3

Browse files
author
Steven Silvester
authored
Merge pull request #102 from afshin/clean-up
General code base clean up
2 parents c6d7914 + 2b84e47 commit b6dfae3

File tree

8 files changed

+86
-23
lines changed

8 files changed

+86
-23
lines changed

.github/actions/check-release/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ runs:
3535
# Install Jupyter Releaser from git unless we are testing Releaser itself
3636
if ! command -v jupyter-releaser &> /dev/null
3737
then
38-
pip install -q git+https://github.com/jupyter-server/jupyter_releaser.git
38+
pip install -q git+https://github.com/jupyter-server/jupyter_releaser.git@v1
3939
fi
4040
4141
export RH_IS_CHECK_RELEASE=true

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ repos:
2222
- id: check-case-conflict
2323
- id: check-executables-have-shebangs
2424
- id: requirements-txt-fixer
25+
- repo: https://github.com/pre-commit/mirrors-pylint
26+
rev: v3.0.0a3
27+
hooks:
28+
- id: pylint
29+
args: [--disable=all, --enable=unused-import]

jupyter_releaser/changelog.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,9 @@ def get_version_entry(
6767
"""
6868
since = since or util.get_latest_tag(branch)
6969

70-
branch = branch.split("/")[-1]
7170
util.log(f"Getting changes to {repo} since {since} on branch {branch}...")
7271

73-
until = util.run(f'git --no-pager log -n 1 origin/{branch} --pretty=format:"%H"')
72+
until = util.run(f'git --no-pager log -n 1 {branch} --pretty=format:"%H"')
7473
until = until.replace("%", "")
7574

7675
md = generate_activity_md(

jupyter_releaser/lib.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from glob import glob
1010
from pathlib import Path
1111
from subprocess import CalledProcessError
12-
from tempfile import TemporaryDirectory
1312

1413
import requests
1514
from ghapi.core import GhApi
@@ -278,6 +277,9 @@ def extract_release(auth, dist_dir, dry_run, release_url, npm_install_options):
278277
# Prepare a git checkout
279278
prep_git(None, branch, f"{owner}/{repo}", auth, None, None)
280279

280+
orig_dir = os.getcwd()
281+
os.chdir(util.CHECKOUT_NAME)
282+
281283
# Clean the dist folder
282284
dist = Path(dist_dir)
283285
if dist.exists():
@@ -318,8 +320,7 @@ def extract_release(auth, dist_dir, dry_run, release_url, npm_install_options):
318320

319321
# Get the commmit message for the tag
320322
commit_message = ""
321-
checkout = osp.join(os.getcwd(), util.CHECKOUT_NAME)
322-
commit_message = util.run(f"git log --format=%B -n 1 {sha}", cwd=checkout)
323+
commit_message = util.run(f"git log --format=%B -n 1 {sha}")
323324

324325
for asset in assets:
325326
# Check the sha against the published sha
@@ -337,6 +338,8 @@ def extract_release(auth, dist_dir, dry_run, release_url, npm_install_options):
337338
if not valid: # pragma: no cover
338339
raise ValueError(f"Invalid file {asset.name}")
339340

341+
os.chdir(orig_dir)
342+
340343

341344
def parse_release_url(release_url):
342345
"""Parse a release url into a regex match"""
@@ -354,7 +357,7 @@ def publish_assets(dist_dir, npm_token, npm_cmd, twine_cmd, dry_run):
354357
# in a temporary directory
355358
if len(glob(f"{dist_dir}/*.whl")):
356359
python.start_local_pypi()
357-
twine_cmd = "twine upload --repository-url=http://localhost:8081"
360+
twine_cmd = "twine upload --repository-url=http://0.0.0.0:8081"
358361
os.environ["TWINE_USERNAME"] = "foo"
359362
os.environ["TWINE_PASSWORD"] = "bar"
360363
npm_cmd = "npm publish --dry-run"
@@ -488,6 +491,12 @@ def prep_git(ref, branch, repo, auth, username, url):
488491
else:
489492
util.run(checkout_cmd)
490493

494+
# Check for detached head state, create branch if needed
495+
try:
496+
util.run("git symbolic-ref -q HEAD")
497+
except Exception:
498+
util.run(f"git switch -c {branch}")
499+
491500
# Install the package
492501
# install python package in editable mode with test deps
493502
if util.SETUP_PY.exists():

jupyter_releaser/tests/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
import json
44
import os
55
import os.path as osp
6-
import traceback
76
from pathlib import Path
87
from urllib.request import OpenerDirector
98

109
from click.testing import CliRunner
1110
from pytest import fixture
1211

13-
from jupyter_releaser import changelog
1412
from jupyter_releaser import cli
1513
from jupyter_releaser import util
1614
from jupyter_releaser.tests import util as testutil

jupyter_releaser/tests/test_cli.py

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,19 @@
99
from pathlib import Path
1010
from subprocess import CalledProcessError
1111
from unittest.mock import call
12-
from unittest.mock import MagicMock
13-
from unittest.mock import patch
14-
from unittest.mock import PropertyMock
1512

1613
import pytest
17-
from pytest import fixture
1814

1915
from jupyter_releaser import changelog
20-
from jupyter_releaser import cli
21-
from jupyter_releaser import npm
22-
from jupyter_releaser import python
2316
from jupyter_releaser import util
2417
from jupyter_releaser.tests.util import CHANGELOG_ENTRY
25-
from jupyter_releaser.tests.util import create_npm_package
26-
from jupyter_releaser.tests.util import create_python_package
2718
from jupyter_releaser.tests.util import get_log
2819
from jupyter_releaser.tests.util import HTML_URL
2920
from jupyter_releaser.tests.util import mock_changelog_entry
3021
from jupyter_releaser.tests.util import MockHTTPResponse
3122
from jupyter_releaser.tests.util import MockRequestResponse
3223
from jupyter_releaser.tests.util import PR_ENTRY
3324
from jupyter_releaser.tests.util import REPO_DATA
34-
from jupyter_releaser.tests.util import TOML_CONFIG
3525
from jupyter_releaser.tests.util import VERSION_SPEC
3626
from jupyter_releaser.util import bump_version
3727
from jupyter_releaser.util import normalize_path
@@ -58,6 +48,38 @@ def test_prep_git_pr(py_package, runner):
5848
assert util.get_branch() == "foo", util.get_branch()
5949

6050

51+
def test_prep_git_tag(py_package, runner):
52+
tag = "v0.1"
53+
util.run(f"git tag {tag}")
54+
result = runner(
55+
["prep-git", "--git-url", py_package],
56+
env=dict(GITHUB_ACTIONS="", RH_REF=f"refs/tags/{tag}", RH_BRANCH=tag),
57+
)
58+
59+
log = get_log()
60+
assert "before-prep-git" not in log
61+
assert "after-prep-git" in log
62+
63+
os.chdir(util.CHECKOUT_NAME)
64+
assert util.get_branch() == tag, util.get_branch()
65+
66+
67+
def test_prep_git_slashes(py_package, runner):
68+
branch = "a/b/c"
69+
util.run(f"git checkout -b {branch} foo")
70+
result = runner(
71+
["prep-git", "--git-url", py_package],
72+
env=dict(GITHUB_ACTIONS="", RH_REF=f"refs/heads/{branch}", RH_BRANCH=branch),
73+
)
74+
75+
log = get_log()
76+
assert "before-prep-git" not in log
77+
assert "after-prep-git" in log
78+
79+
os.chdir(util.CHECKOUT_NAME)
80+
assert util.get_branch() == branch, util.get_branch()
81+
82+
6183
def test_prep_git_full(py_package, tmp_path, mocker, runner):
6284
"""Full GitHub Actions simulation (Push)"""
6385

@@ -239,6 +261,37 @@ def test_build_changelog_backport(py_package, mocker, runner, open_mock):
239261
run("pre-commit run -a")
240262

241263

264+
def test_build_changelog_slashes(py_package, mocker, runner, open_mock):
265+
branch = "a/b/c"
266+
util.run(f"git checkout -b {branch} foo")
267+
env = dict(RH_REF=f"refs/heads/{branch}", RH_BRANCH=branch)
268+
run("pre-commit run -a")
269+
270+
changelog_path = "CHANGELOG.md"
271+
272+
runner(["prep-git", "--git-url", py_package], env=env)
273+
runner(["bump-version", "--version-spec", VERSION_SPEC], env=env)
274+
275+
mocked_gen = mocker.patch("jupyter_releaser.changelog.generate_activity_md")
276+
mocked_gen.return_value = CHANGELOG_ENTRY
277+
runner(["build-changelog", "--changelog-path", changelog_path], env=env)
278+
279+
log = get_log()
280+
assert "before-build-changelog" in log
281+
assert "after-build-changelog" in log
282+
283+
changelog_path = Path(util.CHECKOUT_NAME) / "CHANGELOG.md"
284+
text = changelog_path.read_text(encoding="utf-8")
285+
assert changelog.START_MARKER in text
286+
assert changelog.END_MARKER in text
287+
assert PR_ENTRY in text
288+
289+
assert len(re.findall(changelog.START_MARKER, text)) == 1
290+
assert len(re.findall(changelog.END_MARKER, text)) == 1
291+
292+
run("pre-commit run -a")
293+
294+
242295
def test_draft_changelog_full(py_package, mocker, runner, open_mock, git_prep):
243296
mock_changelog_entry(py_package, runner, mocker)
244297
runner(["draft-changelog", "--version-spec", VERSION_SPEC])
@@ -476,7 +529,7 @@ def test_extract_dist_py(py_package, runner, mocker, open_mock, tmp_path, git_pr
476529
shutil.move(f"{util.CHECKOUT_NAME}/dist", "staging")
477530

478531
def helper(path, **kwargs):
479-
return MockRequestResponse(f"staging/dist/{path}")
532+
return MockRequestResponse(f"{py_package}/staging/dist/{path}")
480533

481534
get_mock = mocker.patch("requests.get", side_effect=helper)
482535

@@ -519,7 +572,7 @@ def test_extract_dist_npm(npm_dist, runner, mocker, open_mock, tmp_path):
519572
shutil.move(f"{util.CHECKOUT_NAME}/dist", "staging")
520573

521574
def helper(path, **kwargs):
522-
return MockRequestResponse(f"staging/dist/{path}")
575+
return MockRequestResponse(f"{npm_dist}/staging/dist/{path}")
523576

524577
get_mock = mocker.patch("requests.get", side_effect=helper)
525578

jupyter_releaser/tests/test_functions.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (c) Jupyter Development Team.
22
# Distributed under the terms of the Modified BSD License.
33
import json
4-
import os
54
import shutil
65
from pathlib import Path
76

jupyter_releaser/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_branch():
106106
elif os.environ.get("GITHUB_REF"):
107107
# GitHub Action Push Event
108108
# e.g. refs/heads/feature-branch-1
109-
branch = os.environ["GITHUB_REF"].split("/")[-1]
109+
branch = "/".join(os.environ["GITHUB_REF"].split("/")[2:])
110110
else:
111111
branch = run("git branch --show-current")
112112
return branch

0 commit comments

Comments
 (0)