Skip to content

Commit aabc3e5

Browse files
committed
Cleanup
1 parent 1c4f9a2 commit aabc3e5

File tree

9 files changed

+78
-43
lines changed

9 files changed

+78
-43
lines changed

.github/workflows/draft-changelog.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
target: ${{ github.event.inputs.target }}
4949
branch: ${{ github.event.inputs.branch }}
5050
since: ${{ github.event.inputs.since }}
51-
since_last_stable: ${{ github.event.intputs.since_last_stable }}
51+
since_last_stable: ${{ github.event.inputs.since_last_stable }}
5252
- name: "** Next Step **"
5353
run: |
5454
echo "Review PR: ${{ steps.draft-changelog.outputs.pr_url }}"

.github/workflows/draft-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
version_spec: ${{ github.event.inputs.version_spec }}
5757
post_version_spec: ${{ github.event.inputs.post_version_spec }}
5858
since: ${{ github.event.inputs.since }}
59-
since_last_stable: ${{ github.event.intputs.since_last_stable }}
59+
since_last_stable: ${{ github.event.inputs.since_last_stable }}
6060
- name: "** Next Step **"
6161
run: |
6262
echo "Run the "Publish Release" Workflow with Release Url:"

jupyter_releaser/actions/publish_release.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,10 @@
22
# Distributed under the terms of the Modified BSD License.
33
import os
44

5-
from jupyter_releaser.util import CHECKOUT_NAME
6-
from jupyter_releaser.util import get_repo
75
from jupyter_releaser.util import run
86

97
release_url = os.environ["release_url"]
108
run(f"jupyter-releaser extract-release {release_url}")
119
run(f"jupyter-releaser forwardport-changelog {release_url}")
12-
13-
# Extract the pypi token
14-
twine_pwd = os.environ.get("PYPI_TOKEN", "")
15-
pypi_token_map = os.environ.get("PYPI_TOKEN_MAP", "").replace(r"\n", "\n")
16-
if pypi_token_map:
17-
pwd = os.getcwd()
18-
os.chdir(CHECKOUT_NAME)
19-
repo_name = get_repo()
20-
for line in pypi_token_map.splitlines():
21-
name, _, token = line.partition(",")
22-
if name == repo_name:
23-
twine_pwd = token
24-
os.chdir(pwd)
25-
os.environ["TWINE_PASSWORD"] = twine_pwd
26-
27-
run("jupyter-releaser publish-assets")
10+
run(f"jupyter-releaser publish-assets {release_url}")
2811
run(f"jupyter-releaser publish-release {release_url}")

jupyter_releaser/cli.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,13 +580,28 @@ def extract_release(auth, dist_dir, dry_run, release_url, npm_install_options):
580580
default="https://pypi.org/simple/",
581581
)
582582
@add_options(dry_run_options)
583+
@click.argument("release-url", nargs=1, required=False)
583584
@use_checkout_dir()
584585
def publish_assets(
585-
dist_dir, npm_token, npm_cmd, twine_cmd, npm_registry, twine_registry, dry_run
586+
dist_dir,
587+
npm_token,
588+
npm_cmd,
589+
twine_cmd,
590+
npm_registry,
591+
twine_registry,
592+
dry_run,
593+
release_url,
586594
):
587595
"""Publish release asset(s)"""
588596
lib.publish_assets(
589-
dist_dir, npm_token, npm_cmd, twine_cmd, npm_registry, twine_registry, dry_run
597+
dist_dir,
598+
npm_token,
599+
npm_cmd,
600+
twine_cmd,
601+
npm_registry,
602+
twine_registry,
603+
dry_run,
604+
release_url,
590605
)
591606

592607

jupyter_releaser/lib.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,27 @@ def parse_release_url(release_url):
373373

374374

375375
def publish_assets(
376-
dist_dir, npm_token, npm_cmd, twine_cmd, npm_registry, twine_registry, dry_run
376+
dist_dir,
377+
npm_token,
378+
npm_cmd,
379+
twine_cmd,
380+
npm_registry,
381+
twine_registry,
382+
dry_run,
383+
release_url,
377384
):
378385
"""Publish release asset(s)"""
379386
os.environ["NPM_REGISTRY"] = npm_registry
380387
os.environ["TWINE_REGISTRY"] = twine_registry
388+
twine_token = ""
389+
390+
if len(glob(f"{dist_dir}/*.tgz")):
391+
npm.handle_npm_config(npm_token)
392+
if npm_token:
393+
util.run("npm whoami")
394+
395+
if len(glob(f"{dist_dir}/*.whl")):
396+
twine_token = python.get_pypi_token(release_url)
381397

