@@ -555,16 +555,15 @@ class WorkingSet:
555
555
556
556
def __init__ (self , entries = None ):
557
557
"""Create working set from list of path entries (default=sys.path)"""
558
- self .entries = []
558
+ self ._entries = None
559
559
self .entry_keys = {}
560
560
self .by_key = {}
561
561
self .callbacks = []
562
562
563
563
if entries is None :
564
564
entries = sys .path
565
565
566
- for entry in entries :
567
- self .add_entry (entry )
566
+ self .paths = entries
568
567
569
568
@classmethod
570
569
def _build_master (cls ):
@@ -619,10 +618,20 @@ def add_entry(self, entry):
619
618
equal ``sys.path``.)
620
619
"""
621
620
self .entry_keys .setdefault (entry , [])
622
- self .entries .append (entry )
621
+ self ._entries .append (entry )
623
622
for dist in find_distributions (entry , True ):
624
623
self .add (dist , entry , False )
625
624
625
+ @property
626
+ def entries (self ):
627
+ """Lazy access to path entries."""
628
+ if self ._entries is None :
629
+ self ._entries = []
630
+
631
+ for entry in self .paths :
632
+ self .add_entry (entry )
633
+ return self ._entries
634
+
626
635
def __contains__ (self , dist ):
627
636
"""True if `dist` is the active distribution for its project"""
628
637
return self .by_key .get (dist .key ) == dist
@@ -3270,21 +3279,11 @@ def _initialize_master_working_set():
3270
3279
run_script = working_set .run_script
3271
3280
# backward compatibility
3272
3281
run_main = run_script
3273
- # Activate all distributions already on sys.path with replace=False and
3274
- # ensure that all distributions added to the working set in the future
3275
- # (e.g. by calling ``require()``) will get activated as well,
3276
- # with higher priority (replace=True).
3277
- tuple (
3278
- dist .activate (replace = False )
3279
- for dist in working_set
3280
- )
3282
+
3281
3283
add_activation_listener (
3282
3284
lambda dist : dist .activate (replace = True ),
3283
3285
existing = False ,
3284
3286
)
3285
- working_set .entries = []
3286
- # match order
3287
- list (map (working_set .add_entry , sys .path ))
3288
3287
globals ().update (locals ())
3289
3288
3290
3289
class PkgResourcesDeprecationWarning (Warning ):
0 commit comments