@@ -373,11 +373,27 @@ def parse_release_url(release_url):
373
373
374
374
375
375
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 ,
377
384
):
378
385
"""Publish release asset(s)"""
379
386
os .environ ["NPM_REGISTRY" ] = npm_registry
380
387
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 )
381
397
382
398
if dry_run :
383
399
# Start local pypi server with no auth, allowing overwrites,
@@ -386,22 +402,21 @@ def publish_assets(
386
402
python .start_local_pypi ()
387
403
twine_cmd = "twine upload --repository-url=http://0.0.0.0:8081"
388
404
os .environ ["TWINE_USERNAME" ] = "foo"
389
- os . environ [ "TWINE_PASSWORD" ] = "bar"
405
+ twine_token = twine_token or "bar"
390
406
npm_cmd = "npm publish --dry-run"
391
407
else :
392
408
os .environ .setdefault ("TWINE_USERNAME" , "__token__" )
393
409
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
-
399
410
found = False
400
411
for path in sorted (glob (f"{ dist_dir } /*.*" )):
401
412
name = Path (path ).name
402
413
suffix = Path (path ).suffix
403
414
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 )
405
420
found = True
406
421
elif suffix == ".tgz" :
407
422
# Ignore already published versions
0 commit comments