Merge pull request #2518 from pypa/purge-pew

Always use virtualenv directly, not "pew new"
This commit is contained in:
Tzu-ping Chung
2018-07-05 16:12:46 +08:00
committed by GitHub
8 changed files with 56 additions and 137 deletions
+47 -41
View File
@@ -102,7 +102,12 @@ if PIPENV_NOSPIN:
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
or os.environ.get("VIRTUAL_ENV", "")
)
if not location and os.path.exists(location):
raise RuntimeError("virtualenv not created nor specified")
if not allow_global:
if os.name == "nt":
p = find_windows_executable(os.path.join(location, "Scripts"), command)
@@ -871,35 +876,16 @@ def convert_three_to_python(three, python):
def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
"""Creates a virtualenv."""
click.echo(
crayons.normal(u"Creating a virtualenv for this project…", bold=True), err=True
)
click.echo(
u"Pipfile: {0}".format(crayons.red(project.pipfile_location, bold=True)),
crayons.normal(u"Creating a virtualenv for this project…", 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",
"-d",
"-a",
project.project_directory,
]
click.echo(
u"Pipfile: {0}".format(
crayons.red(project.pipfile_location, bold=True),
),
err=True,
)
# Default to using sys.executable, if Python wasn't provided.
if not python:
python = sys.executable
@@ -912,14 +898,35 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
),
err=True,
)
cmd = cmd + ["-p", python]
if not project.is_venv_in_project():
cmd = cmd + ["--", project.virtualenv_name]
cmd = [
sys.executable,
"-m",
"virtualenv",
"--prompt=({0})".format(project.name),
"--python={0}".format(python),
project.get_location_for_virtualenv(),
]
# Pass site-packages flag to virtualenv, if desired…
if site_packages:
click.echo(
crayons.normal(u"Making site-packages available…", bold=True),
err=True,
)
cmd.append("--system-site-packages")
if pypi_mirror:
pip_config = {"PIP_INDEX_URL": fs_str(pypi_mirror)}
else:
pip_config = {}
# Actually create the virtualenv.
with spinner():
try:
pip_config = {"PIP_INDEX_URL": fs_str(pypi_mirror)} if pypi_mirror else {}
c = delegator.run(cmd, block=False, timeout=PIPENV_TIMEOUT, env=pip_config)
c = delegator.run(
cmd, block=False, timeout=PIPENV_TIMEOUT, env=pip_config,
)
except OSError:
click.echo(
"{0}: it looks like {1} is not in your {2}. "
@@ -933,14 +940,13 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None):
)
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 project directory with the environment.
# This mimics Pew's "setproject".
project_file_name = os.path.join(project.virtualenv_location, '.project')
with open(project_file_name, 'w') as f:
f.write(fs_str(project.project_directory))
# Say where the virtualenv is.
do_where(virtualenv=True, bare=False)
+9 -19
View File
@@ -237,12 +237,10 @@ class Project(object):
return False
@classmethod
def _get_virtualenv_location(cls, name):
venv = get_workon_home() / name
if not venv.exists():
return ""
return "{0}".format(venv)
def get_location_for_virtualenv(self):
if self.is_venv_in_project():
return os.path.join(self.project_directory, ".venv")
return str(get_workon_home().joinpath(self.virtualenv_name))
@classmethod
def _sanitize(cls, name):
@@ -282,7 +280,7 @@ class Project(object):
if (
fnmatch.fnmatch('A', 'a')
or self.is_venv_in_project()
or self._get_virtualenv_location(venv_name)
or get_workon_home().joinpath(venv_name).exists()
):
return clean_name, encoded_hash
@@ -315,18 +313,10 @@ class Project(object):
if PIPENV_VIRTUALENV:
return PIPENV_VIRTUALENV
# Use cached version, if available.
if self._virtualenv_location:
return self._virtualenv_location
# Default mode.
if not self.is_venv_in_project():
loc = self._get_virtualenv_location(self.virtualenv_name)
# The user wants the virtualenv in the project.
else:
loc = os.sep.join(self.pipfile_location.split(os.sep)[:-1] + [".venv"])
self._virtualenv_location = loc
return loc
if not self._virtualenv_location: # Use cached version, if available.
assert self.project_directory, "project not created"
self._virtualenv_location = self.get_location_for_virtualenv()
return self._virtualenv_location
@property
def virtualenv_src_location(self):
@@ -1,53 +0,0 @@
Metadata-Version: 1.1
Name: pytest-pypi
Version: 0.1.1
Summary: Easily test your HTTP library against a local copy of pypi
Home-page: https://github.com/kennethreitz/pytest-pypi
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: MIT
Description: pytest-httpbin
==============
httpbin is an amazing web service for testing HTTP libraries. It has several
great endpoints that can test pretty much everything you need in a HTTP
library. The only problem is: maybe you don't want to wait for your tests to
travel across the Internet and back to make assertions against a remote web
service.
Enter pytest-httpbin. Pytest-httpbin creates a pytest "fixture" that is
dependency-injected into your tests. It automatically starts up a HTTP server
in a separate thread running httpbin and provides your test with the URL in the
fixture. Check out this example:
.. code-block:: python
def test_that_my_library_works_kinda_ok(httpbin):
assert requests.get(httpbin.url + '/get/').status_code == 200
This replaces a test that might have looked like this before:
.. code-block:: python
def test_that_my_library_works_kinda_ok():
assert requests.get('http://httpbin.org/get').status_code == 200
pytest-httpbin also supports https and includes its own CA cert you can use.
Check out `the full documentation`_ on the github page.
.. _the full documentation: https://github.com/kevin1024/pytest-httpbin
Keywords: pytest-pypi testing pytest pypi
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Libraries
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.6
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
@@ -1,17 +0,0 @@
DESCRIPTION.rst
MANIFEST.in
README.md
setup.cfg
setup.py
pytest_pypi/__init__.py
pytest_pypi/app.py
pytest_pypi/certs.py
pytest_pypi/plugin.py
pytest_pypi/serve.py
pytest_pypi/version.py
pytest_pypi.egg-info/PKG-INFO
pytest_pypi.egg-info/SOURCES.txt
pytest_pypi.egg-info/dependency_links.txt
pytest_pypi.egg-info/entry_points.txt
pytest_pypi.egg-info/requires.txt
pytest_pypi.egg-info/top_level.txt
@@ -1 +0,0 @@
@@ -1,3 +0,0 @@
[pytest11]
pypi = pytest_pypi.plugin
@@ -1,2 +0,0 @@
Flask
six
@@ -1 +0,0 @@
pytest_pypi