Skip to content

Commit 5510f29

Browse files
author
ajohns
committed
-added subprocess.Popen wrapper
-ported to wrapper
1 parent efb1c3d commit 5510f29

File tree

17 files changed

+144
-83
lines changed

17 files changed

+144
-83
lines changed

src/rez/bind/_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rez.exceptions import RezBindError
77
from rez.config import config
88
from rez.util import which
9+
from rez.utils.system import popen
910
from rez.utils.logging_ import print_debug
1011
from pipes import quote
1112
import subprocess
@@ -117,8 +118,7 @@ def _run_command(args):
117118
cmd_str = ' '.join(quote(x) for x in args)
118119
log("running: %s" % cmd_str)
119120

120-
p = subprocess.Popen(args, stdout=subprocess.PIPE,
121-
stderr=subprocess.PIPE)
121+
p = popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
122122
stdout, stderr = p.communicate()
123123
return stdout, stderr, p.returncode
124124

src/rez/developer_package.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from rez.serialise import load_from_file, FileFormat
44
from rez.packages_ import create_package
55
from rez.exceptions import PackageMetadataError, InvalidPackageError
6-
from rez.utils.syspath import add_sys_paths
6+
from rez.utils.system import add_sys_paths
77
from rez.utils.sourcecode import SourceCode
88
from rez.utils.logging_ import print_info, print_error
99
from inspect import isfunction

src/rez/package_help.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from rez.packages_ import iter_packages
22
from rez.config import config
33
from rez.rex_bindings import VersionBinding
4+
from rez.utils.system import popen
45
from rez.utils.backcompat import convert_old_command_expansions
56
from rez.utils.scope import scoped_formatter
67
from rez.system import system
@@ -92,7 +93,8 @@ def open(self, section_index=0):
9293
else:
9394
if self._verbose:
9495
print "running command: %s" % uri
95-
subprocess.Popen(uri, shell=True).wait()
96+
p = popen(uri, shell=True)
97+
p.wait()
9698

9799
def print_info(self, buf=None):
98100
"""Print help sections."""
@@ -112,7 +114,8 @@ def _open_url(cls, url):
112114
cmd = [config.browser, url]
113115
if not config.quiet:
114116
print "running command: %s" % " ".join(cmd)
115-
subprocess.Popen(cmd).communicate()
117+
p = popen(cmd)
118+
p.communicate()
116119
else:
117120
if not config.quiet:
118121
print "opening URL in browser: %s" % url

src/rez/package_py_utils.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
# these imports just forward the symbols into this module's namespace
10-
from rez.utils.sourcecode import late
10+
from rez.utils.system import popen
1111
from rez.exceptions import InvalidPackageError
1212

1313

