77import os
88import shutil
99import sys
10+ import uuid
1011import zipfile
1112
1213from pip ._vendor import pkg_resources , six
@@ -339,8 +340,8 @@ def from_path(self):
339340 s += '->' + comes_from
340341 return s
341342
342- def ensure_build_location (self , build_dir , autodelete ):
343- # type: (str, bool) -> str
343+ def ensure_build_location (self , build_dir , autodelete , parallel_builds ):
344+ # type: (str, bool, bool ) -> str
344345 assert build_dir is not None
345346 if self ._temp_build_dir is not None :
346347 assert self ._temp_build_dir .path
@@ -354,16 +355,19 @@ def ensure_build_location(self, build_dir, autodelete):
354355 )
355356
356357 return self ._temp_build_dir .path
357- if self .editable :
358- name = self .name .lower ()
359- else :
360- name = self .name
358+
359+ # When parallel builds are enabled, add a UUID to the build directory
360+ # name so multiple builds do not interfere with each other.
361+ dir_name = canonicalize_name (self .name )
362+ if parallel_builds :
363+ dir_name = "{}_{}" .format (dir_name , uuid .uuid4 ().hex )
364+
361365 # FIXME: Is there a better place to create the build_dir? (hg and bzr
362366 # need this)
363367 if not os .path .exists (build_dir ):
364368 logger .debug ('Creating directory %s' , build_dir )
365369 os .makedirs (build_dir )
366- actual_build_dir = os .path .join (build_dir , name )
370+ actual_build_dir = os .path .join (build_dir , dir_name )
367371 # `None` indicates that we respect the globally-configured deletion
368372 # settings, which is what we actually want when auto-deleting.
369373 delete_arg = None if autodelete else False
@@ -588,8 +592,13 @@ def assert_source_matches_version(self):
588592 )
589593
590594 # For both source distributions and editables
591- def ensure_has_source_dir (self , parent_dir , autodelete = False ):
592- # type: (str, bool) -> None
595+ def ensure_has_source_dir (
596+ self ,
597+ parent_dir ,
598+ autodelete = False ,
599+ parallel_builds = False ,
600+ ):
601+ # type: (str, bool, bool) -> None
593602 """Ensure that a source_dir is set.
594603
595604 This will create a temporary build dir if the name of the requirement
@@ -601,7 +610,9 @@ def ensure_has_source_dir(self, parent_dir, autodelete=False):
601610 """
602611 if self .source_dir is None :
603612 self .source_dir = self .ensure_build_location (
604- parent_dir , autodelete
613+ parent_dir ,
614+ autodelete = autodelete ,
615+ parallel_builds = parallel_builds ,
605616 )
606617
607618 # For editable installations
0 commit comments