382398
if dry_run:
383399
# Start local pypi server with no auth, allowing overwrites,
@@ -386,22 +402,21 @@ def publish_assets(
386402
python.start_local_pypi()
387403
twine_cmd = "twine upload --repository-url=http://0.0.0.0:8081"
388404
os.environ["TWINE_USERNAME"] = "foo"
389-
os.environ["TWINE_PASSWORD"] = "bar"
405+
twine_token = twine_token or "bar"
390406
npm_cmd = "npm publish --dry-run"
391407
else:
392408
os.environ.setdefault("TWINE_USERNAME", "__token__")
393409

394-
if len(glob(f"{dist_dir}/*.tgz")):
395-
npm.handle_npm_config(npm_token)
396-
if npm_token:
397-
util.run("npm whoami")
398-
399410
found = False
400411
for path in sorted(glob(f"{dist_dir}/*.*")):
401412
name = Path(path).name
402413
suffix = Path(path).suffix
403414
if suffix in [".gz", ".whl"]:
404-
util.retry(f"{twine_cmd} {name}", cwd=dist_dir)
415+
env = os.environ.copy()
416+
env["TWINE_PASSWORD"] = twine_token
417+
# NOTE: Do not print the env since a twine token extracted from
418+
# a PYPI_TOKEN_MAP will not be sanitized in output
419+
util.retry(f"{twine_cmd} {name}", cwd=dist_dir, env=env)
405420
found = True
406421
elif suffix == ".tgz":
407422
# Ignore already published versions

jupyter_releaser/npm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def handle_npm_config(npm_token):
135135

136136
text += f"\n{reg_entry}\n{auth_entry}"
137137
text = text.strip() + "\n"
138-
util.log(f"writing npm config to {npmrc}:\n{text}")
138+
util.log(f"writing npm config to {npmrc}")
139139
npmrc.write_text(text, encoding="utf-8")
140140

141141

jupyter_releaser/python.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ def check_dist(dist_file, test_cmd=""):
6060
util.run(f"{bin_path}/{test_cmd}")
6161

6262

63+
def get_pypi_token(release_url):
64+
"""Get the PyPI token
65+
66+
Note: Do not print the token in CI since it will not be sanitized
67+
if it comes from the PYPI_TOKEN_MAP"""
68+
twine_pwd = os.environ.get("PYPI_TOKEN", "")
69+
pypi_token_map = os.environ.get("PYPI_TOKEN_MAP", "").replace(r"\n", "\n")
70+
if pypi_token_map and release_url:
71+
parts = release_url.replace("https://github.com/", "").split("/")
72+
repo_name = f"{parts[0]}/{parts[1]}"
73+
util.log(f"Looking for PYPI token for {repo_name} in token map")
74+
for line in pypi_token_map.splitlines():
75+
name, _, token = line.partition(",")
76+
if name == repo_name:
77+
twine_pwd = token
78+
util.log("Found PYPI token")
79+
elif twine_pwd:
80+
util.log("Using PYPI token from PYPI_TOKEN")
81+
else:
82+
util.log("PYPI token not found")
83+
84+
return twine_pwd
85+
86+
6387
def start_local_pypi():
6488
"""Start a local PyPI server"""
6589
temp_dir = TemporaryDirectory()

jupyter_releaser/tests/test_cli.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -648,16 +648,19 @@ def test_publish_assets_py(py_package, runner, mocker, git_prep):
648648
orig_run = util.run
649649
called = 0
650650

651+
os.environ["PYPI_TOKEN_MAP"] = "snuffy/test,foo-token\nfizz/buzz,bar"
652+
651653
def wrapped(cmd, **kwargs):
652654
nonlocal called
653655
if cmd.startswith("twine upload"):
654-
called += 1
656+
if kwargs["env"]["TWINE_PASSWORD"] == "foo-token":
657+
called += 1
655658
return orig_run(cmd, **kwargs)
656659

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

659662
dist_dir = py_package / util.CHECKOUT_NAME / "dist"
660-
runner(["publish-assets", "--dist-dir", dist_dir, "--dry-run"])
663+
runner(["publish-assets", "--dist-dir", dist_dir, "--dry-run", HTML_URL])
661664
assert called == 2, called
662665

663666
log = get_log()
@@ -679,13 +682,7 @@ def wrapped(cmd, **kwargs):
679682
mock_run = mocker.patch("jupyter_releaser.util.run", wraps=wrapped)
680683

681684
runner(
682-
[
683-
"publish-assets",
684-
"--npm-cmd",
685-
"npm publish --dry-run",
686-
"--dist-dir",
687-
dist_dir,
688-
]
685+
["publish-assets", "--npm-cmd", "npm publish --dry-run", "--dist-dir", dist_dir]
689686
)
690687

691688
assert called == 3, called
@@ -715,6 +712,7 @@ def wrapped(cmd, **kwargs):
715712
"npm publish --dry-run",
716713
"--dist-dir",
717714
dist_dir,
715+
HTML_URL,
718716
]
719717
)
720718

@@ -745,6 +743,7 @@ def wrapped(cmd, **kwargs):
745743
"npm publish --dry-run",
746744
"--dist-dir",
747745
dist_dir,
746+
HTML_URL,
748747
]
749748
)
750749

setup.cfg

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ install_requires =
4040
requests
4141
requests_cache
4242
setuptools~=57.0
43-
tomlkit==0.7.0
44-
tbump==6.3.2
45-
toml==0.10.2
43+
tbump~=6.4
44+
toml~=0.10
4645
twine
4746

4847
[options.extras_require]

0 commit comments

Comments
 (0)