本文整理汇总了Python中delegator.run方法的典型用法代码示例。如果您正苦于以下问题:Python delegator.run方法的具体用法?Python delegator.run怎么用?Python delegator.run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类delegator
的用法示例。
在下文中一共展示了delegator.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert_to_rst
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def convert_to_rst(fname):
cmd = "jupyter-nbconvert --to rst %s" % fname
c = delegator.run(cmd)
base_name = os.path.splitext(fname)[0]
image_files = "%s_files" % base_name
new_path = os.path.join(target_dir, image_files)
if os.path.isdir(new_path):
shutil.rmtree(new_path)
if os.path.isdir(image_files):
shutil.move(image_files, target_dir)
rst_file = '%s.rst' % base_name
new_path = os.path.join(target_dir, rst_file)
if os.path.isfile(new_path):
os.remove(new_path)
shutil.move(rst_file, target_dir)
示例2: get_downloads_info
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def get_downloads_info(names_map, section):
from .vendor.requirementslib.models.requirements import Requirement
info = []
p = project.parsed_pipfile
for fname in os.listdir(project.download_location):
# Get name from filename mapping.
name = Requirement.from_line(names_map[fname]).name
# Get the version info from the filenames.
version = parse_download_fname(fname, name)
# Get the hash of each file.
cmd = '{0} hash "{1}"'.format(
escape_grouped_arguments(which_pip()),
os.sep.join([project.download_location, fname]),
)
c = delegator.run(cmd)
hash = c.out.split("--hash=")[1].strip()
# Verify we're adding the correct version from Pipfile
# and not one from a dependency.
specified_version = p[section].get(name, "")
if is_required_version(version, specified_version):
info.append(dict(name=name, version=version, hash=hash))
return info
示例3: pip_download
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def pip_download(package_name):
cache_dir = vistir.compat.Path(PIPENV_CACHE_DIR)
pip_config = {
"PIP_CACHE_DIR": vistir.misc.fs_str(cache_dir.as_posix()),
"PIP_WHEEL_DIR": vistir.misc.fs_str(cache_dir.joinpath("wheels").as_posix()),
"PIP_DESTINATION_DIR": vistir.misc.fs_str(
cache_dir.joinpath("pkgs").as_posix()
),
}
for source in project.sources:
cmd = '{0} download "{1}" -i {2} -d {3}'.format(
escape_grouped_arguments(which_pip()),
package_name,
source["url"],
project.download_location,
)
c = delegator.run(cmd, env=pip_config)
if c.return_code == 0:
break
return c
示例4: __init__
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def __init__(self, args, parent: "Bash", blocking: bool = True) -> None:
"""constructor"""
# Environ inherents from parent.
# Remember passed-in arguments.
self.parent = parent
self.args = args
# Run the subprocess.
args = " ".join(args)
self.start_time = time.time()
self.sub = delegator.run(
f"{self.parent.path} {args}", env=self.parent.environ, block=blocking
)
if blocking:
self.elapsed_time = time.time() - self.start_time
示例5: test_local_vcs_urls_work
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def test_local_vcs_urls_work(PipenvInstance, tmpdir):
six_dir = tmpdir.join("six")
six_path = Path(six_dir.strpath)
with PipenvInstance(chdir=True) as p:
c = delegator.run(
"git clone https://github.com/benjaminp/six.git {0}".format(six_dir.strpath)
)
assert c.return_code == 0
c = p.pipenv("install git+{0}#egg=six".format(six_path.as_uri()))
assert c.return_code == 0
assert "six" in p.pipfile["packages"]
示例6: test_install_local_vcs_not_in_lockfile
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def test_install_local_vcs_not_in_lockfile(PipenvInstance):
with PipenvInstance(chdir=True) as p:
# six_path = os.path.join(p.path, "six")
six_path = p._pipfile.get_fixture_path("git/six/").as_posix()
c = delegator.run("git clone {0} ./six".format(six_path))
assert c.return_code == 0
c = p.pipenv("install -e ./six".format(six_path))
assert c.return_code == 0
six_key = list(p.pipfile["packages"].keys())[0]
# we don't need the rest of the test anymore, this just works on its own
assert six_key == "six"
示例7: run_command
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def run_command(cmd, *args, **kwargs):
"""
Take an input command and run it, handling exceptions and error codes and returning
its stdout and stderr.
:param cmd: The list of command and arguments.
:type cmd: list
:returns: A 2-tuple of the output and error from the command
:rtype: Tuple[str, str]
:raises: exceptions.PipenvCmdError
"""
from pipenv.vendor import delegator
from ._compat import decode_for_output
from .cmdparse import Script
catch_exceptions = kwargs.pop("catch_exceptions", True)
if isinstance(cmd, (six.string_types, list, tuple)):
cmd = Script.parse(cmd)
if not isinstance(cmd, Script):
raise TypeError("Command input must be a string, list or tuple")
if "env" not in kwargs:
kwargs["env"] = os.environ.copy()
kwargs["env"]["PYTHONIOENCODING"] = "UTF-8"
try:
cmd_string = cmd.cmdify()
except TypeError:
click_echo("Error turning command into string: {0}".format(cmd), err=True)
sys.exit(1)
if environments.is_verbose():
click_echo("Running command: $ {0}".format(cmd_string, err=True))
c = delegator.run(cmd_string, *args, **kwargs)
return_code = c.return_code
if environments.is_verbose():
click_echo("Command output: {0}".format(
crayons.blue(decode_for_output(c.out))
), err=True)
if not c.ok and catch_exceptions:
raise PipenvCmdError(cmd_string, c.out, c.err, return_code)
return c
示例8: load_path
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def load_path(python):
from ._compat import Path
import delegator
import json
python = Path(python).as_posix()
json_dump_commmand = '"import json, sys; print(json.dumps(sys.path));"'
c = delegator.run('"{0}" -c {1}'.format(python, json_dump_commmand))
if c.return_code == 0:
return json.loads(c.out.strip())
else:
return []
示例9: system_which
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def system_which(command, mult=False):
"""Emulates the system's which. Returns None if not found."""
_which = "which -a" if not os.name == "nt" else "where"
os.environ.update({
vistir.compat.fs_str(k): vistir.compat.fs_str(val)
for k, val in os.environ.items()
})
result = None
try:
c = delegator.run("{0} {1}".format(_which, command))
try:
# Which Not found…
if c.return_code == 127:
click.echo(
"{}: the {} system utility is required for Pipenv to find Python installations properly."
"\n Please install it.".format(
crayons.red("Warning", bold=True), crayons.red(_which)
),
err=True,
)
assert c.return_code == 0
except AssertionError:
result = fallback_which(command, allow_global=True)
except TypeError:
if not result:
result = fallback_which(command, allow_global=True)
else:
if not result:
result = next(iter([c.out, c.err]), "").split("\n")
result = next(iter(result)) if not mult else result
return result
if not result:
result = fallback_which(command, allow_global=True)
result = [result] if mult else result
return result
示例10: system_which
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def system_which(command, mult=False):
"""Emulates the system's which. Returns None if not found."""
_which = "which -a" if not os.name == "nt" else "where"
# os.environ = {
# vistir.compat.fs_str(k): vistir.compat.fs_str(val)
# for k, val in os.environ.items()
# }
result = None
try:
c = delegator.run("{0} {1}".format(_which, command))
try:
# Which Not found…
if c.return_code == 127:
click.echo(
"{}: the {} system utility is required for bake to find bash properly."
"\n Please install it.".format(
click.style("Warning", bold=True), click.style(_which, fg="red")
),
err=True,
)
assert c.return_code == 0
except AssertionError:
result = None
except TypeError:
if not result:
result = None
else:
if not result:
result = next(iter([c.out, c.err]), "").split("\n")
result = next(iter(result)) if not mult else result
return result
if not result:
result = None
result = [result] if mult else result
return result
示例11: __init__
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def __init__(self, *, bf, namespace="hashes", debug=False, enabled=True):
self.bf = bf
self.enabled = enabled
self.debug = debug
self.namespace = namespace
try:
# Assert git exists, and appears functioning.
c = delegator.run("git --version")
assert c.ok
if self.debug:
click.echo(" + cache.git.ok: true", err=True)
# Record the top-level directory of the git repository.
c = delegator.run("git rev-parse --show-toplevel")
self.git_root = c.out.strip()
if self.debug:
click.echo(f" + cache.git.root: {self.git_root!r}", err=True)
# Assert Bakefile exists within it.
assert self.bf.path.startswith(self.git_root)
if self.debug:
click.echo(f" + cache.git.contains_bakefile: true", err=True)
except AssertionError:
# Cache is disabled.
self.enabled = False
if debug:
click.echo(f" + cache.enabled: true", err=True)
示例12: __iter__
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def __iter__(self):
# TODO: Print these.
cmd = "git config --local --list"
if self.debug:
click.echo(f" {click.style('$', fg='green')} {cmd}", err=True)
c = delegator.run(cmd)
for result in c.out.split("\n"):
if result.startswith(self.prefix):
yield result.split("=", -1)[0][
len(self.prefix + "." + self.namespace + ".") :
]
示例13: __getitem__
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def __getitem__(self, k):
key = self._key_for_hashes(k)
cmd = f"git config --local --get {key}"
if self.debug:
click.echo(f" {click.style('$', fg='green')} {cmd}", err=True)
c = delegator.run(cmd)
if c.ok:
return c.out.strip()
else:
return None
示例14: __setitem__
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def __setitem__(self, k, v):
key = self._key_for_hashes(k)
cmd = f"git config --local {key} {v}"
if self.debug:
click.echo(f" {click.style('$', fg='green')} {cmd}", err=True)
c = delegator.run(cmd)
return c.ok
示例15: test_strict_vars1
# 需要导入模块: import delegator [as 别名]
# 或者: from delegator import run [as 别名]
def test_strict_vars1(monkeypatch):
"""Check that cli works correctly with strict vars."""
monkeypatch.setenv('SOM_TT_VALUE', '1')
monkeypatch.setenv('SOM_TT_KEY', '2')
variables = delegator.run('dump-env -p SOM_TT_ --strict=SOM_TT_KEY')
assert variables.out == 'KEY=2\nVALUE=1\n'
assert variables.subprocess.returncode == 0