5
5
6
6
import collections
7
7
import compileall
8
- import copy
9
8
import csv
10
9
import hashlib
11
10
import logging
17
16
import warnings
18
17
from base64 import urlsafe_b64encode
19
18
from email .parser import Parser
20
- from sysconfig import get_paths
21
19
22
- from pip ._vendor import pkg_resources , pytoml
20
+ from pip ._vendor import pkg_resources
23
21
from pip ._vendor .distlib .scripts import ScriptMaker
24
22
from pip ._vendor .packaging .utils import canonicalize_name
25
23
from pip ._vendor .six import StringIO
@@ -602,58 +600,6 @@ def supported(self, tags=None):
602
600
return bool (set (tags ).intersection (self .file_tags ))
603
601
604
602
605
- class BuildEnvironment (object ):
606
- """Context manager to install build deps in a simple temporary environment
607
- """
608
- def __init__ (self , no_clean ):
609
- self ._temp_dir = TempDirectory (kind = "build-env" )
610
- self ._no_clean = no_clean
611
-
612
- def __enter__ (self ):
613
- self ._temp_dir .create ()
614
-
615
- self .save_path = os .environ .get ('PATH' , None )
616
- self .save_pythonpath = os .environ .get ('PYTHONPATH' , None )
617
-
618
- install_scheme = 'nt' if (os .name == 'nt' ) else 'posix_prefix'
619
- install_dirs = get_paths (install_scheme , vars = {
620
- 'base' : self ._temp_dir .path ,
621
- 'platbase' : self ._temp_dir .path ,
622
- })
623
-
624
- scripts = install_dirs ['scripts' ]
625
- if self .save_path :
626
- os .environ ['PATH' ] = scripts + os .pathsep + self .save_path
627
- else :
628
- os .environ ['PATH' ] = scripts + os .pathsep + os .defpath
629
-
630
- if install_dirs ['purelib' ] == install_dirs ['platlib' ]:
631
- lib_dirs = install_dirs ['purelib' ]
632
- else :
633
- lib_dirs = install_dirs ['purelib' ] + os .pathsep + \
634
- install_dirs ['platlib' ]
635
- if self .save_pythonpath :
636
- os .environ ['PYTHONPATH' ] = lib_dirs + os .pathsep + \
637
- self .save_pythonpath
638
- else :
639
- os .environ ['PYTHONPATH' ] = lib_dirs
640
-
641
- return self ._temp_dir .path
642
-
643
- def __exit__ (self , exc_type , exc_val , exc_tb ):
644
- if not self ._no_clean :
645
- self ._temp_dir .cleanup ()
646
- if self .save_path is None :
647
- os .environ .pop ('PATH' , None )
648
- else :
649
- os .environ ['PATH' ] = self .save_path
650
-
651
- if self .save_pythonpath is None :
652
- os .environ .pop ('PYTHONPATH' , None )
653
- else :
654
- os .environ ['PYTHONPATH' ] = self .save_pythonpath
655
-
656
-
657
603
class WheelBuilder (object ):
658
604
"""Build wheels from a RequirementSet."""
659
605
@@ -667,65 +613,14 @@ def __init__(self, finder, preparer, wheel_cache,
667
613
668
614
self .build_options = build_options or []
669
615
self .global_options = global_options or []
670
- self .no_clean = no_clean
671
-
672
- def _find_build_reqs (self , req ):
673
- """Get a list of the packages required to build the project, if any,
674
- and a flag indicating whether pyproject.toml is present, indicating
675
- that the build should be isolated.
676
-
677
- Build requirements can be specified in a pyproject.toml, as described
678
- in PEP 518. If this file exists but doesn't specify build
679
- requirements, pip will default to installing setuptools and wheel.
680
- """
681
- if os .path .isfile (req .pyproject_toml ):
682
- with open (req .pyproject_toml ) as f :
683
- pp_toml = pytoml .load (f )
684
- return pp_toml .get ('build-system' , {})\
685
- .get ('requires' , ['setuptools' , 'wheel' ]), True
686
-
687
- return ['setuptools' , 'wheel' ], False
688
-
689
- def _install_build_reqs (self , reqs , prefix ):
690
- # Local import to avoid circular import (wheel <-> req_install)
691
- from pip ._internal .req .req_install import InstallRequirement
692
- from pip ._internal .index import FormatControl
693
- # Ignore the --no-binary option when installing the build system, so
694
- # we don't recurse trying to build a self-hosting build system.
695
- finder = copy .copy (self .finder )
696
- finder .format_control = FormatControl (set (), set ())
697
- urls = [finder .find_requirement (InstallRequirement .from_line (r ),
698
- upgrade = False ).url
699
- for r in reqs ]
700
-
701
- args = [sys .executable , '-m' , 'pip' , 'install' , '--ignore-installed' ,
702
- '--prefix' , prefix ] + list (urls )
703
- with open_spinner ("Installing build dependencies" ) as spinner :
704
- call_subprocess (args , show_stdout = False , spinner = spinner )
705
616
706
617
def _build_one (self , req , output_dir , python_tag = None ):
707
618
"""Build one wheel.
708
619
709
620
:return: The filename of the built wheel, or None if the build failed.
710
621
"""
711
- build_reqs , isolate = self ._find_build_reqs (req )
712
- if 'setuptools' not in build_reqs :
713
- logger .warning (
714
- "This version of pip does not implement PEP 516, so "
715
- "it cannot build a wheel without setuptools. You may need to "
716
- "upgrade to a newer version of pip." )
717
- # Install build deps into temporary directory (PEP 518)
718
- with BuildEnvironment (self .no_clean ) as prefix :
719
- self ._install_build_reqs (build_reqs , prefix )
720
- return self ._build_one_inside_env (req , output_dir ,
721
- python_tag = python_tag ,
722
- isolate = True )
723
-
724
- def _build_one_inside_env (self , req , output_dir , python_tag = None ,
725
- isolate = False ):
726
622
with TempDirectory (kind = "wheel" ) as temp_dir :
727
- if self .__build_one (req , temp_dir .path , python_tag = python_tag ,
728
- isolate = isolate ):
623
+ if self .__build_one (req , temp_dir .path , python_tag = python_tag ):
729
624
try :
730
625
wheel_name = os .listdir (temp_dir .path )[0 ]
731
626
wheel_path = os .path .join (output_dir , wheel_name )
@@ -740,20 +635,14 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None,
740
635
self ._clean_one (req )
741
636
return None
742
637
743
- def _base_setup_args (self , req , isolate = False ):
744
- flags = '-u'
745
- # The -S flag currently breaks Python in virtualenvs, because it relies
746
- # on site.py to find parts of the standard library outside the env. So
747
- # isolation is disabled for now.
748
- # if isolate:
749
- # flags += 'S'
638
+ def _base_setup_args (self , req ):
750
639
return [
751
- sys .executable , flags , '-c' ,
640
+ sys .executable , '-u' , '-c' ,
752
641
SETUPTOOLS_SHIM % req .setup_py
753
642
] + list (self .global_options )
754
643
755
- def __build_one (self , req , tempd , python_tag = None , isolate = False ):
756
- base_args = self ._base_setup_args (req , isolate = isolate )
644
+ def __build_one (self , req , tempd , python_tag = None ):
645
+ base_args = self ._base_setup_args (req )
757
646
758
647
spin_message = 'Running setup.py bdist_wheel for %s' % (req .name ,)
759
648
with open_spinner (spin_message ) as spinner :
@@ -764,13 +653,8 @@ def __build_one(self, req, tempd, python_tag=None, isolate=False):
764
653
if python_tag is not None :
765
654
wheel_args += ["--python-tag" , python_tag ]
766
655
767
- env = {}
768
- if isolate :
769
- env ['PYTHONNOUSERSITE' ] = '1'
770
-
771
656
try :
772
657
call_subprocess (wheel_args , cwd = req .setup_py_dir ,
773
- extra_environ = env ,
774
658
show_stdout = False , spinner = spinner )
775
659
return True
776
660
except :
0 commit comments