Skip to content

Commit

Permalink
Emit a warning when uploading is skipped (#558)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
mahendrapaipuri authored Feb 28, 2024
1 parent 81555cf commit f26f919
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jupyter_releaser/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,12 @@ def publish_assets(
# a PYPI_TOKEN_MAP will not be sanitized in output
util.retry(f"{twine_cmd} {name}", cwd=dist_dir, env=env, echo=True)
found = True
else:
warnings.warn(
f"Python package name {pkg.name} does not match with name in "
f"jupyter releaser config: {python_package_name}. Skipping uploading dist file {path}",
stacklevel=2,
)
elif suffix == ".tgz":
# Ignore already published versions
try:
Expand Down
30 changes: 30 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,36 @@ def wrapped(cmd, **kwargs):
assert "after-publish-assets" in log


@pytest.mark.skipif(os.name == "nt", reason="pypiserver does not start properly on Windows")
def test_publish_assets_py_skip(py_package, runner, mocker, git_prep, mock_github):
# Create the dist files
changelog_entry = mock_changelog_entry(py_package, runner, mocker)
run("pipx run build .", cwd=util.CHECKOUT_NAME)

orig_run = util.run
called = 0

# Set a different package name in config
os.environ["RH_PYTHON_PACKAGES"] = "foo_path:foo1"

def wrapped(cmd, **kwargs):
nonlocal called
if "twine upload" in cmd:
called += 1
return orig_run(cmd, **kwargs)

mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped)

dist_dir = py_package / util.CHECKOUT_NAME / "dist"
release = create_draft_release(files=glob(f"{dist_dir}/*.*"))
os.environ["RH_RELEASE_URL"] = release.html_url
# Expect a user warning
with pytest.warns(UserWarning):
runner(["publish-assets", "--dist-dir", dist_dir, "--dry-run"])
# Upload should be skipped and command shouldn't be called at all
assert called == 0


def test_publish_assets_npm(npm_dist, runner, mocker, mock_github):
# Create the release.
dist_dir = npm_dist / util.CHECKOUT_NAME / "dist"
Expand Down

0 comments on commit f26f919

Please sign in to comment.