@@ -165,7 +165,7 @@ def exec_command(attr, cmd):
165165
"""
166166
import subprocess
167167

168-
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
168+
p = popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
169169
out, err = p.communicate()
170170

171171
if p.returncode:
@@ -192,9 +192,8 @@ def exec_python(attr, src, executable="python"):
192192
if isinstance(src, basestring):
193193
src = [src]
194194

195-
p = subprocess.Popen(
196-
[executable, "-c", "; ".join(src)],
197-
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
195+
p = popen([executable, "-c", "; ".join(src)],
196+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
198197
out, err = p.communicate()
199198

200199
if p.returncode:
@@ -233,8 +232,8 @@ def find_site_python(module_name, paths=None):
233232

234233
py_cmd = 'import {x}; print {x}.__path__'.format(x=module_name)
235234

236-
p = subprocess.Popen(["python", "-c", py_cmd], stdout=subprocess.PIPE,
237-
stderr=subprocess.PIPE)
235+
p = popen(["python", "-c", py_cmd], stdout=subprocess.PIPE,
236+
stderr=subprocess.PIPE)
238237
out, err = p.communicate()
239238

240239
if p.returncode:

src/rez/pip.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from rez.vendor.distlib.util import parse_name_and_version
77
from rez.vendor.enum.enum import Enum
88
from rez.resolved_context import ResolvedContext
9+
from rez.system import popen
910
from rez.utils.logging_ import print_debug, print_info, print_warning
1011
from rez.exceptions import BuildError, PackageFamilyNotFoundError, \
1112
PackageNotFoundError, convert_errors
@@ -97,7 +98,7 @@ def run_pip_command(command_args, pip_version=None, python_version=None):
9798
command = [pip_exe] + list(command_args)
9899

99100
if context is None:
100-
return subprocess.Popen(command)
101+
return popen(command)
101102
else:
102103
return context.execute_shell(command=command, block=False)
103104

@@ -349,7 +350,7 @@ def _cmd(context, command):
349350
_log("running: %s" % cmd_str)
350351

351352
if context is None:
352-
p = subprocess.Popen(command)
353+
p = popen(command)
353354
else:
354355
p = context.execute_shell(command=command, block=False)
355356

src/rez/release_vcs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from rez.exceptions import ReleaseVCSError
22
from rez.packages_ import get_developer_package
33
from rez.util import which
4+
from rez.utils.system import popen
45
from rez.utils.logging_ import print_debug
56
from rez.utils.filesystem import walk_up_dirs
67
import subprocess
@@ -204,9 +205,10 @@ def _cmd(self, *nargs):
204205
if self.package.config.debug("package_release"):
205206
print_debug("Running command: %s" % cmd_str)
206207

207-
p = subprocess.Popen(nargs, stdout=subprocess.PIPE,
208-
stderr=subprocess.PIPE, cwd=self.pkg_root)
208+
p = popen(nargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
209+
cwd=self.pkg_root)
209210
out, err = p.communicate()
211+
210212
if p.returncode:
211213
print_debug("command stdout:")
212214
print_debug(out)

src/rez/rex.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from rez.exceptions import RexError, RexUndefinedVariableError, RezSystemError
1313
from rez.util import shlex_join
1414
from rez.utils import reraise
15+
from rez.system import popen
1516
from rez.utils.sourcecode import SourceCode, SourceCodeError
1617
from rez.utils.data_utils import AttrDictWrapper
1718
from rez.utils.formatting import expandvars
@@ -612,10 +613,10 @@ def subprocess(self, args, **subproc_kwargs):
612613
self.target_environ.update(self.manager.environ)
613614

614615
shell_mode = not hasattr(args, '__iter__')
615-
return subprocess.Popen(args,
616-
shell=shell_mode,
617-
env=self.target_environ,
618-
**subproc_kwargs)
616+
return popen(args,
617+
shell=shell_mode,
618+
env=self.target_environ,
619+
**subproc_kwargs)
619620

620621
def command(self, value):
621622
if self.passive:

src/rez/serialise.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from rez.utils.filesystem import TempDirs
99
from rez.exceptions import ResourceError, InvalidPackageError
1010
from rez.utils.memcached import memcached
11-
from rez.utils.syspath import add_sys_paths
11+
from rez.utils.system import add_sys_paths
1212
from rez.config import config
1313
from rez.vendor.enum import Enum
1414
from rez.vendor import yaml

src/rez/shells.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from rez.exceptions import RezSystemError
88
from rez.rex import EscapedString
99
from rez.config import config
10-
from rez.system import system
10+
from rez.system import system, popen
1111
import subprocess
1212
import os.path
1313
import pipes
@@ -345,7 +345,7 @@ def _create_ex():
345345
cmd.extend([self.executable, target_file])
346346

347347
try:
348-
p = subprocess.Popen(cmd, env=env, **Popen_args)
348+
p = popen(cmd, env=env, **Popen_args)
349349
except Exception as e:
350350
cmd_str = ' '.join(map(pipes.quote, cmd))
351351
raise RezSystemError("Error running command:\n%s\n%s"

src/rez/utils/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22

33
# Update this value to version up Rez. Do not place anything else in this file.
4-
_rez_version = "2.15.0"
4+
_rez_version = "2.16.0"
55

66
try:
77
from rez.vendor.version.version import Version

0 commit comments

Comments
 (0)