1
1
# Copyright (c) Jupyter Development Team.
2
2
# Distributed under the terms of the Modified BSD License.
3
+ import atexit
3
4
import os
4
5
import os .path as osp
5
6
import re
7
+ import shlex
6
8
import shutil
7
9
import sys
8
10
import uuid
9
11
from datetime import datetime
10
12
from glob import glob
11
13
from pathlib import Path
14
+ from subprocess import PIPE
15
+ from subprocess import Popen
12
16
from tempfile import TemporaryDirectory
13
17
14
18
import requests
@@ -348,6 +352,25 @@ def publish_release(
348
352
"""Publish release asset(s) and finalize GitHub release"""
349
353
util .log (f"Publishing { release_url } in with dry run: { dry_run } " )
350
354
355
+ if dry_run :
356
+ # Start local pypi server with no auth, allowing overwrites,
357
+ # in a temporary directory
358
+ temp_dir = TemporaryDirectory ()
359
+ cmd = f"pypi-server -p 8081 -P . -a . -o -v { temp_dir .name } "
360
+ proc = Popen (shlex .split (cmd ), stderr = PIPE )
361
+ # Wait for the server to start
362
+ while True :
363
+ line = proc .stderr .readline ().decode ("utf-8" ).strip ()
364
+ util .log (line )
365
+ if "Listening on" in line :
366
+ break
367
+ atexit .register (proc .kill )
368
+ atexit .register (temp_dir .cleanup )
369
+ twine_cmd = "twine upload --repository-url=http://localhost:8081"
370
+ os .environ ["TWINE_USERNAME" ] = "foo"
371
+ os .environ ["TWINE_PASSWORD" ] = "bar"
372
+ npm_cmd = "npm publish --dry-run"
373
+
351
374
match = parse_release_url (release_url )
352
375
353
376
if npm_token :
@@ -387,7 +410,7 @@ def publish_release(
387
410
util .actions_output ("release_url" , release .html_url )
388
411
389
412
390
- def prep_git (branch , repo , auth , username , url ):
413
+ def prep_git (branch , repo , auth , username , url , install = True ):
391
414
"""Set up git"""
392
415
repo = repo or util .get_repo ()
393
416
@@ -409,7 +432,7 @@ def prep_git(branch, repo, auth, username, url):
409
432
checkout_dir = os .environ .get ("RH_CHECKOUT_DIR" , util .CHECKOUT_NAME )
410
433
checkout_exists = False
411
434
if osp .exists (osp .join (checkout_dir , ".git" )):
412
- print ("Git checkout already exists" , file = sys . stderr )
435
+ util . log ("Git checkout already exists" )
413
436
checkout_exists = True
414
437
415
438
if not checkout_exists :
@@ -440,7 +463,7 @@ def prep_git(branch, repo, auth, username, url):
440
463
util .run (f"git checkout { branch } " )
441
464
442
465
# Install the package with test deps
443
- if util .SETUP_PY .exists ():
466
+ if util .SETUP_PY .exists () and install :
444
467
util .run ('pip install ".[test]"' )
445
468
446
469
os .chdir (orig_dir )
@@ -459,8 +482,10 @@ def forwardport_changelog(
459
482
tag = release .tag_name
460
483
461
484
repo = f'{ match ["owner" ]} /{ match ["repo" ]} '
485
+
462
486
# We want to target the main branch
463
- branch = prep_git (None , repo , auth , username , git_url )
487
+ orig_dir = os .getcwd ()
488
+ branch = prep_git (None , repo , auth , username , git_url , install = False )
464
489
os .chdir (util .CHECKOUT_NAME )
465
490
466
491
# Bail if the tag has been merged to the branch
@@ -520,3 +545,7 @@ def forwardport_changelog(
520
545
pr = make_changelog_pr (
521
546
auth , branch , repo , title , commit_message , body , dry_run = dry_run
522
547
)
548
+
549
+ # Clean up after ourselves
550
+ os .chdir (orig_dir )
551
+ shutil .rmtree (util .CHECKOUT_NAME )
0 commit comments