20
20
from io import BytesIO
21
21
from pathlib import Path
22
22
from subprocess import PIPE , CalledProcessError , check_output
23
+ from urllib .parse import urlparse
23
24
24
25
import requests
25
26
import toml
45
46
TBUMP_CMD = "pipx run tbump --non-interactive --only-patch"
46
47
47
48
CHECKOUT_NAME = ".jupyter_releaser_checkout"
48
-
49
- MOCK_GITHUB_URL = "http://127.0.0.1:8000 "
50
- RELEASE_HTML_PATTERN = f"(?:https://github.com| { MOCK_GITHUB_URL } )/(?P<owner>[^/]+)/(?P<repo>[^/]+)/releases/tag/(?P<tag>.*)"
49
+ RELEASE_HTML_PATTERN = (
50
+ "(?:https://github.com|%s)/(?P<owner>[^/]+)/(?P<repo>[^/]+)/releases/tag/(?P<tag>.*) "
51
+ )
51
52
RELEASE_API_PATTERN = (
52
53
"https://api.github.com/repos/(?P<owner>[^/]+)/(?P<repo>[^/]+)/releases/tags/(?P<tag>.*)"
53
54
)
54
55
55
-
56
56
SCHEMA = files ("jupyter_releaser" ).joinpath ("schema.json" ).read_text ()
57
57
SCHEMA = json .loads (SCHEMA )
58
58
@@ -468,7 +468,8 @@ def read_config():
468
468
469
469
def parse_release_url (release_url ):
470
470
"""Parse a release url into a regex match"""
471
- match = re .match (RELEASE_HTML_PATTERN , release_url )
471
+ pattern = RELEASE_HTML_PATTERN % get_mock_github_url ()
472
+ match = re .match (pattern , release_url )
472
473
match = match or re .match (RELEASE_API_PATTERN , release_url )
473
474
if not match :
474
475
raise ValueError (f"Release url is not valid: { release_url } " )
@@ -686,13 +687,20 @@ def get_remote_name(dry_run):
686
687
return "test"
687
688
688
689
690
+ def get_mock_github_url ():
691
+ port = os .environ .get ("MOCK_GITHUB_PORT" , "8000" )
692
+ return f"http://127.0.0.1:{ port } "
693
+
694
+
689
695
def ensure_mock_github ():
690
696
"""Check for or start a mock github server."""
691
- core .GH_HOST = MOCK_GITHUB_URL
697
+ core .GH_HOST = host = get_mock_github_url ()
698
+ port = urlparse (host ).port
699
+
692
700
log ("Ensuring mock GitHub" )
693
701
# First see if it is already running.
694
702
try :
695
- requests .get (MOCK_GITHUB_URL )
703
+ requests .get (host )
696
704
return
697
705
except requests .ConnectionError :
698
706
pass
@@ -705,7 +713,9 @@ def ensure_mock_github():
705
713
except ImportError :
706
714
run (f"'{ python } ' -m pip install fastapi uvicorn" )
707
715
708
- proc = subprocess .Popen ([python , "-m" , "uvicorn" , "jupyter_releaser.mock_github:app" ])
716
+ proc = subprocess .Popen (
717
+ [python , "-m" , "uvicorn" , "jupyter_releaser.mock_github:app" , "--port" , str (port )]
718
+ )
709
719
710
720
try :
711
721
ret = proc .wait (1 )
@@ -718,7 +728,7 @@ def ensure_mock_github():
718
728
719
729
while 1 :
720
730
try :
721
- requests .get (MOCK_GITHUB_URL )
731
+ requests .get (host )
722
732
break
723
733
except requests .ConnectionError :
724
734
pass
0 commit comments