Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Operation pewetomy #2325

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ will detect it.
- ``PIPENV_SHELL_FANCY`` — Always use fancy mode when invoking ``pipenv shell``.

- ``PIPENV_VENV_IN_PROJECT`` — If set, use ``.venv`` in your project directory
instead of the global virtualenv manager ``pew``.
instead of the global ``WORKON_HOME`` directory.

- ``PIPENV_COLORBLIND`` — Disable terminal colors, for some reason.

Expand Down Expand Up @@ -407,8 +407,9 @@ For example::
☤ Custom Virtual Environment Location
-------------------------------------

Pipenv's underlying ``pew`` dependency will automatically honor the ``WORKON_HOME`` environment
variable, if you have it set — so you can tell pipenv to store your virtual environments wherever you want, e.g.::
Pipenv automatically honors the ``WORKON_HOME`` environment variable, if you
have it set — so you can tell pipenv to store your virtual environments
wherever you want, e.g.::

export WORKON_HOME=~/.venvs

Expand Down
1 change: 0 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ imagesize==0.7.1
Jinja2==2.9.6
MarkupSafe==1.0
pbr==3.1.1
pew==0.1.26
pip-tools==1.9.0
-e .
Pygments==2.2.0
Expand Down
8 changes: 6 additions & 2 deletions pipenv/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ def __init__(self, *args, **kwargs):
def detach(self):
return False


if six.PY2:

class ResourceWarning(Warning):
pass

# Backport required for earlier versions of Python.
if sys.version_info < (3, 3):
from .vendor.backports.shutil_get_terminal_size import get_terminal_size
else:
from shutil import get_terminal_size


def pip_import(module_path, subimport=None, old_path=None):
internal = 'pip._internal.{0}'.format(module_path)
Expand Down
174 changes: 54 additions & 120 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import crayons
import dotenv
import delegator
from .vendor import pexpect
from first import first
import pipfile
from blindspin import spinner
Expand Down Expand Up @@ -73,16 +72,12 @@
PIPENV_USE_SYSTEM,
PIPENV_DOTENV_LOCATION,
PIPENV_SHELL,
PIPENV_EMULATOR,
PIPENV_PYTHON,
PIPENV_VIRTUALENV,
PIPENV_CACHE_DIR,
)

# Backport required for earlier versions of Python.
if sys.version_info < (3, 3):
from .vendor.backports.shutil_get_terminal_size import get_terminal_size
else:
from shutil import get_terminal_size
# Packages that should be ignored later.
BAD_PACKAGES = ('setuptools', 'pip', 'wheel', 'packaging', 'distribute')
# Are we using the default Python?
Expand Down Expand Up @@ -122,7 +117,7 @@ def spinner():

def which(command, location=None, allow_global=False):
if not allow_global and location is None:
location = project.virtualenv_location or os.environ.get('VIRTUAL_ENV')
location = project.virtualenv_location
if not allow_global:
if os.name == 'nt':
p = find_windows_executable(
Expand Down Expand Up @@ -471,7 +466,7 @@ def activate_pyenv():
if (not PIPENV_DONT_USE_PYENV) and (SESSION_IS_INTERACTIVE or PIPENV_YES):
version_map = {
# TODO: Keep this up to date!
# These versions appear incompatible with pew:
# These versions appear incompatible with virtualenv?
# '2.5': '2.5.6',
'2.6': '2.6.9',
'2.7': '2.7.15',
Expand Down Expand Up @@ -892,28 +887,7 @@ def do_create_virtualenv(python=None, site_packages=False):
click.echo(u'Pipfile: {0}'.format(
crayons.red(project.pipfile_location, bold=True),
), err=True)
# The user wants the virtualenv in the project.
if project.is_venv_in_project():
cmd = [
sys.executable, '-m', 'virtualenv',
project.virtualenv_location,
'--prompt=({0})'.format(project.name),
]
# Pass site-packages flag to virtualenv, if desired...
if site_packages:
cmd.append('--system-site-packages')
else:
# Default: use pew.
cmd = [
sys.executable,
'-m',
'pipenv.pew',
'new',
project.virtualenv_name,
'-d',
'-a',
project.project_directory,
]

# Default to using sys.executable, if Python wasn't provided.
if not python:
python = sys.executable
Expand All @@ -926,7 +900,17 @@ def do_create_virtualenv(python=None, site_packages=False):
),
err=True,
)
cmd = cmd + ['-p', python]

