mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
@@ -1 +1 @@
|
||||
__version__ = '3.1.9'
|
||||
__version__ = '3.1.9'
|
||||
|
||||
@@ -18,4 +18,4 @@ __author__ = "Kenneth Reitz and individual contributors"
|
||||
__email__ = "me@kennethreitz.org"
|
||||
|
||||
__license__ = "BSD or Apache License, Version 2.0"
|
||||
__copyright__ = "Copyright 2017 %s" % __author__
|
||||
__copyright__ = "Copyright 2017 %s" % __author__
|
||||
|
||||
@@ -8,4 +8,4 @@ from .__about__ import (
|
||||
__uri__, __version__
|
||||
)
|
||||
|
||||
from .api import load, Pipfile
|
||||
from .api import load, Pipfile
|
||||
|
||||
@@ -48,7 +48,6 @@ def walk_up(bottom):
|
||||
yield x
|
||||
|
||||
|
||||
|
||||
class PipfileParser(object):
|
||||
def __init__(self, filename='Pipfile'):
|
||||
self.filename = filename
|
||||
@@ -191,4 +190,4 @@ def load(pipfile_path=None):
|
||||
if pipfile_path is None:
|
||||
pipfile_path = Pipfile.find()
|
||||
|
||||
return Pipfile.load(filename=pipfile_path)
|
||||
return Pipfile.load(filename=pipfile_path)
|
||||
|
||||
+33
-20
@@ -7,18 +7,6 @@ import distutils.spawn
|
||||
import shutil
|
||||
import signal
|
||||
|
||||
try:
|
||||
from HTMLParser import HTMLParser
|
||||
except ImportError:
|
||||
from html.parser import HTMLParser
|
||||
|
||||
# Backport required for earlier versions of Python.
|
||||
if sys.version_info < (3, 3):
|
||||
from backports.shutil_get_terminal_size import get_terminal_size
|
||||
|
||||
else:
|
||||
from shutil import get_terminal_size
|
||||
|
||||
import click
|
||||
import crayons
|
||||
import delegator
|
||||
@@ -32,9 +20,22 @@ from .utils import convert_deps_from_pip, convert_deps_to_pip
|
||||
from .__version__ import __version__
|
||||
from . import pep508checker
|
||||
|
||||
try:
|
||||
from HTMLParser import HTMLParser
|
||||
except ImportError:
|
||||
from html.parser import HTMLParser
|
||||
|
||||
# Backport required for earlier versions of Python.
|
||||
if sys.version_info < (3, 3):
|
||||
from backports.shutil_get_terminal_size import get_terminal_size
|
||||
|
||||
else:
|
||||
from shutil import get_terminal_size
|
||||
|
||||
|
||||
project = Project()
|
||||
|
||||
|
||||
def ensure_latest_pip():
|
||||
"""Updates pip to the latest version."""
|
||||
|
||||
@@ -48,6 +49,7 @@ def ensure_latest_pip():
|
||||
c = delegator.run('{0} install pip --upgrade'.format(which_pip()), block=False)
|
||||
click.echo(crayons.blue(c.out))
|
||||
|
||||
|
||||
def ensure_pipfile():
|
||||
"""Creates a Pipfile for the project, if it doesn't exist."""
|
||||
|
||||
@@ -59,6 +61,7 @@ def ensure_pipfile():
|
||||
# Create the pipfile if it doesn't exist.
|
||||
project.create_pipfile()
|
||||
|
||||
|
||||
def ensure_virtualenv(three=None):
|
||||
"""Creates a virtualenv, if one doesn't exist."""
|
||||
|
||||
@@ -141,7 +144,6 @@ def do_install_dependencies(dev=False, only=False, bare=False, requirements=Fals
|
||||
click.echo(f.read())
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
# pip install:
|
||||
c = pip_install(r=deps_path, allow_global=allow_global)
|
||||
if not c.return_code == 0:
|
||||
@@ -206,6 +208,7 @@ def do_create_virtualenv(three=None):
|
||||
# Say where the virtualenv is.
|
||||
do_where(virtualenv=True, bare=False)
|
||||
|
||||
|
||||
def parse_download_fname(fname):
|
||||
|
||||
# Use Parse to attempt to parse filenames for metadata.
|
||||
@@ -227,6 +230,7 @@ def parse_download_fname(fname):
|
||||
|
||||
return name, version
|
||||
|
||||
|
||||
def get_downloads_info():
|
||||
info = []
|
||||
|
||||
@@ -243,6 +247,7 @@ def get_downloads_info():
|
||||
|
||||
return info
|
||||
|
||||
|
||||
def do_lock():
|
||||
"""Executes the freeze functionality."""
|
||||
|
||||
@@ -266,7 +271,6 @@ def do_lock():
|
||||
if dep:
|
||||
lockfile['develop'].update({dep['name']: {'hash': dep['hash'], 'version': '=={0}'.format(dep['version'])}})
|
||||
|
||||
|
||||
# Purge the virtualenv download dir, for default dependencies.
|
||||
do_purge(downloads=True, bare=True)
|
||||
|
||||
@@ -314,9 +318,11 @@ def activate_virtualenv(source=True):
|
||||
def do_activate_virtualenv(bare=False):
|
||||
"""Executes the activate virtualenv functionality."""
|
||||
# Check for environment marker, and skip if it's set.
|
||||
if not 'PIPENV_ACTIVE' in os.environ:
|
||||
if 'PIPENV_ACTIVE' not in os.environ:
|
||||
if not bare:
|
||||
click.echo('To activate this project\'s virtualenv, run the following:\n $ {0}'.format(crayons.red('pipenv shell')))
|
||||
click.echo('To activate this project\'s virtualenv, run the following:\n $ {0}'.format(
|
||||
crayons.red('pipenv shell'))
|
||||
)
|
||||
else:
|
||||
click.echo(activate_virtualenv())
|
||||
|
||||
@@ -381,6 +387,7 @@ def do_init(dev=False, requirements=False, skip_virtualenv=False, allow_global=F
|
||||
# Activate virtualenv instructions.
|
||||
do_activate_virtualenv()
|
||||
|
||||
|
||||
def pip_install(package_name=None, r=None, allow_global=False):
|
||||
if r:
|
||||
c = delegator.run('{0} install -r {1} --require-hashes -i {2}'.format(which_pip(allow_global=allow_global), r, project.source['url']))
|
||||
@@ -388,10 +395,12 @@ def pip_install(package_name=None, r=None, allow_global=False):
|
||||
c = delegator.run('{0} install "{1}" -i {2}'.format(which_pip(allow_global=allow_global), package_name, project.source['url']))
|
||||
return c
|
||||
|
||||
|
||||
def pip_download(package_name):
|
||||
c = delegator.run('{0} download "{1}" -d {2}'.format(which_pip(), package_name, project.download_location))
|
||||
return c
|
||||
|
||||
|
||||
def which(command):
|
||||
return os.sep.join([project.virtualenv_location] + ['bin/{0}'.format(command)])
|
||||
|
||||
@@ -403,6 +412,7 @@ def which_pip(allow_global=False):
|
||||
|
||||
return which('pip')
|
||||
|
||||
|
||||
def proper_case(package_name):
|
||||
|
||||
# Capture tag contents here.
|
||||
@@ -423,6 +433,7 @@ def proper_case(package_name):
|
||||
# Use the last link on the page, use it to get proper casing.
|
||||
return parse_download_fname(collected[-1])[0]
|
||||
|
||||
|
||||
def format_help(help):
|
||||
"""Formats the help string."""
|
||||
help = help.replace(' check', str(crayons.green(' check')))
|
||||
@@ -451,9 +462,9 @@ Commands:""".format(
|
||||
|
||||
help = help.replace('Commands:', additional_help)
|
||||
|
||||
|
||||
return help
|
||||
|
||||
|
||||
def format_pip_error(error):
|
||||
error = error.replace('Expected', str(crayons.green('Expected', bold=True)))
|
||||
error = error.replace('Got', str(crayons.red('Got', bold=True)))
|
||||
@@ -461,6 +472,7 @@ def format_pip_error(error):
|
||||
error = error.replace('someone may have tampered with them', str(crayons.red('someone may have tampered with them')))
|
||||
return error
|
||||
|
||||
|
||||
def format_pip_output(out, r=None):
|
||||
def gen(out):
|
||||
for line in out.split('\n'):
|
||||
@@ -473,10 +485,12 @@ def format_pip_output(out, r=None):
|
||||
out = '\n'.join([l for l in gen(out)])
|
||||
return out
|
||||
|
||||
|
||||
def easter_egg(package_name):
|
||||
if package_name in ['requests', 'maya', 'crayons', 'delegator.py' 'records', 'tablib']:
|
||||
click.echo('P.S. You have excellent taste! ✨🍰✨')
|
||||
|
||||
|
||||
@click.group(invoke_without_command=True)
|
||||
@click.option('--where', is_flag=True, default=False, help="Output project home information.")
|
||||
@click.option('--bare', is_flag=True, default=False, help="Minimal output.")
|
||||
@@ -501,11 +515,10 @@ def cli(ctx, where=False, bare=False, three=False, help=False):
|
||||
click.echo(format_help(ctx.get_help()))
|
||||
|
||||
|
||||
|
||||
@click.command(help="Installs provided packages and adds them to Pipfile, or (if none is given), installs all packages.")
|
||||
@click.argument('package_name', default=False)
|
||||
@click.argument('more_packages', nargs=-1)
|
||||
@click.option('--dev','-d', is_flag=True, default=False, help="Install package(s) in [dev-packages].")
|
||||
@click.option('--dev', '-d', is_flag=True, default=False, help="Install package(s) in [dev-packages].")
|
||||
@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.")
|
||||
@click.option('--system', is_flag=True, default=False, help="System pip management.")
|
||||
@click.option('--requirements', is_flag=True, default=False, help="Just generate a requirements.txt. Only works with bare install command.")
|
||||
@@ -700,7 +713,7 @@ def check():
|
||||
|
||||
|
||||
@click.command(help="Updates pip to latest version, uninstalls all packages, and re-installs them to latest compatible versions.")
|
||||
@click.option('--dev','-d', is_flag=True, default=False, help="Install package(s) in [dev-packages].")
|
||||
@click.option('--dev', '-d', is_flag=True, default=False, help="Install package(s) in [dev-packages].")
|
||||
@click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.")
|
||||
def update(dev=False, three=None):
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import os
|
||||
import platform
|
||||
import json
|
||||
|
||||
|
||||
def format_full_version(info):
|
||||
version = '{0.major}.{0.minor}.{0.micro}'.format(info)
|
||||
kind = info.releaselevel
|
||||
|
||||
+2
-5
@@ -6,6 +6,7 @@ from . import _pipfile as pipfile
|
||||
from .utils import format_toml, multi_split
|
||||
from .utils import convert_deps_from_pip, convert_deps_to_pip
|
||||
|
||||
|
||||
def mkdir_p(newdir):
|
||||
"""works the way a good mkdir should :)
|
||||
- already exists, silently complete
|
||||
@@ -16,13 +17,11 @@ def mkdir_p(newdir):
|
||||
if os.path.isdir(newdir):
|
||||
pass
|
||||
elif os.path.isfile(newdir):
|
||||
raise OSError("a file with the same name as the desired " \
|
||||
"dir, '%s', already exists." % newdir)
|
||||
raise OSError("a file with the same name as the desired dir, '%s', already exists." % newdir)
|
||||
else:
|
||||
head, tail = os.path.split(newdir)
|
||||
if head and not os.path.isdir(head):
|
||||
_mkdir(head)
|
||||
#print "_mkdir %s" % repr(newdir)
|
||||
if tail:
|
||||
os.mkdir(newdir)
|
||||
|
||||
@@ -57,7 +56,6 @@ class Project(object):
|
||||
|
||||
return d_dir
|
||||
|
||||
|
||||
@property
|
||||
def pipfile_location(self):
|
||||
try:
|
||||
@@ -108,7 +106,6 @@ class Project(object):
|
||||
with open(pipfile_path, 'w') as f:
|
||||
f.write(data)
|
||||
|
||||
|
||||
def add_package_to_pipfile(self, package_name, dev=False):
|
||||
# Lower-case package name.
|
||||
package_name = package_name
|
||||
|
||||
@@ -15,7 +15,6 @@ def format_toml(data):
|
||||
return '\n'.join(data)
|
||||
|
||||
|
||||
|
||||
def multi_split(s, split):
|
||||
"""Splits on multiple given separators."""
|
||||
for r in split:
|
||||
|
||||
+1
-2
@@ -3,7 +3,6 @@ import pytest
|
||||
import pipenv.utils
|
||||
|
||||
|
||||
|
||||
def test_convert_deps_to_pip():
|
||||
|
||||
# requests = '*'
|
||||
@@ -36,6 +35,7 @@ def test_convert_deps_to_pip():
|
||||
deps = pipenv.utils.convert_deps_to_pip(deps, r=False)
|
||||
assert deps[0] == 'git+git://github.com/pinax/pinax.git@1.4#egg=pinax'
|
||||
|
||||
|
||||
def test_convert_from_pip():
|
||||
|
||||
# requests
|
||||
@@ -56,4 +56,3 @@ def test_convert_from_pip():
|
||||
dep = '-e svn+svn://svn.myproject.org/svn/MyProject#egg=MyProject'
|
||||
dep = pipenv.utils.convert_deps_from_pip(dep)
|
||||
assert dep == {u'MyProject': {u'svn': u'svn://svn.myproject.org/svn/MyProject', 'editable': True}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user