Skip to content

Commit

Permalink
🔥 Revert existing PEP 518 support
Browse files Browse the repository at this point in the history
It might be easier to go about implementing things with a clean state.

Please don't hate mate -> takluyver.
  • Loading branch information
pradyunsg committed Dec 16, 2017
1 parent b0a762a commit 6ff51ba
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 668 deletions.
1 change: 0 additions & 1 deletion src/pip/_internal/commands/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ def run(self, options, args):
finder, preparer, wheel_cache,
build_options=options.build_options or [],
global_options=options.global_options or [],
no_clean=options.no_clean,
)
wheels_built_successfully = wb.build(
requirement_set.requirements.values(), session=session,
Expand Down
12 changes: 0 additions & 12 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,18 +435,6 @@ def setup_py(self):

return setup_py

@property
def pyproject_toml(self):
assert self.source_dir, "No source dir for %s" % self

pp_toml = os.path.join(self.setup_py_dir, 'pyproject.toml')

# Python2 __file__ should not be unicode
if six.PY2 and isinstance(pp_toml, six.text_type):
pp_toml = pp_toml.encode(sys.getfilesystemencoding())

return pp_toml

def run_egg_info(self):
assert self.source_dir
if self.name:
Expand Down
128 changes: 6 additions & 122 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import collections
import compileall
import copy
import csv
import hashlib
import logging
Expand All @@ -17,9 +16,8 @@
import warnings
from base64 import urlsafe_b64encode
from email.parser import Parser
from sysconfig import get_paths

from pip._vendor import pkg_resources, pytoml
from pip._vendor import pkg_resources
from pip._vendor.distlib.scripts import ScriptMaker
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.six import StringIO
Expand Down Expand Up @@ -602,58 +600,6 @@ def supported(self, tags=None):
return bool(set(tags).intersection(self.file_tags))


class BuildEnvironment(object):
"""Context manager to install build deps in a simple temporary environment
"""
def __init__(self, no_clean):
self._temp_dir = TempDirectory(kind="build-env")
self._no_clean = no_clean

def __enter__(self):
self._temp_dir.create()

self.save_path = os.environ.get('PATH', None)
self.save_pythonpath = os.environ.get('PYTHONPATH', None)

install_scheme = 'nt' if (os.name == 'nt') else 'posix_prefix'
install_dirs = get_paths(install_scheme, vars={
'base': self._temp_dir.path,
'platbase': self._temp_dir.path,
})

scripts = install_dirs['scripts']
if self.save_path:
os.environ['PATH'] = scripts + os.pathsep + self.save_path
else:
os.environ['PATH'] = scripts + os.pathsep + os.defpath

if install_dirs['purelib'] == install_dirs['platlib']:
lib_dirs = install_dirs['purelib']
else:
lib_dirs = install_dirs['purelib'] + os.pathsep + \
install_dirs['platlib']
if self.save_pythonpath:
os.environ['PYTHONPATH'] = lib_dirs + os.pathsep + \
self.save_pythonpath
else:
os.environ['PYTHONPATH'] = lib_dirs

return self._temp_dir.path

def __exit__(self, exc_type, exc_val, exc_tb):
if not self._no_clean:
self._temp_dir.cleanup()
if self.save_path is None:
os.environ.pop('PATH', None)
else:
os.environ['PATH'] = self.save_path

if self.save_pythonpath is None:
os.environ.pop('PYTHONPATH', None)
else:
os.environ['PYTHONPATH'] = self.save_pythonpath


class WheelBuilder(object):
"""Build wheels from a RequirementSet."""

Expand All @@ -667,65 +613,14 @@ def __init__(self, finder, preparer, wheel_cache,

self.build_options = build_options or []
self.global_options = global_options or []
self.no_clean = no_clean

def _find_build_reqs(self, req):
"""Get a list of the packages required to build the project, if any,
and a flag indicating whether pyproject.toml is present, indicating
that the build should be isolated.
Build requirements can be specified in a pyproject.toml, as described
in PEP 518. If this file exists but doesn't specify build
requirements, pip will default to installing setuptools and wheel.
"""
if os.path.isfile(req.pyproject_toml):
with open(req.pyproject_toml) as f:
pp_toml = pytoml.load(f)
return pp_toml.get('build-system', {})\
.get('requires', ['setuptools', 'wheel']), True

return ['setuptools', 'wheel'], False

def _install_build_reqs(self, reqs, prefix):
# Local import to avoid circular import (wheel <-> req_install)
from pip._internal.req.req_install import InstallRequirement
from pip._internal.index import FormatControl
# Ignore the --no-binary option when installing the build system, so
# we don't recurse trying to build a self-hosting build system.
finder = copy.copy(self.finder)
finder.format_control = FormatControl(set(), set())
urls = [finder.find_requirement(InstallRequirement.from_line(r),
upgrade=False).url
for r in reqs]

args = [sys.executable, '-m', 'pip', 'install', '--ignore-installed',
'--prefix', prefix] + list(urls)
with open_spinner("Installing build dependencies") as spinner:
call_subprocess(args, show_stdout=False, spinner=spinner)

def _build_one(self, req, output_dir, python_tag=None):
"""Build one wheel.
:return: The filename of the built wheel, or None if the build failed.
"""
build_reqs, isolate = self._find_build_reqs(req)
if 'setuptools' not in build_reqs:
logger.warning(
"This version of pip does not implement PEP 516, so "
"it cannot build a wheel without setuptools. You may need to "
"upgrade to a newer version of pip.")
# Install build deps into temporary directory (PEP 518)
with BuildEnvironment(self.no_clean) as prefix:
self._install_build_reqs(build_reqs, prefix)
return self._build_one_inside_env(req, output_dir,
python_tag=python_tag,
isolate=True)

def _build_one_inside_env(self, req, output_dir, python_tag=None,
isolate=False):
with TempDirectory(kind="wheel") as temp_dir:
if self.__build_one(req, temp_dir.path, python_tag=python_tag,
isolate=isolate):
if self.__build_one(req, temp_dir.path, python_tag=python_tag):
try:
wheel_name = os.listdir(temp_dir.path)[0]
wheel_path = os.path.join(output_dir, wheel_name)
Expand All @@ -740,20 +635,14 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None,
self._clean_one(req)
return None

def _base_setup_args(self, req, isolate=False):
flags = '-u'
# The -S flag currently breaks Python in virtualenvs, because it relies
# on site.py to find parts of the standard library outside the env. So
# isolation is disabled for now.
# if isolate:
# flags += 'S'
def _base_setup_args(self, req):
return [
sys.executable, flags, '-c',
sys.executable, '-u', '-c',
SETUPTOOLS_SHIM % req.setup_py
] + list(self.global_options)

def __build_one(self, req, tempd, python_tag=None, isolate=False):
base_args = self._base_setup_args(req, isolate=isolate)
def __build_one(self, req, tempd, python_tag=None):
base_args = self._base_setup_args(req)

spin_message = 'Running setup.py bdist_wheel for %s' % (req.name,)
with open_spinner(spin_message) as spinner:
Expand All @@ -764,13 +653,8 @@ def __build_one(self, req, tempd, python_tag=None, isolate=False):
if python_tag is not None:
wheel_args += ["--python-tag", python_tag]

env = {}
if isolate:
env['PYTHONNOUSERSITE'] = '1'

try:
call_subprocess(wheel_args, cwd=req.setup_py_dir,
extra_environ=env,
show_stdout=False, spinner=spinner)
return True
except:
Expand Down
1 change: 0 additions & 1 deletion src/pip/_vendor/pytoml.pyi

This file was deleted.

3 changes: 0 additions & 3 deletions src/pip/_vendor/pytoml/__init__.py

This file was deleted.

13 changes: 0 additions & 13 deletions src/pip/_vendor/pytoml/core.py

This file was deleted.

Loading

0 comments on commit 6ff51ba

Please sign in to comment.