cmd = [
sys.executable, '-m', 'virtualenv',
project.virtualenv_location,
'--prompt', '({0})'.format(project.name),
'--python', python,
]
# Pass site-packages flag to virtualenv, if desired...
if site_packages:
cmd.append('--system-site-packages')

# Actually create the virtualenv.
with spinner():
try:
Expand All @@ -944,15 +928,13 @@ def do_create_virtualenv(python=None, site_packages=False):
)
sys.exit(1)
click.echo(crayons.blue(c.out), err=True)
# Enable site-packages, if desired...
if not project.is_venv_in_project() and site_packages:
click.echo(
crayons.normal(u'Making site-packages available…', bold=True),
err=True,
)
os.environ['VIRTUAL_ENV'] = project.virtualenv_location
delegator.run('pipenv run pewtwo toggleglobalsitepackages')
del os.environ['VIRTUAL_ENV']

# Associate the project to the virtual environment.
# We write with binary so the write never fails, and is guarenteed to be
# in the platform's native filesystem encoding.
with Path(project.virtualenv_location, '.project').open('wb') as f:
f.write(str(Path(project.project_directory).resolve()).encode())

# Say where the virtualenv is.
do_where(virtualenv=True, bare=False)

Expand Down Expand Up @@ -1181,7 +1163,7 @@ def activate_virtualenv(source=True):
"""Returns the string to activate a virtualenv."""
# Suffix and source command for other shells.
suffix = ''
command = '.' if source else ''
command = ' .' if source else ''
# Support for fish shell.
if PIPENV_SHELL and 'fish' in PIPENV_SHELL:
suffix = '.fish'
Expand Down Expand Up @@ -2151,93 +2133,45 @@ def do_uninstall(


def do_shell(three=None, python=False, fancy=False, shell_args=None):
from .patched.pew import pew

# Ensure that virtualenv is available.
ensure_project(three=three, python=python, validate=False)
# Set an environment variable, so we know we're in the environment.
os.environ['PIPENV_ACTIVE'] = '1'
compat = (not fancy)

# Support shell compatibility mode.
if PIPENV_SHELL_FANCY:
compat = False
# Compatibility mode:
if compat:
if PIPENV_SHELL:
shell = os.path.abspath(PIPENV_SHELL)
else:
click.echo(
crayons.red(
'Please ensure that the {0} environment variable '
'is set before activating shell.'.format(
crayons.normal('SHELL', bold=True)
)
),
err=True,
)
sys.exit(1)
click.echo(
crayons.normal(
'Spawning environment shell ({0}). Use {1} to leave.'.format(
crayons.red(shell), crayons.normal("'exit'", bold=True)
),
bold=True,
),
err=True,
fancy = True

from .shells import choose_shell, CannotGuessShell
try:
shell = choose_shell(PIPENV_SHELL, PIPENV_EMULATOR)
except CannotGuessShell:
click.echo(crayons.red(
'Please ensure that the {0} environment variable is set before '
'activating shell.'.format(crayons.normal('SHELL', bold=True)),
), err=True)
sys.exit(1)

click.echo(crayons.normal(
'Spawning environment shell ({0}). Use {1} to leave.'.format(
crayons.red(shell.cmd), crayons.normal("'exit'", bold=True)
),
bold=True,
), err=True)

if fancy:
shell.fork(
project.virtualenv_location,
project.project_directory,
shell_args,
)
cmd = "{0} -i'".format(shell)
args = []
# Standard (properly configured shell) mode:
else:
if project.is_venv_in_project():
# use .venv as the target virtualenv name
workon_name = '.venv'
else:
workon_name = project.virtualenv_name
cmd = sys.executable
args = ['-m', 'pipenv.pew', 'workon', workon_name]
# Grab current terminal dimensions to replace the hardcoded default
# dimensions of pexpect
terminal_dimensions = get_terminal_size()
try:
with temp_environ():
if project.is_venv_in_project():
os.environ['WORKON_HOME'] = project.project_directory
c = pexpect.spawn(
cmd,
args,
dimensions=(
terminal_dimensions.lines, terminal_dimensions.columns
),
)
# Windows!
except AttributeError:
# import subprocess
# Tell pew to use the project directory as its workon_home
with temp_environ():
if project.is_venv_in_project():
os.environ['WORKON_HOME'] = project.project_directory
pew.workon_cmd([workon_name])
sys.exit(0)
# Activate the virtualenv if in compatibility mode.
if compat:
c.sendline(activate_virtualenv())
# Send additional arguments to the subshell.
if shell_args:
c.sendline(' '.join(shell_args))

# Handler for terminal resizing events
# Must be defined here to have the shell process in its context, since we
# can't pass it as an argument
def sigwinch_passthrough(sig, data):
terminal_dimensions = get_terminal_size()
c.setwinsize(terminal_dimensions.lines, terminal_dimensions.columns)

signal.signal(signal.SIGWINCH, sigwinch_passthrough)
# Interact with the new shell.
c.interact(escape_character=None)
c.close()
sys.exit(c.exitstatus)
shell.fork_compat(
project.virtualenv_location,
project.project_directory,
shell_args,
activate_virtualenv(),
)


def inline_activate_virtualenv():
Expand Down
7 changes: 6 additions & 1 deletion pipenv/environments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
# Prevent invalid shebangs with Homebrew-installed Python:
# https://bugs.python.org/issue22490
os.environ.pop('__PYVENV_LAUNCHER__', None)
# Where to put virtual environments.
WORKON_HOME = os.path.expanduser(os.environ.get(
'WORKON_HOME', '~/.virtualenvs',
)).strip()
# Shell compatibility mode, for mis-configured shells.
PIPENV_SHELL_FANCY = bool(os.environ.get('PIPENV_SHELL_FANCY'))
# Support for both Python 2 and Python 3 at the same time.
PIPENV_PYTHON = os.environ.get('PIPENV_PYTHON')
# Create the virtualenv in the project, instead of with pew.
# Create the virtualenv in the project, instead of inside WORKON_HOME.
PIPENV_VENV_IN_PROJECT = bool(
os.environ.get('PIPENV_VENV_IN_PROJECT')
)
Expand Down Expand Up @@ -75,4 +79,5 @@
)
SESSION_IS_INTERACTIVE = bool(os.isatty(sys.stdout.fileno()))
PIPENV_SHELL = os.environ.get('SHELL') or os.environ.get('PYENV_SHELL')
PIPENV_EMULATOR = os.environ.get('PIPENV_EMULATOR')
PIPENV_CACHE_DIR = os.environ.get('PIPENV_CACHE_DIR', user_cache_dir('pipenv'))
1 change: 0 additions & 1 deletion pipenv/patched/patched.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
safety
git+https://github.com/jumpscale7/python-consistent-toml.git#egg=contoml
crayons==0.1.2
git+https://github.com/berdario/pew.git@1.1.5#egg=pew
pipfile==0.0.2
git+https://github.com/jazzband/pip-tools.git@9cb41d828fcb0967a32cc140c1dcaca94e5f4daa#egg=piptools
prettytoml==0.3
Expand Down
17 changes: 0 additions & 17 deletions pipenv/patched/pew/LICENSE

This file was deleted.

4 changes: 0 additions & 4 deletions pipenv/patched/pew/__init__.py

This file was deleted.

4 changes: 0 additions & 4 deletions pipenv/patched/pew/__main__.py

This file was deleted.

Loading