66from .constants import NPM_REGISTRY_URL
77from .package_json import PackageJson
88from .utils import build_nm_path , build_pj_path
9- from .timeit import timeit , is_timeit_enabled
9+ from .timeit import timeit
1010
1111
1212class PackageManagerError (RuntimeError ):
@@ -34,6 +34,7 @@ def __init__(
3434 script_path ,
3535 module_path = None ,
3636 sources_root = None ,
37+ verbose = False ,
3738 ):
3839 self .module_path = build_path [len (build_root ) + 1 :] if module_path is None else module_path
3940 self .build_path = build_path
@@ -42,6 +43,7 @@ def __init__(
4243 self .sources_root = sources_path [: - len (self .module_path ) - 1 ] if sources_root is None else sources_root
4344 self .nodejs_bin_path = nodejs_bin_path
4445 self .script_path = script_path
46+ self .verbose = verbose
4547
4648 @classmethod
4749 def load_package_json (cls , path ):
@@ -133,18 +135,27 @@ def _exec_command(self, args, cwd: str, include_defaults=True, script_path=None,
133135 + args
134136 + (self ._get_default_options () if include_defaults else [])
135137 )
136- p = subprocess .Popen (cmd , cwd = cwd , stdin = None , stdout = subprocess .PIPE , stderr = subprocess .PIPE , env = env )
138+ p = subprocess .Popen (
139+ cmd ,
140+ cwd = cwd ,
141+ stdin = None ,
142+ stdout = subprocess .PIPE ,
143+ stderr = subprocess .PIPE ,
144+ env = env ,
145+ text = True ,
146+ encoding = "utf-8" ,
147+ )
137148 stdout , stderr = p .communicate ()
138149
139- if is_timeit_enabled () :
150+ if self . verbose :
140151 print (f'cd { cwd } && { " " .join (cmd )} ' , file = sys .stderr )
141- print (f'stdout: { stdout . decode ( "utf-8" ) } ' , file = sys .stderr )
142- print (f'stderr: { stderr . decode ( "utf-8" ) } ' , file = sys .stderr )
152+ print (f'stdout: { stdout } ' , file = sys .stderr ) if stdout else None
153+ print (f'stderr: { stderr } ' , file = sys .stderr ) if stderr else None
143154
144155 if p .returncode != 0 :
145156 self ._dump_debug_log ()
146157
147- raise PackageManagerCommandError (cmd , p .returncode , stdout . decode ( "utf-8" ) , stderr . decode ( "utf-8" ) )
158+ raise PackageManagerCommandError (cmd , p .returncode , stdout , stderr )
148159
149160 def _nm_path (self , * parts ):
150161 return os .path .join (build_nm_path (self .build_path ), * parts )
0 commit comments