mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
@@ -12,8 +12,7 @@ click = "*"
|
||||
pytest-pypy = {path = "./tests/pytest-pypi", editable = true}
|
||||
pytest-tap = "*"
|
||||
stdeb = {version="*", sys_platform="== 'linux'"}
|
||||
white = {version="*", python_version="=='3.6'"}
|
||||
black = {version="*", python_version="=='3.6'"}
|
||||
white = {version="*"}
|
||||
|
||||
|
||||
[packages]
|
||||
|
||||
Generated
+4
-14
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "cce9ff19b4d0e5df129d50def066395400866c5cc42ad6c7f99234fbed85d676"
|
||||
"sha256": "d995b30822f7b34c1e620ca94a4657f3c868f78264d88b475d5353c004330bf7"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {},
|
||||
@@ -43,15 +43,6 @@
|
||||
],
|
||||
"version": "==2.5.3"
|
||||
},
|
||||
"black": {
|
||||
"hashes": [
|
||||
"sha256:0461c7a52b5beb378936bf642753dec7a45305c96c6129d540b9c53227121a5a",
|
||||
"sha256:7183263650ba3071034e90b40a1ea74abccbd32cf525cef6d7914479dbe7f2fb"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version == '3.6'",
|
||||
"version": "==18.3a0"
|
||||
},
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:14131608ad2fd56836d33a71ee60fa1c82bc9d2c8d98b7bdbc631fe1b3cd1296",
|
||||
@@ -364,12 +355,11 @@
|
||||
},
|
||||
"white": {
|
||||
"hashes": [
|
||||
"sha256:b3850a6737f5ce231564ece002f4f5e0c15b5377364a904b7830d8d45300934c",
|
||||
"sha256:d5f52fa8143f440ab792d09d8a179b7a1779c27e982e8ab8e335ac81699fcd04"
|
||||
"sha256:45e2c7f54de1facc60bf0a726b480cdc43422aad57c3a0bc5ba54cb536696683",
|
||||
"sha256:bca98066256cfff6fb85ec36b95cc5913c888c170a8407c340786972b06c6f8f"
|
||||
],
|
||||
"index": "pypi",
|
||||
"markers": "python_version == '3.6'",
|
||||
"version": "==0.0.2"
|
||||
"version": "==0.1.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -73,7 +73,9 @@ except ImportError:
|
||||
try:
|
||||
out.append(packI(acc))
|
||||
except struct.error:
|
||||
raise ValueError('base85 overflow in hunk starting at byte %d' % i)
|
||||
raise ValueError(
|
||||
'base85 overflow in hunk starting at byte %d' % i
|
||||
)
|
||||
|
||||
result = b''.join(out)
|
||||
if padding:
|
||||
|
||||
+116
-33
@@ -57,24 +57,43 @@ def setup_verbose(ctx, param, value):
|
||||
|
||||
|
||||
@click.group(
|
||||
cls=PipenvGroup, invoke_without_command=True, context_settings=CONTEXT_SETTINGS
|
||||
cls=PipenvGroup,
|
||||
invoke_without_command=True,
|
||||
context_settings=CONTEXT_SETTINGS,
|
||||
)
|
||||
@click.option(
|
||||
'--update', is_flag=True, default=False, help="Update Pipenv & pip to latest."
|
||||
'--update',
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Update Pipenv & pip to latest.",
|
||||
)
|
||||
@click.option(
|
||||
'--where', is_flag=True, default=False, help="Output project home information."
|
||||
'--where',
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Output project home information.",
|
||||
)
|
||||
@click.option(
|
||||
'--venv', is_flag=True, default=False, help="Output virtualenv information."
|
||||
'--venv',
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Output virtualenv information.",
|
||||
)
|
||||
@click.option(
|
||||
'--py', is_flag=True, default=False, help="Output Python interpreter information."
|
||||
'--py',
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Output Python interpreter information.",
|
||||
)
|
||||
@click.option(
|
||||
'--envs', is_flag=True, default=False, help="Output Environment Variable options."
|
||||
'--envs',
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Output Environment Variable options.",
|
||||
)
|
||||
@click.option(
|
||||
'--rm', is_flag=True, default=False, help="Remove the virtualenv."
|
||||
)
|
||||
@click.option('--rm', is_flag=True, default=False, help="Remove the virtualenv.")
|
||||
@click.option('--bare', is_flag=True, default=False, help="Minimal output.")
|
||||
@click.option(
|
||||
'--completion',
|
||||
@@ -151,7 +170,9 @@ def cli(
|
||||
path = os.sep.join([os.path.dirname(__file__), 'pipenv.1'])
|
||||
os.execle(core.system_which('man'), 'man', path, os.environ)
|
||||
else:
|
||||
click.echo('man does not appear to be available on your system.', err=True)
|
||||
click.echo(
|
||||
'man does not appear to be available on your system.', err=True
|
||||
)
|
||||
if envs:
|
||||
click.echo(
|
||||
'The following environment variables can be set, to do various things:\n'
|
||||
@@ -181,7 +202,9 @@ def cli(
|
||||
# There is no virtualenv yet.
|
||||
if not core.project.virtualenv_exists:
|
||||
click.echo(
|
||||
crayons.red('No virtualenv has been created for this project yet!'),
|
||||
crayons.red(
|
||||
'No virtualenv has been created for this project yet!'
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
sys.exit(1)
|
||||
@@ -258,7 +281,9 @@ def cli(
|
||||
nargs=1,
|
||||
help="Specify which version of Python virtualenv should use.",
|
||||
)
|
||||
@click.option('--system', is_flag=True, default=False, help="System pip management.")
|
||||
@click.option(
|
||||
'--system', is_flag=True, default=False, help="System pip management."
|
||||
)
|
||||
@click.option(
|
||||
'--requirements',
|
||||
'-r',
|
||||
@@ -266,7 +291,9 @@ def cli(
|
||||
default=False,
|
||||
help="Import a requirements.txt file.",
|
||||
)
|
||||
@click.option('--code', '-c', nargs=1, default=False, help="Import from codebase.")
|
||||
@click.option(
|
||||
'--code', '-c', nargs=1, default=False, help="Import from codebase."
|
||||
)
|
||||
@click.option(
|
||||
'--verbose',
|
||||
'-v',
|
||||
@@ -299,7 +326,9 @@ def cli(
|
||||
default=False,
|
||||
help=u"Abort if the Pipfile.lock is out–of–date, or Python version is wrong.",
|
||||
)
|
||||
@click.option('--pre', is_flag=True, default=False, help=u"Allow pre–releases.")
|
||||
@click.option(
|
||||
'--pre', is_flag=True, default=False, help=u"Allow pre–releases."
|
||||
)
|
||||
@click.option(
|
||||
'--keep-outdated',
|
||||
is_flag=True,
|
||||
@@ -354,7 +383,9 @@ def install(
|
||||
)
|
||||
|
||||
|
||||
@click.command(short_help="Un-installs a provided package and removes it from Pipfile.")
|
||||
@click.command(
|
||||
short_help="Un-installs a provided package and removes it from Pipfile."
|
||||
)
|
||||
@click.argument('package_name', default=False)
|
||||
@click.argument('more_packages', nargs=-1)
|
||||
@click.option(
|
||||
@@ -369,7 +400,9 @@ def install(
|
||||
nargs=1,
|
||||
help="Specify which version of Python virtualenv should use.",
|
||||
)
|
||||
@click.option('--system', is_flag=True, default=False, help="System pip management.")
|
||||
@click.option(
|
||||
'--system', is_flag=True, default=False, help="System pip management."
|
||||
)
|
||||
@click.option(
|
||||
'--verbose',
|
||||
'-v',
|
||||
@@ -463,7 +496,9 @@ def uninstall(
|
||||
@click.option(
|
||||
'--clear', is_flag=True, default=False, help="Clear the dependency cache."
|
||||
)
|
||||
@click.option('--pre', is_flag=True, default=False, help=u"Allow pre–releases.")
|
||||
@click.option(
|
||||
'--pre', is_flag=True, default=False, help=u"Allow pre–releases."
|
||||
)
|
||||
@click.option(
|
||||
'--keep-outdated',
|
||||
is_flag=True,
|
||||
@@ -489,7 +524,9 @@ def lock(
|
||||
pre = core.project.settings.get('pre')
|
||||
if requirements:
|
||||
core.do_init(dev=dev, requirements=requirements)
|
||||
core.do_lock(verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated)
|
||||
core.do_lock(
|
||||
verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated
|
||||
)
|
||||
|
||||
|
||||
@click.command(
|
||||
@@ -521,13 +558,17 @@ def lock(
|
||||
help="Always spawn a subshell, even if one is already spawned.",
|
||||
)
|
||||
@click.argument('shell_args', nargs=-1)
|
||||
def shell(three=None, python=False, fancy=False, shell_args=None, anyway=False):
|
||||
def shell(
|
||||
three=None, python=False, fancy=False, shell_args=None, anyway=False
|
||||
):
|
||||
from .import core
|
||||
|
||||
# Prevent user from activating nested environments.
|
||||
if 'PIPENV_ACTIVE' in os.environ:
|
||||
# If PIPENV_ACTIVE is set, VIRTUAL_ENV should always be set too.
|
||||
venv_name = os.environ.get('VIRTUAL_ENV', 'UNKNOWN_VIRTUAL_ENVIRONMENT')
|
||||
venv_name = os.environ.get(
|
||||
'VIRTUAL_ENV', 'UNKNOWN_VIRTUAL_ENVIRONMENT'
|
||||
)
|
||||
if not anyway:
|
||||
click.echo(
|
||||
'{0} {1} {2}\nNo action taken to avoid nested environments.'.format(
|
||||
@@ -543,7 +584,9 @@ def shell(three=None, python=False, fancy=False, shell_args=None, anyway=False):
|
||||
# Use fancy mode for Windows.
|
||||
if os.name == 'nt':
|
||||
fancy = True
|
||||
core.do_shell(three=three, python=python, fancy=fancy, shell_args=shell_args)
|
||||
core.do_shell(
|
||||
three=three, python=python, fancy=fancy, shell_args=shell_args
|
||||
)
|
||||
|
||||
|
||||
@click.command(
|
||||
@@ -591,7 +634,9 @@ def run(command, args, three=None, python=False):
|
||||
nargs=1,
|
||||
help="Specify which version of Python virtualenv should use.",
|
||||
)
|
||||
@click.option('--system', is_flag=True, default=False, help="Use system Python.")
|
||||
@click.option(
|
||||
'--system', is_flag=True, default=False, help="Use system Python."
|
||||
)
|
||||
@click.option(
|
||||
'--unused',
|
||||
nargs=1,
|
||||
@@ -599,10 +644,19 @@ def run(command, args, three=None, python=False):
|
||||
help="Given a code path, show potentially unused dependencies.",
|
||||
)
|
||||
@click.argument('args', nargs=-1)
|
||||
def check(three=None, python=False, system=False, unused=False, style=False, args=None):
|
||||
def check(
|
||||
three=None,
|
||||
python=False,
|
||||
system=False,
|
||||
unused=False,
|
||||
style=False,
|
||||
args=None,
|
||||
):
|
||||
from .import core
|
||||
|
||||
core.do_check(three=three, python=python, system=system, unused=unused, args=args)
|
||||
core.do_check(
|
||||
three=three, python=python, system=system, unused=unused, args=args
|
||||
)
|
||||
|
||||
|
||||
@click.command(short_help="Runs lock, then sync.")
|
||||
@@ -638,7 +692,9 @@ def check(three=None, python=False, system=False, unused=False, style=False, arg
|
||||
'--clear', is_flag=True, default=False, help="Clear the dependency cache."
|
||||
)
|
||||
@click.option('--bare', is_flag=True, default=False, help="Minimal output.")
|
||||
@click.option('--pre', is_flag=True, default=False, help=u"Allow pre–releases.")
|
||||
@click.option(
|
||||
'--pre', is_flag=True, default=False, help=u"Allow pre–releases."
|
||||
)
|
||||
@click.option(
|
||||
'--keep-outdated',
|
||||
is_flag=True,
|
||||
@@ -652,10 +708,16 @@ def check(three=None, python=False, system=False, unused=False, style=False, arg
|
||||
help="Install dependencies one-at-a-time, instead of concurrently.",
|
||||
)
|
||||
@click.option(
|
||||
'--outdated', is_flag=True, default=False, help=u"List out–of–date dependencies."
|
||||
'--outdated',
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help=u"List out–of–date dependencies.",
|
||||
)
|
||||
@click.option(
|
||||
'--dry-run', is_flag=True, default=None, help=u"List out–of–date dependencies."
|
||||
'--dry-run',
|
||||
is_flag=True,
|
||||
default=None,
|
||||
help=u"List out–of–date dependencies.",
|
||||
)
|
||||
@click.argument('package', default=False)
|
||||
@click.pass_context
|
||||
@@ -696,7 +758,9 @@ def update(
|
||||
# Load the --pre settings from the Pipfile.
|
||||
if not pre:
|
||||
pre = core.project.settings.get('pre')
|
||||
core.do_lock(verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated)
|
||||
core.do_lock(
|
||||
verbose=verbose, clear=clear, pre=pre, keep_outdated=keep_outdated
|
||||
)
|
||||
core.do_sync(
|
||||
ctx=ctx,
|
||||
install=install,
|
||||
@@ -746,7 +810,9 @@ def update(
|
||||
)
|
||||
|
||||
|
||||
@click.command(short_help=u"Displays currently–installed dependency graph information.")
|
||||
@click.command(
|
||||
short_help=u"Displays currently–installed dependency graph information."
|
||||
)
|
||||
@click.option('--bare', is_flag=True, default=False, help="Minimal output.")
|
||||
@click.option('--json', is_flag=True, default=False, help="Output JSON.")
|
||||
@click.option(
|
||||
@@ -778,7 +844,9 @@ def run_open(module, three=None, python=None):
|
||||
# Ensure that virtualenv is available.
|
||||
core.ensure_project(three=three, python=python, validate=False)
|
||||
c = delegator.run(
|
||||
'{0} -c "import {1}; print({1}.__file__);"'.format(core.which('python'), module)
|
||||
'{0} -c "import {1}; print({1}.__file__);"'.format(
|
||||
core.which('python'), module
|
||||
)
|
||||
)
|
||||
try:
|
||||
assert c.return_code == 0
|
||||
@@ -789,7 +857,9 @@ def run_open(module, three=None, python=None):
|
||||
p = os.path.dirname(c.out.strip().rstrip('cdo'))
|
||||
else:
|
||||
p = c.out.strip().rstrip('cdo')
|
||||
click.echo(crayons.normal('Opening {0!r} in your EDITOR.'.format(p), bold=True))
|
||||
click.echo(
|
||||
crayons.normal('Opening {0!r} in your EDITOR.'.format(p), bold=True)
|
||||
)
|
||||
click.edit(filename=p)
|
||||
sys.exit(0)
|
||||
|
||||
@@ -865,7 +935,9 @@ def sync(
|
||||
)
|
||||
|
||||
|
||||
@click.command(short_help="Uninstalls all packages not specified in Pipfile.lock.")
|
||||
@click.command(
|
||||
short_help="Uninstalls all packages not specified in Pipfile.lock."
|
||||
)
|
||||
@click.option(
|
||||
'--verbose',
|
||||
'-v',
|
||||
@@ -887,15 +959,26 @@ def sync(
|
||||
help="Specify which version of Python virtualenv should use.",
|
||||
)
|
||||
@click.option(
|
||||
'--dry-run', is_flag=True, default=False, help="Just output unneeded packages."
|
||||
'--dry-run',
|
||||
is_flag=True,
|
||||
default=False,
|
||||
help="Just output unneeded packages.",
|
||||
)
|
||||
@click.pass_context
|
||||
def clean(
|
||||
ctx, three=None, python=None, dry_run=False, bare=False, user=False, verbose=False
|
||||
ctx,
|
||||
three=None,
|
||||
python=None,
|
||||
dry_run=False,
|
||||
bare=False,
|
||||
user=False,
|
||||
verbose=False,
|
||||
):
|
||||
from .import core
|
||||
|
||||
core.do_clean(ctx=ctx, three=three, python=python, dry_run=dry_run, verbose=verbose)
|
||||
core.do_clean(
|
||||
ctx=ctx, three=three, python=python, dry_run=dry_run, verbose=verbose
|
||||
)
|
||||
|
||||
|
||||
# Install click commands.
|
||||
|
||||
+241
-80
@@ -126,7 +126,9 @@ def which(command, location=None, allow_global=False):
|
||||
location = project.virtualenv_location
|
||||
if not allow_global:
|
||||
if os.name == 'nt':
|
||||
p = find_windows_executable(os.path.join(location, 'Scripts'), command)
|
||||
p = find_windows_executable(
|
||||
os.path.join(location, 'Scripts'), command
|
||||
)
|
||||
else:
|
||||
p = os.sep.join([location] + ['bin/{0}'.format(command)])
|
||||
else:
|
||||
@@ -151,7 +153,9 @@ def load_dot_env():
|
||||
)
|
||||
if os.path.isfile(denv):
|
||||
click.echo(
|
||||
crayons.normal('Loading .env environment variables…', bold=True),
|
||||
crayons.normal(
|
||||
'Loading .env environment variables…', bold=True
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
dotenv.load_dotenv(denv, override=True)
|
||||
@@ -160,7 +164,9 @@ def load_dot_env():
|
||||
def add_to_path(p):
|
||||
"""Adds a given path to the PATH."""
|
||||
if p not in os.environ['PATH']:
|
||||
os.environ['PATH'] = '{0}{1}{2}'.format(p, os.pathsep, os.environ['PATH'])
|
||||
os.environ['PATH'] = '{0}{1}{2}'.format(
|
||||
p, os.pathsep, os.environ['PATH']
|
||||
)
|
||||
|
||||
|
||||
def ensure_latest_self(user=False):
|
||||
@@ -179,22 +185,30 @@ def ensure_latest_self(user=False):
|
||||
click.echo(
|
||||
'{0}: {1} is now available. Automatically upgrading!'.format(
|
||||
crayons.green('Courtesy Notice'),
|
||||
crayons.yellow('Pipenv {v.major}.{v.minor}.{v.patch}'.format(v=latest)),
|
||||
crayons.yellow(
|
||||
'Pipenv {v.major}.{v.minor}.{v.patch}'.format(v=latest)
|
||||
),
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
# Resolve user site, enable user mode automatically.
|
||||
if site.ENABLE_USER_SITE and site.USER_SITE in sys.modules['pipenv'].__file__:
|
||||
if site.ENABLE_USER_SITE and site.USER_SITE in sys.modules[
|
||||
'pipenv'
|
||||
].__file__:
|
||||
args = ['install', '--user', '--upgrade', 'pipenv', '--no-cache']
|
||||
else:
|
||||
args = ['install', '--upgrade', 'pipenv', '--no-cache']
|
||||
os.environ['PIP_PYTHON_VERSION'] = str('.'.join(map(str, sys.version_info[:3])))
|
||||
os.environ['PIP_PYTHON_VERSION'] = str(
|
||||
'.'.join(map(str, sys.version_info[:3]))
|
||||
)
|
||||
os.environ['PIP_PYTHON_PATH'] = str(sys.executable)
|
||||
sys.modules['pip'].main(args)
|
||||
click.echo(
|
||||
'{0} to {1}!'.format(
|
||||
crayons.green('Pipenv updated'),
|
||||
crayons.yellow('{v.major}.{v.minor}.{v.patch}'.format(v=latest)),
|
||||
crayons.yellow(
|
||||
'{v.major}.{v.minor}.{v.patch}'.format(v=latest)
|
||||
),
|
||||
)
|
||||
)
|
||||
else:
|
||||
@@ -223,7 +237,9 @@ def ensure_latest_pip():
|
||||
if 'however' in c.err:
|
||||
# If version is out of date, update.
|
||||
click.echo(
|
||||
crayons.normal(u'Pip is out of date… updating to latest.', bold=True)
|
||||
crayons.normal(
|
||||
u'Pip is out of date… updating to latest.', bold=True
|
||||
)
|
||||
)
|
||||
windows = '-m' if os.name == 'nt' else ''
|
||||
c = delegator.run(
|
||||
@@ -334,7 +350,9 @@ def ensure_pipfile(validate=True, skip_requirements=False):
|
||||
)
|
||||
else:
|
||||
click.echo(
|
||||
crayons.normal(u'Creating a Pipfile for this project…', bold=True),
|
||||
crayons.normal(
|
||||
u'Creating a Pipfile for this project…', bold=True
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
# Create the pipfile if it doesn't exist.
|
||||
@@ -348,7 +366,8 @@ def ensure_pipfile(validate=True, skip_requirements=False):
|
||||
# Write changes out to disk.
|
||||
if changed:
|
||||
click.echo(
|
||||
crayons.normal(u'Fixing package names in Pipfile…', bold=True), err=True
|
||||
crayons.normal(u'Fixing package names in Pipfile…', bold=True),
|
||||
err=True,
|
||||
)
|
||||
project.write_toml(p)
|
||||
|
||||
@@ -450,13 +469,17 @@ def ensure_python(three=None, python=None):
|
||||
if PYENV_INSTALLED:
|
||||
if PYENV_ROOT:
|
||||
pyenv_paths = {}
|
||||
for found in glob('{0}{1}versions{1}*'.format(PYENV_ROOT, os.sep)):
|
||||
for found in glob(
|
||||
'{0}{1}versions{1}*'.format(PYENV_ROOT, os.sep)
|
||||
):
|
||||
pyenv_paths[os.path.split(found)[1]] = '{0}{1}bin'.format(
|
||||
found, os.sep
|
||||
)
|
||||
for version_str, pyenv_path in pyenv_paths.items():
|
||||
version = pip9._vendor.packaging.version.parse(version_str)
|
||||
if version.is_prerelease and pyenv_paths.get(version.base_version):
|
||||
if version.is_prerelease and pyenv_paths.get(
|
||||
version.base_version
|
||||
):
|
||||
continue
|
||||
|
||||
add_to_path(pyenv_path)
|
||||
@@ -533,7 +556,9 @@ def ensure_python(three=None, python=None):
|
||||
click.echo(
|
||||
u'{0} {1} {2} {3}{4}'.format(
|
||||
crayons.normal(u'Installing', bold=True),
|
||||
crayons.green(u'CPython {0}'.format(version), bold=True),
|
||||
crayons.green(
|
||||
u'CPython {0}'.format(version), bold=True
|
||||
),
|
||||
crayons.normal(u'with pyenv', bold=True),
|
||||
crayons.normal(u'(this may take a few minutes)'),
|
||||
crayons.normal(u'…', bold=True),
|
||||
@@ -613,16 +638,20 @@ def ensure_virtualenv(three=None, python=None, site_packages=False):
|
||||
# about, so confirm first.
|
||||
if 'VIRTUAL_ENV' in os.environ:
|
||||
if not (
|
||||
PIPENV_YES or click.confirm('Remove existing virtualenv?', default=True)
|
||||
PIPENV_YES or
|
||||
click.confirm('Remove existing virtualenv?', default=True)
|
||||
):
|
||||
abort()
|
||||
click.echo(
|
||||
crayons.normal(u'Removing existing virtualenv…', bold=True), err=True
|
||||
crayons.normal(u'Removing existing virtualenv…', bold=True),
|
||||
err=True,
|
||||
)
|
||||
# Remove the virtualenv.
|
||||
cleanup_virtualenv(bare=True)
|
||||
# Call this function again.
|
||||
ensure_virtualenv(three=three, python=python, site_packages=site_packages)
|
||||
ensure_virtualenv(
|
||||
three=three, python=python, site_packages=site_packages
|
||||
)
|
||||
|
||||
|
||||
def ensure_project(
|
||||
@@ -643,7 +672,9 @@ def ensure_project(
|
||||
project.touch_pipfile()
|
||||
# Skip virtualenv creation when --system was used.
|
||||
if not system:
|
||||
ensure_virtualenv(three=three, python=python, site_packages=site_packages)
|
||||
ensure_virtualenv(
|
||||
three=three, python=python, site_packages=site_packages
|
||||
)
|
||||
if warn:
|
||||
# Warn users if they are using the wrong version of Python.
|
||||
if project.required_python_version:
|
||||
@@ -688,7 +719,9 @@ def proper_case_section(section):
|
||||
"""
|
||||
# Casing for section.
|
||||
changed_values = False
|
||||
unknown_names = [k for k in section.keys() if k not in set(project.proper_names)]
|
||||
unknown_names = [
|
||||
k for k in section.keys() if k not in set(project.proper_names)
|
||||
]
|
||||
# Replace each package with proper casing.
|
||||
for dep in unknown_names:
|
||||
try:
|
||||
@@ -713,7 +746,10 @@ def shorten_path(location, bold=False):
|
||||
"""Returns a visually shorter representation of a given system path."""
|
||||
original = location
|
||||
short = os.sep.join(
|
||||
[s[0] if len(s) > (len('2long4')) else s for s in location.split(os.sep)]
|
||||
[
|
||||
s[0] if len(s) > (len('2long4')) else s
|
||||
for s in location.split(os.sep)
|
||||
]
|
||||
)
|
||||
short = short.split(os.sep)
|
||||
short[-1] = original.split(os.sep)[-1]
|
||||
@@ -752,7 +788,8 @@ def do_where(virtualenv=False, bare=True):
|
||||
location = project.virtualenv_location
|
||||
if not bare:
|
||||
click.echo(
|
||||
'Virtualenv location: {0}'.format(crayons.green(location)), err=True
|
||||
'Virtualenv location: {0}'.format(crayons.green(location)),
|
||||
err=True,
|
||||
)
|
||||
else:
|
||||
click.echo(location)
|
||||
@@ -802,7 +839,9 @@ def do_install_dependencies(
|
||||
if skip_lock or only or not project.lockfile_exists:
|
||||
if not bare:
|
||||
click.echo(
|
||||
crayons.normal(u'Installing dependencies from Pipfile…', bold=True)
|
||||
crayons.normal(
|
||||
u'Installing dependencies from Pipfile…', bold=True
|
||||
)
|
||||
)
|
||||
lockfile = split_file(project._lockfile)
|
||||
else:
|
||||
@@ -856,7 +895,8 @@ def do_install_dependencies(
|
||||
index = None
|
||||
if ' -i ' in dep:
|
||||
dep, index = dep.split(' -i ')
|
||||
dep = '{0} {1}'.format(dep, ' '.join(index.split()[1:])).strip()
|
||||
dep = '{0} {1}'.format(dep, ' '.join(index.split()[1:])).strip(
|
||||
)
|
||||
index = index.split()[0]
|
||||
# Install the module.
|
||||
c = pip_install(
|
||||
@@ -879,13 +919,18 @@ def do_install_dependencies(
|
||||
# Iterate over the hopefully-poorly-packaged dependencies...
|
||||
if failed_deps_list:
|
||||
click.echo(
|
||||
crayons.normal(u'Installing initially–failed dependencies…', bold=True)
|
||||
crayons.normal(
|
||||
u'Installing initially–failed dependencies…', bold=True
|
||||
)
|
||||
)
|
||||
for dep, ignore_hash in progress.bar(failed_deps_list, label=INSTALL_LABEL2):
|
||||
for dep, ignore_hash in progress.bar(
|
||||
failed_deps_list, label=INSTALL_LABEL2
|
||||
):
|
||||
index = None
|
||||
if ' -i ' in dep:
|
||||
dep, index = dep.split(' -i ')
|
||||
dep = '{0} {1}'.format(dep, ' '.join(index.split()[1:])).strip()
|
||||
dep = '{0} {1}'.format(dep, ' '.join(index.split()[1:])).strip(
|
||||
)
|
||||
index = index.split()[0]
|
||||
# Install the module.
|
||||
c = pip_install(
|
||||
@@ -932,7 +977,8 @@ def convert_three_to_python(three, python):
|
||||
def do_create_virtualenv(python=None, site_packages=False):
|
||||
"""Creates a virtualenv."""
|
||||
click.echo(
|
||||
crayons.normal(u'Creating a virtualenv for this project…', bold=True), err=True
|
||||
crayons.normal(u'Creating a virtualenv for this project…', bold=True),
|
||||
err=True,
|
||||
)
|
||||
# The user wants the virtualenv in the project.
|
||||
if PIPENV_VENV_IN_PROJECT:
|
||||
@@ -946,7 +992,14 @@ def do_create_virtualenv(python=None, site_packages=False):
|
||||
cmd.append('--system-site-packages')
|
||||
else:
|
||||
# Default: use pew.
|
||||
cmd = [sys.executable, '-m', 'pipenv.pew', 'new', project.virtualenv_name, '-d']
|
||||
cmd = [
|
||||
sys.executable,
|
||||
'-m',
|
||||
'pipenv.pew',
|
||||
'new',
|
||||
project.virtualenv_name,
|
||||
'-d',
|
||||
]
|
||||
# Default to using sys.executable, if Python wasn't provided.
|
||||
if not python:
|
||||
python = sys.executable
|
||||
@@ -980,7 +1033,8 @@ def do_create_virtualenv(python=None, site_packages=False):
|
||||
# Enable site-packages, if desired...
|
||||
if not PIPENV_VENV_IN_PROJECT and site_packages:
|
||||
click.echo(
|
||||
crayons.normal(u'Making site-packages available…', bold=True), err=True
|
||||
crayons.normal(u'Making site-packages available…', bold=True),
|
||||
err=True,
|
||||
)
|
||||
os.environ['VIRTUAL_ENV'] = project.virtualenv_location
|
||||
delegator.run('pipenv run pewtwo toggleglobalsitepackages')
|
||||
@@ -1027,7 +1081,12 @@ def get_downloads_info(names_map, section):
|
||||
|
||||
|
||||
def do_lock(
|
||||
verbose=False, system=False, clear=False, pre=False, keep_outdated=False, write=True
|
||||
verbose=False,
|
||||
system=False,
|
||||
clear=False,
|
||||
pre=False,
|
||||
keep_outdated=False,
|
||||
write=True,
|
||||
):
|
||||
"""Executes the freeze functionality."""
|
||||
cached_lockfile = {}
|
||||
@@ -1065,9 +1124,16 @@ def do_lock(
|
||||
if dev_package in project.packages:
|
||||
dev_packages[dev_package] = project.packages[dev_package]
|
||||
# Resolve dev-package dependencies, with pip-tools.
|
||||
deps = convert_deps_to_pip(dev_packages, project, r=False, include_index=True)
|
||||
deps = convert_deps_to_pip(
|
||||
dev_packages, project, r=False, include_index=True
|
||||
)
|
||||
results = venv_resolve_deps(
|
||||
deps, which=which, verbose=verbose, project=project, clear=clear, pre=pre
|
||||
deps,
|
||||
which=which,
|
||||
verbose=verbose,
|
||||
project=project,
|
||||
clear=clear,
|
||||
pre=pre,
|
||||
)
|
||||
# Add develop dependencies to lockfile.
|
||||
for dep in results:
|
||||
@@ -1114,9 +1180,16 @@ def do_lock(
|
||||
err=True,
|
||||
)
|
||||
# Resolve package dependencies, with pip-tools.
|
||||
deps = convert_deps_to_pip(project.packages, project, r=False, include_index=True)
|
||||
deps = convert_deps_to_pip(
|
||||
project.packages, project, r=False, include_index=True
|
||||
)
|
||||
results = venv_resolve_deps(
|
||||
deps, which=which, verbose=verbose, project=project, clear=clear, pre=pre
|
||||
deps,
|
||||
which=which,
|
||||
verbose=verbose,
|
||||
project=project,
|
||||
clear=clear,
|
||||
pre=pre,
|
||||
)
|
||||
# Add default dependencies to lockfile.
|
||||
for dep in results:
|
||||
@@ -1155,13 +1228,17 @@ def do_lock(
|
||||
for package_specified in section:
|
||||
norm_name = pep423_name(package_specified)
|
||||
if not is_pinned(section[package_specified]):
|
||||
lockfile[section_name][norm_name] = cached_lockfile[section_name][
|
||||
lockfile[section_name][norm_name] = cached_lockfile[
|
||||
section_name
|
||||
][
|
||||
norm_name
|
||||
]
|
||||
# Overwrite any develop packages with default packages.
|
||||
for default_package in lockfile['default']:
|
||||
if default_package in lockfile['develop']:
|
||||
lockfile['develop'][default_package] = lockfile['default'][default_package]
|
||||
lockfile['develop'][default_package] = lockfile['default'][
|
||||
default_package
|
||||
]
|
||||
if write:
|
||||
# Write out the lockfile.
|
||||
with open(project.lockfile_location, 'w') as f:
|
||||
@@ -1226,7 +1303,9 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False):
|
||||
"""Executes the purge functionality."""
|
||||
if downloads:
|
||||
if not bare:
|
||||
click.echo(crayons.normal(u'Clearing out downloads directory…', bold=True))
|
||||
click.echo(
|
||||
crayons.normal(u'Clearing out downloads directory…', bold=True)
|
||||
)
|
||||
shutil.rmtree(project.download_location)
|
||||
return
|
||||
|
||||
@@ -1237,7 +1316,9 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False):
|
||||
).out
|
||||
# Remove comments from the output, if any.
|
||||
installed = [
|
||||
line for line in freeze.splitlines() if not line.lstrip().startswith('#')
|
||||
line
|
||||
for line in freeze.splitlines()
|
||||
if not line.lstrip().startswith('#')
|
||||
]
|
||||
# Remove setuptools and friends from installed, if present.
|
||||
for package_name in BAD_PACKAGES:
|
||||
@@ -1257,7 +1338,9 @@ def do_purge(bare=False, downloads=False, allow_global=False, verbose=False):
|
||||
actually_installed.append(dep)
|
||||
if not bare:
|
||||
click.echo(
|
||||
u'Found {0} installed package(s), purging…'.format(len(actually_installed))
|
||||
u'Found {0} installed package(s), purging…'.format(
|
||||
len(actually_installed)
|
||||
)
|
||||
)
|
||||
command = '{0} uninstall {1} -y'.format(
|
||||
escape_grouped_arguments(which_pip(allow_global=allow_global)),
|
||||
@@ -1296,7 +1379,9 @@ def do_init(
|
||||
# Ensure the Pipfile exists.
|
||||
ensure_pipfile()
|
||||
if not requirements_dir:
|
||||
requirements_dir = TemporaryDirectory(suffix='-requirements', prefix='pipenv-')
|
||||
requirements_dir = TemporaryDirectory(
|
||||
suffix='-requirements', prefix='pipenv-'
|
||||
)
|
||||
# Write out the lockfile if it doesn't exist, but not if the Pipfile is being ignored
|
||||
if (project.lockfile_exists and not ignore_pipfile) and not skip_lock:
|
||||
# Open the lockfile.
|
||||
@@ -1316,7 +1401,9 @@ def do_init(
|
||||
)
|
||||
)
|
||||
)
|
||||
click.echo(crayons.normal('Aborting deploy.', bold=True), err=True)
|
||||
click.echo(
|
||||
crayons.normal('Aborting deploy.', bold=True), err=True
|
||||
)
|
||||
requirements_dir.cleanup()
|
||||
sys.exit(1)
|
||||
else:
|
||||
@@ -1333,9 +1420,15 @@ def do_init(
|
||||
# Write out the lockfile if it doesn't exist.
|
||||
if not project.lockfile_exists and not skip_lock:
|
||||
click.echo(
|
||||
crayons.normal(u'Pipfile.lock not found, creating…', bold=True), err=True
|
||||
crayons.normal(u'Pipfile.lock not found, creating…', bold=True),
|
||||
err=True,
|
||||
)
|
||||
do_lock(
|
||||
system=system,
|
||||
pre=pre,
|
||||
keep_outdated=keep_outdated,
|
||||
verbose=verbose,
|
||||
)
|
||||
do_lock(system=system, pre=pre, keep_outdated=keep_outdated, verbose=verbose)
|
||||
do_install_dependencies(
|
||||
dev=dev,
|
||||
requirements=requirements,
|
||||
@@ -1368,11 +1461,14 @@ def pip_install(
|
||||
|
||||
if verbose:
|
||||
click.echo(
|
||||
crayons.normal('Installing {0!r}'.format(package_name), bold=True), err=True
|
||||
crayons.normal('Installing {0!r}'.format(package_name), bold=True),
|
||||
err=True,
|
||||
)
|
||||
pip9.logger.setLevel(logging.INFO)
|
||||
# Create files for hash mode.
|
||||
if not package_name.startswith('-e ') and (not ignore_hashes) and (r is None):
|
||||
if not package_name.startswith('-e ') and (not ignore_hashes) and (
|
||||
r is None
|
||||
):
|
||||
fd, r = tempfile.mkstemp(
|
||||
prefix='pipenv-', suffix='-requirement.txt', dir=requirements_dir
|
||||
)
|
||||
@@ -1515,18 +1611,23 @@ def format_help(help):
|
||||
"""Formats the help string."""
|
||||
help = help.replace('Options:', str(crayons.normal('Options:', bold=True)))
|
||||
help = help.replace(
|
||||
'Usage: pipenv', str('Usage: {0}'.format(crayons.normal('pipenv', bold=True)))
|
||||
'Usage: pipenv',
|
||||
str('Usage: {0}'.format(crayons.normal('pipenv', bold=True))),
|
||||
)
|
||||
help = help.replace(' check', str(crayons.red(' check', bold=True)))
|
||||
help = help.replace(' clean', str(crayons.red(' clean', bold=True)))
|
||||
help = help.replace(' graph', str(crayons.red(' graph', bold=True)))
|
||||
help = help.replace(' install', str(crayons.magenta(' install', bold=True)))
|
||||
help = help.replace(
|
||||
' install', str(crayons.magenta(' install', bold=True))
|
||||
)
|
||||
help = help.replace(' lock', str(crayons.green(' lock', bold=True)))
|
||||
help = help.replace(' open', str(crayons.red(' open', bold=True)))
|
||||
help = help.replace(' run', str(crayons.yellow(' run', bold=True)))
|
||||
help = help.replace(' shell', str(crayons.yellow(' shell', bold=True)))
|
||||
help = help.replace(' sync', str(crayons.green(' sync', bold=True)))
|
||||
help = help.replace(' uninstall', str(crayons.magenta(' uninstall', bold=True)))
|
||||
help = help.replace(
|
||||
' uninstall', str(crayons.magenta(' uninstall', bold=True))
|
||||
)
|
||||
help = help.replace(' update', str(crayons.green(' update', bold=True)))
|
||||
additional_help = """
|
||||
Usage Examples:
|
||||
@@ -1567,13 +1668,16 @@ Commands:""".format(
|
||||
|
||||
|
||||
def format_pip_error(error):
|
||||
error = error.replace('Expected', str(crayons.green('Expected', bold=True)))
|
||||
error = error.replace(
|
||||
'Expected', str(crayons.green('Expected', bold=True))
|
||||
)
|
||||
error = error.replace('Got', str(crayons.red('Got', bold=True)))
|
||||
error = error.replace(
|
||||
'THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE',
|
||||
str(
|
||||
crayons.red(
|
||||
'THESE PACKAGES DO NOT MATCH THE HASHES FROM Pipfile.lock!', bold=True
|
||||
'THESE PACKAGES DO NOT MATCH THE HASHES FROM Pipfile.lock!',
|
||||
bold=True,
|
||||
)
|
||||
),
|
||||
)
|
||||
@@ -1581,7 +1685,9 @@ def format_pip_error(error):
|
||||
'someone may have tampered with them',
|
||||
str(crayons.red('someone may have tampered with them')),
|
||||
)
|
||||
error = error.replace('option to pip install', 'option to \'pipenv install\'')
|
||||
error = error.replace(
|
||||
'option to pip install', 'option to \'pipenv install\''
|
||||
)
|
||||
return error
|
||||
|
||||
|
||||
@@ -1659,7 +1765,10 @@ def do_py(system=False):
|
||||
|
||||
def do_outdated():
|
||||
packages = {}
|
||||
results = delegator.run('{0} freeze'.format(which('pip'))).out.strip().split('\n')
|
||||
results = delegator.run('{0} freeze'.format(which('pip'))).out.strip(
|
||||
).split(
|
||||
'\n'
|
||||
)
|
||||
results = filter(bool, results)
|
||||
for result in results:
|
||||
packages.update(convert_deps_from_pip(result))
|
||||
@@ -1668,14 +1777,18 @@ def do_outdated():
|
||||
for section in ('develop', 'default'):
|
||||
for package in lockfile[section]:
|
||||
try:
|
||||
updated_packages[package] = lockfile[section][package]['version']
|
||||
updated_packages[package] = lockfile[section][package][
|
||||
'version'
|
||||
]
|
||||
except KeyError:
|
||||
pass
|
||||
outdated = []
|
||||
for package in packages:
|
||||
if package in updated_packages:
|
||||
if updated_packages[package] != packages[package]:
|
||||
outdated.append((package, updated_packages[package], packages[package]))
|
||||
outdated.append(
|
||||
(package, updated_packages[package], packages[package])
|
||||
)
|
||||
for package, new_version, old_version in outdated:
|
||||
click.echo(
|
||||
'Package {0!r} out–of–date: {1!r} installed, {2!r} available.'.format(
|
||||
@@ -1748,7 +1861,9 @@ def do_install(
|
||||
# Check if the file is remote or not
|
||||
if remote:
|
||||
fd, temp_reqs = tempfile.mkstemp(
|
||||
prefix='pipenv-', suffix='-requirement.txt', dir=requirements_directory.name
|
||||
prefix='pipenv-',
|
||||
suffix='-requirement.txt',
|
||||
dir=requirements_directory.name,
|
||||
)
|
||||
requirements_url = requirements
|
||||
# Download requirements file
|
||||
@@ -1778,7 +1893,8 @@ def do_install(
|
||||
error, traceback = None, None
|
||||
click.echo(
|
||||
crayons.normal(
|
||||
u'Requirements file provided! Importing into Pipfile…', bold=True
|
||||
u'Requirements file provided! Importing into Pipfile…',
|
||||
bold=True,
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
@@ -1786,7 +1902,9 @@ def do_install(
|
||||
import_requirements(r=project.path_to(requirements), dev=dev)
|
||||
except (UnicodeDecodeError, pip9.exceptions.PipError) as e:
|
||||
# Don't print the temp file path if remote since it will be deleted.
|
||||
req_path = requirements_url if remote else project.path_to(requirements)
|
||||
req_path = requirements_url if remote else project.path_to(
|
||||
requirements
|
||||
)
|
||||
error = (
|
||||
u'Unexpected syntax in {0}. Are you sure this is a '
|
||||
'requirements.txt style file?'.format(req_path)
|
||||
@@ -1810,7 +1928,9 @@ def do_install(
|
||||
sys.exit(1)
|
||||
if code:
|
||||
click.echo(
|
||||
crayons.normal(u'Discovering imports from local codebase…', bold=True)
|
||||
crayons.normal(
|
||||
u'Discovering imports from local codebase…', bold=True
|
||||
)
|
||||
)
|
||||
for req in import_from_code(code):
|
||||
click.echo(' Found {0}!'.format(crayons.green(req)))
|
||||
@@ -1851,7 +1971,9 @@ def do_install(
|
||||
package__name = list(package.keys())[0]
|
||||
package__val = list(package.values())[0]
|
||||
try:
|
||||
if not is_star(section[package__name]) and is_star(package__val):
|
||||
if not is_star(section[package__name]) and is_star(
|
||||
package__val
|
||||
):
|
||||
# Support for VCS dependencies.
|
||||
package_names[i] = convert_deps_to_pip(
|
||||
{package_name: section[package__name]}, r=False
|
||||
@@ -1863,7 +1985,9 @@ def do_install(
|
||||
for package_name in package_names:
|
||||
click.echo(
|
||||
crayons.normal(
|
||||
u'Installing {0}…'.format(crayons.green(package_name, bold=True)),
|
||||
u'Installing {0}…'.format(
|
||||
crayons.green(package_name, bold=True)
|
||||
),
|
||||
bold=True,
|
||||
)
|
||||
)
|
||||
@@ -1887,7 +2011,9 @@ def do_install(
|
||||
requirements_directory.cleanup()
|
||||
sys.exit(1)
|
||||
key = [k for k in converted.keys()][0]
|
||||
if is_vcs(key) or is_vcs(converted[key]) and not converted[key].get(
|
||||
if is_vcs(key) or is_vcs(converted[key]) and not converted[
|
||||
key
|
||||
].get(
|
||||
'editable'
|
||||
):
|
||||
click.echo(
|
||||
@@ -1895,7 +2021,8 @@ def do_install(
|
||||
'This will work fine, but sub-dependencies will not be resolved by {1}.'
|
||||
'\n To enable this sub–dependency functionality, specify that this dependency is editable.'
|
||||
''.format(
|
||||
crayons.red('Warning', bold=True), crayons.red('$ pipenv lock')
|
||||
crayons.red('Warning', bold=True),
|
||||
crayons.red('$ pipenv lock'),
|
||||
)
|
||||
)
|
||||
click.echo(crayons.blue(format_pip_output(c.out)))
|
||||
@@ -1905,7 +2032,8 @@ def do_install(
|
||||
except AssertionError:
|
||||
click.echo(
|
||||
'{0} An error occurred while installing {1}!'.format(
|
||||
crayons.red('Error: ', bold=True), crayons.green(package_name)
|
||||
crayons.red('Error: ', bold=True),
|
||||
crayons.green(package_name),
|
||||
),
|
||||
err=True,
|
||||
)
|
||||
@@ -1917,7 +2045,9 @@ def do_install(
|
||||
crayons.normal('Adding', bold=True),
|
||||
crayons.green(package_name, bold=True),
|
||||
crayons.normal("to Pipfile's", bold=True),
|
||||
crayons.red('[dev-packages]' if dev else '[packages]', bold=True),
|
||||
crayons.red(
|
||||
'[dev-packages]' if dev else '[packages]', bold=True
|
||||
),
|
||||
crayons.normal('…', bold=True),
|
||||
)
|
||||
)
|
||||
@@ -1926,7 +2056,9 @@ def do_install(
|
||||
project.add_package_to_pipfile(package_name, dev)
|
||||
except ValueError as e:
|
||||
click.echo(
|
||||
'{0} {1}'.format(crayons.red('ERROR (PACKAGE NOT INSTALLED):'), e)
|
||||
'{0} {1}'.format(
|
||||
crayons.red('ERROR (PACKAGE NOT INSTALLED):'), e
|
||||
)
|
||||
)
|
||||
# Update project settings with pre preference.
|
||||
if pre:
|
||||
@@ -1967,7 +2099,9 @@ def do_uninstall(
|
||||
# Un-install all dependencies, if --all was provided.
|
||||
if all is True:
|
||||
click.echo(
|
||||
crayons.normal(u'Un-installing all packages from virtualenv…', bold=True)
|
||||
crayons.normal(
|
||||
u'Un-installing all packages from virtualenv…', bold=True
|
||||
)
|
||||
)
|
||||
do_purge(allow_global=system, verbose=verbose)
|
||||
sys.exit(0)
|
||||
@@ -1976,14 +2110,17 @@ def do_uninstall(
|
||||
if 'dev-packages' not in project.parsed_pipfile:
|
||||
click.echo(
|
||||
crayons.normal(
|
||||
'No {0} to uninstall.'.format(crayons.red('[dev-packages]')),
|
||||
'No {0} to uninstall.'.format(
|
||||
crayons.red('[dev-packages]')
|
||||
),
|
||||
bold=True,
|
||||
)
|
||||
)
|
||||
sys.exit(0)
|
||||
click.echo(
|
||||
crayons.normal(
|
||||
u'Un-installing {0}…'.format(crayons.red('[dev-packages]')), bold=True
|
||||
u'Un-installing {0}…'.format(crayons.red('[dev-packages]')),
|
||||
bold=True,
|
||||
)
|
||||
)
|
||||
package_names = project.parsed_pipfile['dev-packages']
|
||||
@@ -2002,7 +2139,9 @@ def do_uninstall(
|
||||
click.echo(crayons.blue(c.out))
|
||||
if pipfile_remove:
|
||||
norm_name = pep423_name(package_name)
|
||||
in_dev_packages = (norm_name in project._pipfile.get('dev-packages', {}))
|
||||
in_dev_packages = (
|
||||
norm_name in project._pipfile.get('dev-packages', {})
|
||||
)
|
||||
in_packages = (norm_name in project._pipfile.get('packages', {}))
|
||||
if not in_dev_packages and not in_packages:
|
||||
click.echo(
|
||||
@@ -2013,7 +2152,9 @@ def do_uninstall(
|
||||
continue
|
||||
|
||||
click.echo(
|
||||
u'Removing {0} from Pipfile…'.format(crayons.green(package_name))
|
||||
u'Removing {0} from Pipfile…'.format(
|
||||
crayons.green(package_name)
|
||||
)
|
||||
)
|
||||
# Remove package from both packages and dev-packages.
|
||||
project.remove_package_from_pipfile(package_name, dev=True)
|
||||
@@ -2078,7 +2219,9 @@ def do_shell(three=None, python=False, fancy=False, shell_args=None):
|
||||
c = pexpect.spawn(
|
||||
cmd,
|
||||
args,
|
||||
dimensions=(terminal_dimensions.lines, terminal_dimensions.columns),
|
||||
dimensions=(
|
||||
terminal_dimensions.lines, terminal_dimensions.columns
|
||||
),
|
||||
)
|
||||
# Windows!
|
||||
except AttributeError:
|
||||
@@ -2202,7 +2345,8 @@ def do_check(three=None, python=False, system=False, unused=False, args=None):
|
||||
# Run the PEP 508 checker in the virtualenv.
|
||||
c = delegator.run(
|
||||
'"{0}" {1}'.format(
|
||||
python, escape_grouped_arguments(pep508checker.__file__.rstrip('cdo'))
|
||||
python,
|
||||
escape_grouped_arguments(pep508checker.__file__.rstrip('cdo')),
|
||||
)
|
||||
)
|
||||
results = simplejson.loads(c.out)
|
||||
@@ -2230,7 +2374,9 @@ def do_check(three=None, python=False, system=False, unused=False, args=None):
|
||||
sys.exit(1)
|
||||
else:
|
||||
click.echo(crayons.green('Passed!'))
|
||||
click.echo(crayons.normal(u'Checking installed package safety…', bold=True))
|
||||
click.echo(
|
||||
crayons.normal(u'Checking installed package safety…', bold=True)
|
||||
)
|
||||
path = pep508checker.__file__.rstrip('cdo')
|
||||
path = os.sep.join(__file__.split(os.sep)[:-1] + ['patched', 'safety.zip'])
|
||||
if not system:
|
||||
@@ -2306,7 +2452,9 @@ def do_graph(bare=False, json=False, reverse=False):
|
||||
)
|
||||
sys.exit(1)
|
||||
cmd = '"{0}" {1} {2}'.format(
|
||||
python_path, escape_grouped_arguments(pipdeptree.__file__.rstrip('cdo')), flag
|
||||
python_path,
|
||||
escape_grouped_arguments(pipdeptree.__file__.rstrip('cdo')),
|
||||
flag,
|
||||
)
|
||||
# Run dep-tree.
|
||||
c = delegator.run(cmd)
|
||||
@@ -2351,7 +2499,9 @@ def do_sync(
|
||||
unused=False,
|
||||
sequential=False,
|
||||
):
|
||||
requirements_dir = TemporaryDirectory(suffix='-requirements', prefix='pipenv-')
|
||||
requirements_dir = TemporaryDirectory(
|
||||
suffix='-requirements', prefix='pipenv-'
|
||||
)
|
||||
# Ensure that virtualenv is available.
|
||||
ensure_project(three=three, python=python, validate=False)
|
||||
concurrent = (not sequential)
|
||||
@@ -2367,11 +2517,15 @@ def do_sync(
|
||||
click.echo(crayons.green('All dependencies are now up-to-date!'))
|
||||
|
||||
|
||||
def do_clean(ctx, three=None, python=None, dry_run=False, bare=False, verbose=False):
|
||||
def do_clean(
|
||||
ctx, three=None, python=None, dry_run=False, bare=False, verbose=False
|
||||
):
|
||||
# Ensure that virtualenv is available.
|
||||
ensure_project(three=three, python=python, validate=False)
|
||||
ensure_lockfile()
|
||||
installed_packages = delegator.run('{0} freeze'.format(which('pip'))).out.strip(
|
||||
installed_packages = delegator.run(
|
||||
'{0} freeze'.format(which('pip'))
|
||||
).out.strip(
|
||||
).split(
|
||||
'\n'
|
||||
)
|
||||
@@ -2389,13 +2543,17 @@ def do_clean(ctx, three=None, python=None, dry_run=False, bare=False, verbose=Fa
|
||||
if bad_package in installed_package_names:
|
||||
if verbose:
|
||||
click.echo('Ignoring {0}.'.format(repr(bad_package)), err=True)
|
||||
del installed_package_names[installed_package_names.index(bad_package)]
|
||||
del installed_package_names[
|
||||
installed_package_names.index(bad_package)
|
||||
]
|
||||
# Intelligently detect if --dev should be used or not.
|
||||
develop = [k.lower() for k in project.lockfile_content['develop'].keys()]
|
||||
default = [k.lower() for k in project.lockfile_content['default'].keys()]
|
||||
for used_package in set(develop + default):
|
||||
if used_package in installed_package_names:
|
||||
del installed_package_names[installed_package_names.index(used_package)]
|
||||
del installed_package_names[
|
||||
installed_package_names.index(used_package)
|
||||
]
|
||||
failure = False
|
||||
for apparent_bad_package in installed_package_names:
|
||||
if dry_run:
|
||||
@@ -2403,12 +2561,15 @@ def do_clean(ctx, three=None, python=None, dry_run=False, bare=False, verbose=Fa
|
||||
else:
|
||||
click.echo(
|
||||
crayons.white(
|
||||
'Uninstalling {0}…'.format(repr(apparent_bad_package)), bold=True
|
||||
'Uninstalling {0}…'.format(repr(apparent_bad_package)),
|
||||
bold=True,
|
||||
)
|
||||
)
|
||||
# Uninstall the package.
|
||||
c = delegator.run(
|
||||
'{0} uninstall {1} -y'.format(which('pip'), apparent_bad_package)
|
||||
'{0} uninstall {1} -y'.format(
|
||||
which('pip'), apparent_bad_package
|
||||
)
|
||||
)
|
||||
if c.return_code != 0:
|
||||
failure = True
|
||||
|
||||
+8
-2
@@ -61,7 +61,9 @@ def main():
|
||||
print('---------------------------')
|
||||
print('')
|
||||
if project.pipfile_exists:
|
||||
print(u'Contents of `Pipfile` ({0!r}):'.format(project.pipfile_location))
|
||||
print(
|
||||
u'Contents of `Pipfile` ({0!r}):'.format(project.pipfile_location)
|
||||
)
|
||||
print('')
|
||||
print('```toml')
|
||||
with open(project.pipfile_location, 'r') as f:
|
||||
@@ -70,7 +72,11 @@ def main():
|
||||
print('')
|
||||
if project.lockfile_exists:
|
||||
print('')
|
||||
print(u'Contents of `Pipfile.lock` ({0!r}):'.format(project.lockfile_location))
|
||||
print(
|
||||
u'Contents of `Pipfile.lock` ({0!r}):'.format(
|
||||
project.lockfile_location
|
||||
)
|
||||
)
|
||||
print('')
|
||||
print('```json')
|
||||
with open(project.lockfile_location, 'r') as f:
|
||||
|
||||
+5
-2
@@ -194,9 +194,12 @@ def mill(it, label='', hide=None, expected_size=None, every=1):
|
||||
def _show(_i):
|
||||
if not hide:
|
||||
if (
|
||||
(_i % every) == 0 or (_i == count) # True every "every" updates
|
||||
(_i % every) == 0 or
|
||||
(_i == count) # True every "every" updates
|
||||
): # And when we're done
|
||||
STREAM.write(MILL_TEMPLATE % (label, _mill_char(_i), _i, count))
|
||||
STREAM.write(
|
||||
MILL_TEMPLATE % (label, _mill_char(_i), _i, count)
|
||||
)
|
||||
STREAM.flush()
|
||||
|
||||
count = len(it) if expected_size is None else expected_size
|
||||
|
||||
+43
-13
@@ -92,7 +92,10 @@ class Project(object):
|
||||
any(
|
||||
(
|
||||
prefix in v and
|
||||
(os.path.isfile(v[prefix]) or is_valid_url(v[prefix]))
|
||||
(
|
||||
os.path.isfile(v[prefix]) or
|
||||
is_valid_url(v[prefix])
|
||||
)
|
||||
)
|
||||
for prefix in ['path', 'file']
|
||||
)
|
||||
@@ -138,14 +141,18 @@ class Project(object):
|
||||
'python_full_version'
|
||||
)
|
||||
if not required:
|
||||
required = self.parsed_pipfile.get('requires', {}).get('python_version')
|
||||
required = self.parsed_pipfile.get('requires', {}).get(
|
||||
'python_version'
|
||||
)
|
||||
if required != "*":
|
||||
return required
|
||||
|
||||
@property
|
||||
def project_directory(self):
|
||||
if self.pipfile_location is not None:
|
||||
return os.path.abspath(os.path.join(self.pipfile_location, os.pardir))
|
||||
return os.path.abspath(
|
||||
os.path.join(self.pipfile_location, os.pardir)
|
||||
)
|
||||
|
||||
else:
|
||||
return None
|
||||
@@ -162,7 +169,9 @@ class Project(object):
|
||||
extra = ['Scripts', 'activate.bat']
|
||||
else:
|
||||
extra = ['bin', 'activate']
|
||||
return os.path.isfile(os.sep.join([self.virtualenv_location] + extra))
|
||||
return os.path.isfile(
|
||||
os.sep.join([self.virtualenv_location] + extra)
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
@@ -206,13 +215,16 @@ class Project(object):
|
||||
if not PIPENV_VENV_IN_PROJECT:
|
||||
c = delegator.run(
|
||||
'{0} -m pipenv.pew dir "{1}"'.format(
|
||||
escape_grouped_arguments(sys.executable), self.virtualenv_name
|
||||
escape_grouped_arguments(sys.executable),
|
||||
self.virtualenv_name,
|
||||
)
|
||||
)
|
||||
loc = c.out.strip()
|
||||
# Default mode.
|
||||
else:
|
||||
loc = os.sep.join(self.pipfile_location.split(os.sep)[:-1] + ['.venv'])
|
||||
loc = os.sep.join(
|
||||
self.pipfile_location.split(os.sep)[:-1] + ['.venv']
|
||||
)
|
||||
self._virtualenv_location = loc
|
||||
return loc
|
||||
|
||||
@@ -234,7 +246,9 @@ class Project(object):
|
||||
@property
|
||||
def proper_names_location(self):
|
||||
if self._proper_names_location is None:
|
||||
loc = os.sep.join([self.virtualenv_location, 'pipenv-proper-names.txt'])
|
||||
loc = os.sep.join(
|
||||
[self.virtualenv_location, 'pipenv-proper-names.txt']
|
||||
)
|
||||
self._proper_names_location = loc
|
||||
# Create the database, if it doesn't exist.
|
||||
open(self._proper_names_location, 'a').close()
|
||||
@@ -287,7 +301,9 @@ class Project(object):
|
||||
# Convert things to inline tables — fancy :)
|
||||
if hasattr(data[section][package], 'keys'):
|
||||
_data = data[section][package]
|
||||
data[section][package] = toml._get_empty_inline_table(dict)
|
||||
data[section][package] = toml._get_empty_inline_table(
|
||||
dict
|
||||
)
|
||||
data[section][package].update(_data)
|
||||
# We lose comments here, but it's for the best.)
|
||||
try:
|
||||
@@ -424,7 +440,11 @@ class Project(object):
|
||||
indexes = install.get('extra-index-url', '').lstrip('\n').split('\n')
|
||||
if PIPENV_TEST_INDEX:
|
||||
sources = [
|
||||
{u'url': PIPENV_TEST_INDEX, u'verify_ssl': True, u'name': u'custom'}
|
||||
{
|
||||
u'url': PIPENV_TEST_INDEX,
|
||||
u'verify_ssl': True,
|
||||
u'name': u'custom',
|
||||
}
|
||||
]
|
||||
else:
|
||||
# Default source.
|
||||
@@ -441,7 +461,11 @@ class Project(object):
|
||||
source_name = 'pip_index_{}'.format(i)
|
||||
verify_ssl = index.startswith('https')
|
||||
sources.append(
|
||||
{u'url': index, u'verify_ssl': verify_ssl, u'name': source_name}
|
||||
{
|
||||
u'url': index,
|
||||
u'verify_ssl': verify_ssl,
|
||||
u'name': source_name,
|
||||
}
|
||||
)
|
||||
data = {
|
||||
u'source': sources,
|
||||
@@ -450,7 +474,9 @@ class Project(object):
|
||||
u'dev-packages': {},
|
||||
}
|
||||
# Default requires.
|
||||
required_python = python or self.which('python', self.virtualenv_location)
|
||||
required_python = python or self.which(
|
||||
'python', self.virtualenv_location
|
||||
)
|
||||
data[u'requires'] = {
|
||||
'python_version': python_version(required_python)[: len('2.7')]
|
||||
}
|
||||
@@ -468,7 +494,9 @@ class Project(object):
|
||||
# Convert things to inline tables — fancy :)
|
||||
if hasattr(data[section][package], 'keys'):
|
||||
_data = data[section][package]
|
||||
data[section][package] = toml._get_empty_inline_table(dict)
|
||||
data[section][package] = toml._get_empty_inline_table(
|
||||
dict
|
||||
)
|
||||
data[section][package].update(_data)
|
||||
formatted_data = toml.dumps(data).rstrip()
|
||||
formatted_data = cleanup_toml(formatted_data)
|
||||
@@ -529,7 +557,9 @@ class Project(object):
|
||||
# Don't re-capitalize file URLs or VCSs.
|
||||
converted = convert_deps_from_pip(package_name)
|
||||
converted = converted[[k for k in converted.keys()][0]]
|
||||
if not (is_file(package_name) or is_vcs(converted) or 'path' in converted):
|
||||
if not (
|
||||
is_file(package_name) or is_vcs(converted) or 'path' in converted
|
||||
):
|
||||
package_name = pep423_name(package_name)
|
||||
key = 'dev-packages' if dev else 'packages'
|
||||
# Set empty group if it doesn't exist yet.
|
||||
|
||||
+70
-23
@@ -146,7 +146,9 @@ def get_requirement(dep):
|
||||
req.markers = markers
|
||||
if extras:
|
||||
# Bizarrely this is also what pip does...
|
||||
req.extras = [r for r in requirements.parse('fakepkg{0}'.format(extras))][
|
||||
req.extras = [
|
||||
r for r in requirements.parse('fakepkg{0}'.format(extras))
|
||||
][
|
||||
0
|
||||
].extras
|
||||
return req
|
||||
@@ -249,7 +251,10 @@ def prepare_pip_source_args(sources, pip_args=None):
|
||||
# Trust the host if it's not verified.
|
||||
if not sources[0].get('verify_ssl', True):
|
||||
pip_args.extend(
|
||||
['--trusted-host', urlparse(sources[0]['url']).netloc.split(':')[0]]
|
||||
[
|
||||
'--trusted-host',
|
||||
urlparse(sources[0]['url']).netloc.split(':')[0],
|
||||
]
|
||||
)
|
||||
# Add additional sources as extra indexes.
|
||||
if len(sources) > 1:
|
||||
@@ -258,7 +263,10 @@ def prepare_pip_source_args(sources, pip_args=None):
|
||||
# Trust the host if it's not verified.
|
||||
if not source.get('verify_ssl', True):
|
||||
pip_args.extend(
|
||||
['--trusted-host', urlparse(source['url']).netloc.split(':')[0]]
|
||||
[
|
||||
'--trusted-host',
|
||||
urlparse(source['url']).netloc.split(':')[0],
|
||||
]
|
||||
)
|
||||
return pip_args
|
||||
|
||||
@@ -278,7 +286,9 @@ def actually_resolve_reps(
|
||||
for dep in deps:
|
||||
if dep:
|
||||
if dep.startswith('-e '):
|
||||
constraint = req.InstallRequirement.from_editable(dep[len('-e '):])
|
||||
constraint = req.InstallRequirement.from_editable(
|
||||
dep[len('-e '):]
|
||||
)
|
||||
else:
|
||||
fd, t = tempfile.mkstemp(
|
||||
prefix='pipenv-', suffix='-requirement.txt', dir=req_dir
|
||||
@@ -298,7 +308,9 @@ def actually_resolve_reps(
|
||||
'name'
|
||||
)
|
||||
if constraint.markers:
|
||||
markers_lookup[constraint.name] = str(constraint.markers).replace(
|
||||
markers_lookup[constraint.name] = str(
|
||||
constraint.markers
|
||||
).replace(
|
||||
'"', "'"
|
||||
)
|
||||
constraints.append(constraint)
|
||||
@@ -311,13 +323,18 @@ def actually_resolve_reps(
|
||||
print('Using pip: {0}'.format(' '.join(pip_args)))
|
||||
pip_options, _ = pip_command.parse_args(pip_args)
|
||||
session = pip_command._build_session(pip_options)
|
||||
pypi = PyPIRepository(pip_options=pip_options, use_json=False, session=session)
|
||||
pypi = PyPIRepository(
|
||||
pip_options=pip_options, use_json=False, session=session
|
||||
)
|
||||
if verbose:
|
||||
logging.log.verbose = True
|
||||
piptools_logging.log.verbose = True
|
||||
resolved_tree = set()
|
||||
resolver = Resolver(
|
||||
constraints=constraints, repository=pypi, clear_caches=clear, prereleases=pre
|
||||
constraints=constraints,
|
||||
repository=pypi,
|
||||
clear_caches=clear,
|
||||
prereleases=pre,
|
||||
)
|
||||
# pre-resolve instead of iterating to avoid asking pypi for hashes of editable packages
|
||||
try:
|
||||
@@ -345,7 +362,9 @@ def actually_resolve_reps(
|
||||
return resolved_tree, resolver
|
||||
|
||||
|
||||
def venv_resolve_deps(deps, which, project, pre=False, verbose=False, clear=False):
|
||||
def venv_resolve_deps(
|
||||
deps, which, project, pre=False, verbose=False, clear=False
|
||||
):
|
||||
from .import resolver
|
||||
import json
|
||||
|
||||
@@ -439,7 +458,9 @@ def resolve_deps(
|
||||
version = clean_pkg_version(result.specifier)
|
||||
index = index_lookup.get(result.name)
|
||||
if not markers_lookup.get(result.name):
|
||||
markers = str(result.markers) if result.markers and 'extra' not in str(
|
||||
markers = str(
|
||||
result.markers
|
||||
) if result.markers and 'extra' not in str(
|
||||
result.markers
|
||||
) else None
|
||||
else:
|
||||
@@ -449,15 +470,20 @@ def resolve_deps(
|
||||
try:
|
||||
# Grab the hashes from the new warehouse API.
|
||||
r = requests.get(
|
||||
'https://pypi.org/pypi/{0}/json'.format(name), timeout=10
|
||||
'https://pypi.org/pypi/{0}/json'.format(name),
|
||||
timeout=10,
|
||||
)
|
||||
api_releases = r.json()['releases']
|
||||
cleaned_releases = {}
|
||||
for api_version, api_info in api_releases.items():
|
||||
cleaned_releases[clean_pkg_version(api_version)] = api_info
|
||||
cleaned_releases[
|
||||
clean_pkg_version(api_version)
|
||||
] = api_info
|
||||
for release in cleaned_releases[version]:
|
||||
collected_hashes.append(release['digests']['sha256'])
|
||||
collected_hashes = ['sha256:' + s for s in collected_hashes]
|
||||
collected_hashes = [
|
||||
'sha256:' + s for s in collected_hashes
|
||||
]
|
||||
except (ValueError, KeyError, ConnectionError) as e:
|
||||
if verbose:
|
||||
click.echo(
|
||||
@@ -592,7 +618,9 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
|
||||
# Support for multiple hashes (spec 2).
|
||||
if 'hashes' in deps[dep]:
|
||||
hash = '{0} '.format(
|
||||
''.join([' --hash={0} '.format(h) for h in deps[dep]['hashes']])
|
||||
''.join(
|
||||
[' --hash={0} '.format(h) for h in deps[dep]['hashes']]
|
||||
)
|
||||
)
|
||||
# Support for extras (e.g. requests[socks])
|
||||
if 'extras' in deps[dep]:
|
||||
@@ -609,7 +637,9 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
|
||||
for specifier in specifiers:
|
||||
if specifier in deps[dep]:
|
||||
if not is_star(deps[dep][specifier]):
|
||||
specs.append('{0} {1}'.format(specifier, deps[dep][specifier]))
|
||||
specs.append(
|
||||
'{0} {1}'.format(specifier, deps[dep][specifier])
|
||||
)
|
||||
if specs:
|
||||
specs = '; {0}'.format(' and '.join(specs))
|
||||
else:
|
||||
@@ -656,7 +686,9 @@ def convert_deps_to_pip(deps, project=None, r=True, include_index=False):
|
||||
dep = '-e '
|
||||
else:
|
||||
dep = ''
|
||||
s = '{0}{1}{2}{3}{4} {5}'.format(dep, extra, version, specs, hash, index).strip(
|
||||
s = '{0}{1}{2}{3}{4} {5}'.format(
|
||||
dep, extra, version, specs, hash, index
|
||||
).strip(
|
||||
)
|
||||
dependencies.append(s)
|
||||
if not r:
|
||||
@@ -731,7 +763,9 @@ def is_vcs(pipfile_entry):
|
||||
|
||||
elif isinstance(pipfile_entry, six.string_types):
|
||||
return bool(
|
||||
requirements.requirement.VCS_REGEX.match(clean_git_uri(pipfile_entry))
|
||||
requirements.requirement.VCS_REGEX.match(
|
||||
clean_git_uri(pipfile_entry)
|
||||
)
|
||||
)
|
||||
|
||||
return False
|
||||
@@ -811,11 +845,15 @@ def proper_case(package_name):
|
||||
"""Properly case project name from pypi.org."""
|
||||
# Hit the simple API.
|
||||
r = requests.get(
|
||||
'https://pypi.org/pypi/{0}/json'.format(package_name), timeout=0.3, stream=True
|
||||
'https://pypi.org/pypi/{0}/json'.format(package_name),
|
||||
timeout=0.3,
|
||||
stream=True,
|
||||
)
|
||||
if not r.ok:
|
||||
raise IOError(
|
||||
'Unable to find package {0} in PyPI repository.'.format(package_name)
|
||||
'Unable to find package {0} in PyPI repository.'.format(
|
||||
package_name
|
||||
)
|
||||
)
|
||||
|
||||
r = parse.parse('https://pypi.org/pypi/{name}/json', r.url)
|
||||
@@ -873,7 +911,8 @@ def split_section(input_file, section_suffix, test_function):
|
||||
def split_file(file_dict):
|
||||
"""Split VCS and editable dependencies out from file."""
|
||||
sections = {
|
||||
'vcs': is_vcs, 'editable': lambda x: hasattr(x, 'keys') and x.get('editable')
|
||||
'vcs': is_vcs,
|
||||
'editable': lambda x: hasattr(x, 'keys') and x.get('editable'),
|
||||
}
|
||||
for k, func in sections.items():
|
||||
file_dict = split_section(file_dict, k, func)
|
||||
@@ -968,9 +1007,13 @@ def find_windows_executable(bin_path, exe_name):
|
||||
|
||||
# Ensure we aren't adding two layers of file extensions
|
||||
exe_name = os.path.splitext(exe_name)[0]
|
||||
files = ['{0}.{1}'.format(exe_name, ext) for ext in ['', 'py', 'exe', 'bat']]
|
||||
files = [
|
||||
'{0}.{1}'.format(exe_name, ext) for ext in ['', 'py', 'exe', 'bat']
|
||||
]
|
||||
exec_paths = [get_windows_path(bin_path, f) for f in files]
|
||||
exec_files = [filename for filename in exec_paths if os.path.isfile(filename)]
|
||||
exec_files = [
|
||||
filename for filename in exec_paths if os.path.isfile(filename)
|
||||
]
|
||||
if exec_files:
|
||||
return exec_files[0]
|
||||
|
||||
@@ -1108,7 +1151,9 @@ def is_readonly_path(fn):
|
||||
Permissions check is `bool(path.stat & stat.S_IREAD)` or `not os.access(path, os.W_OK)`
|
||||
"""
|
||||
if os.path.exists(fn):
|
||||
return (os.stat(fn).st_mode & stat.S_IREAD) or not os.access(fn, os.W_OK)
|
||||
return (os.stat(fn).st_mode & stat.S_IREAD) or not os.access(
|
||||
fn, os.W_OK
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
@@ -1141,7 +1186,9 @@ def handle_remove_readonly(func, path, exc):
|
||||
func(path)
|
||||
except (OSError, IOError) as e:
|
||||
if e.errno in [errno.EACCES, errno.EPERM]:
|
||||
warnings.warn(default_warning_message.format(path), ResourceWarning)
|
||||
warnings.warn(
|
||||
default_warning_message.format(path), ResourceWarning
|
||||
)
|
||||
return
|
||||
|
||||
if exc_exception.errno in [errno.EACCES, errno.EPERM]:
|
||||
|
||||
Reference in New Issue
Block a user