77import sysconfig
88from contextlib import closing
99from pathlib import Path
10- from subprocess import PIPE , Popen , check_call
10+ from subprocess import PIPE , Popen , run
1111from threading import Thread
1212from types import TracebackType
1313from typing import IO , Iterator , Sequence , cast
1414
1515from .version import __version__
1616
1717
18+ def _check_call (cmd : list [str ]) -> None :
19+ run (cmd , check = True , stdout = PIPE , stderr = PIPE )
20+
21+
1822class Index :
1923 def __init__ (self , base_url : str , name : str , user : str , client_cmd_base : list [str ]) -> None :
2024 self ._client_cmd_base = client_cmd_base
@@ -27,11 +31,11 @@ def url(self) -> str:
2731 return f"{ self ._server_url } /{ self .name } /+simple/"
2832
2933 def use (self ) -> None :
30- check_call (self ._client_cmd_base + ["use" , f"{ self .user } /{ self .name } " ], stdout = PIPE , stderr = PIPE )
34+ _check_call (self ._client_cmd_base + ["use" , f"{ self .user } /{ self .name } " ])
3135
3236 def upload (self , * files : Path ) -> None :
3337 cmd = self ._client_cmd_base + ["upload" , "--index" , self .name ] + [str (i ) for i in files ]
34- check_call (cmd )
38+ _check_call (cmd )
3539
3640 def __repr__ (self ) -> str :
3741 return f"{ self .__class__ .__name__ } (url={ self .url } )"
@@ -81,7 +85,7 @@ def _create_and_start_server(self) -> None:
8185 cmd .extend (("--role" , "standalone" , "--root-passwd" , self ._passwd ))
8286 if self ._with_root_pypi is False :
8387 cmd .append ("--no-root-pypi" )
84- check_call (cmd , stdout = PIPE , stderr = PIPE )
88+ _check_call (cmd )
8589 # 2. start the server
8690 cmd = [self ._server , "--serverdir" , server_at , "--port" , str (self .port )]
8791 cmd .extend (self ._start_args )
@@ -112,14 +116,14 @@ def _setup_client(self) -> None:
112116 """create a user on the server and authenticate it"""
113117 self ._client_dir .mkdir (exist_ok = True )
114118 base = ["--clientdir" , str (self ._client_dir )]
115- check_call ([self ._client , "use" ] + base + [self .url ], stdout = PIPE , stderr = PIPE )
116- check_call ([self ._client , "login" ] + base + [self .user , "--password" , self ._passwd ], stdout = PIPE , stderr = PIPE )
119+ _check_call ([self ._client , "use" ] + base + [self .url ])
120+ _check_call ([self ._client , "login" ] + base + [self .user , "--password" , self ._passwd ])
117121
118122 def create_index (self , name : str , * args : str ) -> Index :
119123 if name in self ._indexes : # pragma: no cover
120124 raise ValueError (f"index { name } already exists" )
121125 base = [self ._client , "--clientdir" , str (self ._client_dir )]
122- check_call (base + ["index" , "-c" , name , * args ], stdout = PIPE , stderr = PIPE )
126+ _check_call (base + ["index" , "-c" , name , * args ])
123127 index = Index (f"{ self .url } /{ self .user } " , name , self .user , base )
124128 self ._indexes [name ] = index
125129 return index
0 commit comments