Skip to content

Commit f26f919

Browse files
Emit a warning when uploading is skipped (#558)
* When py packages names are inconsistent between jupyter releaser config and wheel, uploading assets to PyPI will be silently skipped * We emit a warning now when this happens * A unit test has been added to test the warning Signed-off-by: Mahendra Paipuri <[email protected]>
1 parent 81555cf commit f26f919

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

jupyter_releaser/lib.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,12 @@ def publish_assets(
434434
# a PYPI_TOKEN_MAP will not be sanitized in output
435435
util.retry(f"{twine_cmd} {name}", cwd=dist_dir, env=env, echo=True)
436436
found = True
437+
else:
438+
warnings.warn(
439+
f"Python package name {pkg.name} does not match with name in "
440+
f"jupyter releaser config: {python_package_name}. Skipping uploading dist file {path}",
441+
stacklevel=2,
442+
)
437443
elif suffix == ".tgz":
438444
# Ignore already published versions
439445
try:

tests/test_cli.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,36 @@ def wrapped(cmd, **kwargs):
605605
assert "after-publish-assets" in log
606606

607607

608+
@pytest.mark.skipif(os.name == "nt", reason="pypiserver does not start properly on Windows")
609+
def test_publish_assets_py_skip(py_package, runner, mocker, git_prep, mock_github):
610+
# Create the dist files
611+
changelog_entry = mock_changelog_entry(py_package, runner, mocker)
612+
run("pipx run build .", cwd=util.CHECKOUT_NAME)
613+
614+
orig_run = util.run
615+
called = 0
616+
617+
# Set a different package name in config
618+
os.environ["RH_PYTHON_PACKAGES"] = "foo_path:foo1"
619+
620+
def wrapped(cmd, **kwargs):
621+
nonlocal called
622+
if "twine upload" in cmd:
623+
called += 1
624+
return orig_run(cmd, **kwargs)
625+
626+
mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped)
627+
628+
dist_dir = py_package / util.CHECKOUT_NAME / "dist"
629+
release = create_draft_release(files=glob(f"{dist_dir}/*.*"))
630+
os.environ["RH_RELEASE_URL"] = release.html_url
631+
# Expect a user warning
632+
with pytest.warns(UserWarning):
633+
runner(["publish-assets", "--dist-dir", dist_dir, "--dry-run"])
634+
# Upload should be skipped and command shouldn't be called at all
635+
assert called == 0
636+
637+
608638
def test_publish_assets_npm(npm_dist, runner, mocker, mock_github):
609639
# Create the release.
610640
dist_dir = npm_dist / util.CHECKOUT_NAME / "dist"

0 commit comments

Comments
 (0)