1818from .resolvable import ResolvableRequirement , resolvables_from_iterable
1919from .resolver_options import ResolverOptionsBuilder
2020from .tracer import TRACER
21+ from .util import DistributionHelper
2122
2223
2324class Untranslateable (Exception ):
@@ -55,9 +56,9 @@ def merge(self, other):
5556
5657
5758class _ResolvableSet (object ):
58- def __init__ (self ):
59+ def __init__ (self , tuples = None ):
5960 # A list of _ResolvedPackages
60- self .__tuples = []
61+ self .__tuples = tuples or []
6162
6263 def _collapse (self ):
6364 # Collapse all resolvables by name along with the intersection of all compatible packages.
@@ -112,6 +113,18 @@ def extras(self, name):
112113 return set .union (
113114 * [set (tup .resolvable .extras ()) for tup in self .__tuples if tup .resolvable .name == name ])
114115
116+ def replace_built (self , built_packages ):
117+ """Return a copy of this resolvable set but with built packages.
118+
119+ :param dict built_packages: A mapping from a resolved package to its locally built package.
120+ :returns: A new resolvable set with built package replacements made.
121+ """
122+ def map_packages (resolved_packages ):
123+ packages = OrderedSet (built_packages .get (p , p ) for p in resolved_packages .packages )
124+ return _ResolvedPackages (resolved_packages .resolvable , packages , resolved_packages .parent )
125+
126+ return _ResolvableSet ([map_packages (rp ) for rp in self .__tuples ])
127+
115128
116129class Resolver (object ):
117130 """Interface for resolving resolvable entities into python packages."""
@@ -165,6 +178,7 @@ def resolve(self, resolvables, resolvable_set=None):
165178 resolvable_set .merge (resolvable , packages , parent )
166179 processed_resolvables .add (resolvable )
167180
181+ built_packages = {}
168182 for resolvable , packages , parent in resolvable_set .packages ():
169183 assert len (packages ) > 0 , 'ResolvableSet.packages(%s) should not be empty' % resolvable
170184 package = next (iter (packages ))
@@ -174,13 +188,19 @@ def resolve(self, resolvables, resolvable_set=None):
174188 raise self .Error ('Ambiguous resolvable: %s' % resolvable )
175189 continue
176190 if package not in distributions :
177- distributions [package ] = self .build (package , resolvable .options )
191+ dist = self .build (package , resolvable .options )
192+ built_package = Package .from_href (dist .location )
193+ built_packages [package ] = built_package
194+ distributions [built_package ] = dist
195+ package = built_package
196+
178197 distribution = distributions [package ]
179198 processed_packages [resolvable .name ] = package
180199 new_parent = '%s->%s' % (parent , resolvable ) if parent else str (resolvable )
181200 resolvables .extend (
182201 (ResolvableRequirement (req , resolvable .options ), new_parent ) for req in
183202 distribution .requires (extras = resolvable_set .extras (resolvable .name )))
203+ resolvable_set = resolvable_set .replace_built (built_packages )
184204
185205 return list (distributions .values ())
186206
@@ -233,7 +253,8 @@ def build(self, package, options):
233253 shutil .copyfile (dist .location , target + '~' )
234254 os .rename (target + '~' , target )
235255 os .utime (target , None )
236- return dist
256+
257+ return DistributionHelper .distribution_from_path (target )
237258
238259
239260def resolve (
0 commit comments