Skip to content

Commit 6919890

Browse files
authored
Use pipx for cli scripts and hatch for hatch version (#389)
1 parent 71a8bd6 commit 6919890

File tree

8 files changed

+27
-31
lines changed

8 files changed

+27
-31
lines changed

jupyter_releaser/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def main(force):
283283
click.option(
284284
"--pydist-check-cmd",
285285
envvar="RH_PYDIST_CHECK_CMD",
286-
default="twine check --strict",
286+
default="pipx run twine check --strict",
287287
help="The command to use to check a python distribution file",
288288
),
289289
click.option(
@@ -666,7 +666,7 @@ def extract_release(
666666
"--twine-cmd",
667667
help="The twine to run for Python release",
668668
envvar="TWINE_COMMAND",
669-
default="twine upload",
669+
default="pipx run twine upload",
670670
)
671671
@click.option(
672672
"--npm-registry",

jupyter_releaser/lib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def publish_assets(
488488
# in a temporary directory
489489
if len(glob(f"{dist_dir}/*.whl")):
490490
python.start_local_pypi()
491-
twine_cmd = "twine upload --repository-url=http://0.0.0.0:8081"
491+
twine_cmd = "pipx run twine upload --repository-url=http://0.0.0.0:8081"
492492
os.environ["TWINE_USERNAME"] = "foo"
493493
twine_token = twine_token or "bar"
494494
npm_cmd = "npm publish --dry-run"

jupyter_releaser/python.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def build_dist(dist_dir, clean=True):
2626
os.remove(pkg)
2727

2828
if PYPROJECT.exists():
29-
util.run(f"python -m build --outdir {dest} .", quiet=True, show_cwd=True)
29+
util.run(f"pipx run build --outdir {dest} .", quiet=True, show_cwd=True)
3030
elif SETUP_PY.exists():
3131
util.run(f"python setup.py sdist --dist-dir {dest}", quiet=True)
3232
util.run(f"python setup.py bdist_wheel --dist-dir {dest}", quiet=True)
@@ -36,7 +36,7 @@ def check_dist(
3636
dist_file,
3737
test_cmd="",
3838
python_imports=None,
39-
check_cmd="twine check --strict",
39+
check_cmd="pipx twine check --strict",
4040
resource_paths=None,
4141
):
4242
"""Check a Python package locally (not as a cli)"""

jupyter_releaser/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def py_dist(py_package, runner, mocker, build_mock, git_prep):
128128
changelog_entry = testutil.mock_changelog_entry(py_package, runner, mocker)
129129

130130
# Create the dist files
131-
util.run("python -m build .", cwd=util.CHECKOUT_NAME, quiet=True)
131+
util.run("pipx run build .", cwd=util.CHECKOUT_NAME, quiet=True)
132132

133133
# Finalize the release
134134
runner(["tag-release"])
@@ -177,7 +177,7 @@ def build_mock(mocker):
177177
orig_run = util.run
178178

179179
def wrapped(cmd, **kwargs):
180-
if cmd == "python -m build .":
180+
if cmd == "pipx run build .":
181181
if osp.exists(util.CHECKOUT_NAME):
182182
dist_dir = Path(f"{util.CHECKOUT_NAME}/dist")
183183
else:

jupyter_releaser/tests/test_cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ def test_tag_release(py_package, runner, build_mock, git_prep):
487487
# Bump the version
488488
runner(["bump-version", "--version-spec", VERSION_SPEC])
489489
# Create the dist files
490-
util.run("python -m build .", cwd=util.CHECKOUT_NAME)
490+
util.run("pipx run build .", cwd=util.CHECKOUT_NAME)
491491
# Tag the release
492492
runner(
493493
[
@@ -554,7 +554,7 @@ def test_extract_dist_py(py_package, runner, mocker, mock_github, tmp_path, git_
554554
changelog_entry = mock_changelog_entry(py_package, runner, mocker)
555555

556556
# Create the dist files
557-
run("python -m build .", cwd=util.CHECKOUT_NAME)
557+
run("pipx run build .", cwd=util.CHECKOUT_NAME)
558558

559559
# Finalize the release
560560
runner(["tag-release"])
@@ -588,7 +588,7 @@ def test_extract_dist_multipy(py_multipackage, runner, mocker, mock_github, tmp_
588588
dist_dir = normalize_path(Path(util.CHECKOUT_NAME).resolve() / "dist")
589589
for package in py_multipackage:
590590
run(
591-
f"python -m build . -o {dist_dir}",
591+
f"pipx run build . -o {dist_dir}",
592592
cwd=Path(util.CHECKOUT_NAME) / package["rel_path"],
593593
)
594594
files.extend(glob(dist_dir + "/*.*"))
@@ -638,7 +638,7 @@ def test_extract_dist_npm(npm_dist, runner, mocker, mock_github, tmp_path):
638638
def test_publish_assets_py(py_package, runner, mocker, git_prep, mock_github):
639639
# Create the dist files
640640
changelog_entry = mock_changelog_entry(py_package, runner, mocker)
641-
run("python -m build .", cwd=util.CHECKOUT_NAME)
641+
run("pipx run build .", cwd=util.CHECKOUT_NAME)
642642

643643
orig_run = util.run
644644
called = 0
@@ -647,7 +647,7 @@ def test_publish_assets_py(py_package, runner, mocker, git_prep, mock_github):
647647

648648
def wrapped(cmd, **kwargs):
649649
nonlocal called
650-
if cmd.startswith("twine upload"):
650+
if "twine upload" in cmd:
651651
if kwargs["env"]["TWINE_PASSWORD"] == "foo-token":
652652
called += 1
653653
return orig_run(cmd, **kwargs)
@@ -763,7 +763,7 @@ def test_config_file(py_package, runner, mocker, git_prep):
763763

764764
def wrapped(cmd, **kwargs):
765765
nonlocal called
766-
if cmd.startswith("python -m build --outdir foo"):
766+
if cmd.startswith("pipx run build --outdir foo"):
767767
called = True
768768
return ""
769769
return orig_run(cmd, **kwargs)
@@ -785,7 +785,7 @@ def test_config_file_env_override(py_package, runner, mocker, git_prep):
785785

786786
def wrapped(cmd, **kwargs):
787787
nonlocal called
788-
if cmd.startswith("python -m build --outdir bar"):
788+
if cmd.startswith("pipx run build --outdir bar"):
789789
called = True
790790
return ""
791791
return orig_run(cmd, **kwargs)
@@ -807,7 +807,7 @@ def test_config_file_cli_override(py_package, runner, mocker, git_prep):
807807

808808
def wrapped(cmd, **kwargs):
809809
nonlocal called
810-
if cmd.startswith("python -m build --outdir bar"):
810+
if cmd.startswith("pipx run build --outdir bar"):
811811
called = True
812812
return ""
813813
return orig_run(cmd, **kwargs)

jupyter_releaser/tests/test_functions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def test_compute_sha256(py_package):
237237
def test_create_release_commit(py_package, build_mock):
238238
util.bump_version("0.0.2a0")
239239
version = util.get_version()
240-
util.run("python -m build .")
240+
util.run("pipx run build .")
241241
shas = util.create_release_commit(version)
242242
assert util.normalize_path("dist/foo-0.0.2a0.tar.gz") in shas
243243
assert util.normalize_path("dist/foo-0.0.2a0-py3-none-any.whl") in shas
@@ -257,7 +257,7 @@ def test_create_release_commit_hybrid(py_package, build_mock):
257257
txt += testutil.TBUMP_NPM_TEMPLATE
258258
(py_package / "tbump.toml").write_text(txt, encoding="utf-8")
259259

260-
util.run("python -m build .")
260+
util.run("pipx run build .")
261261
shas = util.create_release_commit(version)
262262
assert len(shas) == 2
263263
assert util.normalize_path("dist/foo-0.0.2a0.tar.gz") in shas

jupyter_releaser/util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
METADATA_JSON = Path("metadata.json")
4343

4444
BUF_SIZE = 65536
45-
TBUMP_CMD = "tbump --non-interactive --only-patch"
45+
TBUMP_CMD = "pipx run tbump --non-interactive --only-patch"
4646

4747
CHECKOUT_NAME = ".jupyter_releaser_checkout"
4848

@@ -166,10 +166,10 @@ def get_version():
166166
if version:
167167
return version
168168

169-
# If this is a hatchling project, use hatchling to get
169+
# If this is a hatchling project, use hatch to get
170170
# the dynamic version.
171171
if data.get("build-system", {}).get("build-backend") == "hatchling.build":
172-
return run("hatchling version").split("\n")[-1]
172+
return run("pipx run hatch version").split("\n")[-1]
173173

174174
if SETUP_PY.exists():
175175
warnings.warn("Using deprecated setup.py invocation")
@@ -181,7 +181,7 @@ def get_version():
181181
# Build the wheel and extract the version.
182182
if PYPROJECT.exists():
183183
with tempfile.TemporaryDirectory() as tempdir:
184-
run(f"{sys.executable} -m build --wheel --outdir {tempdir}")
184+
run(f"pipx run build --wheel --outdir {tempdir}")
185185
wheel_path = glob(f"{tempdir}/*.whl")[0]
186186
wheel = Wheel(wheel_path)
187187
version = wheel.version
@@ -252,7 +252,7 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
252252
if "tool.tbump" in pyproject_text:
253253
version_cmd = version_cmd or TBUMP_CMD
254254
elif "hatchling.build" in pyproject_text:
255-
version_cmd = version_cmd or "hatchling version"
255+
version_cmd = version_cmd or "pipx run hatch version"
256256

257257
if SETUP_CFG.exists():
258258
if "bumpversion" in SETUP_CFG.read_text(encoding="utf-8"):
@@ -266,13 +266,13 @@ def bump_version(version_spec, *, changelog_path="", version_cmd=""):
266266

267267
# Assign default values if no version spec was given
268268
if not version_spec:
269-
if "tbump" in version_cmd or "hatchling" in version_cmd:
269+
if "tbump" in version_cmd or "hatch" in version_cmd:
270270
version_spec = "next"
271271
else:
272272
version_spec = "patch"
273273

274274
# Add some convenience options on top of "tbump" and "hatch"
275-
if "tbump" in version_cmd or "hatchling" in version_cmd:
275+
if "tbump" in version_cmd or "hatch" in version_cmd:
276276
v = parse_version(get_version())
277277
assert isinstance(v, Version)
278278

pyproject.toml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,19 @@ urls = {Homepage = "https://jupyter.org"}
2222
requires-python = ">=3.8"
2323
dynamic = ["version"]
2424
dependencies = [
25-
"build",
26-
"check-manifest",
2725
"click",
2826
"ghapi",
2927
"github-activity~=0.2",
30-
"hatchling>=1.0",
3128
"importlib_resources",
3229
"jsonschema>=3.0.1",
3330
"packaging",
3431
"pkginfo",
35-
"pre-commit",
36-
"pypiserver",
3732
"pytest-check-links>=0.7",
33+
"pypiserver",
34+
"pipx",
3835
"requests",
3936
"requests_cache",
40-
"tbump~=6.7",
4137
"toml~=0.10",
42-
"twine",
4338
]
4439

4540
[project.readme]
@@ -50,6 +45,7 @@ content-type = "text/markdown"
5045
test = [
5146
"coverage",
5247
"fastapi",
48+
"pre-commit",
5349
"pytest>=7.0",
5450
"pytest-cov",
5551
"pytest-mock",

0 commit comments

Comments
 (0)