diff options
| author | Jason R. Coombs <jaraco@jaraco.com> | 2015-04-26 10:14:37 -0400 |
|---|---|---|
| committer | Jason R. Coombs <jaraco@jaraco.com> | 2015-04-26 10:14:37 -0400 |
| commit | 0e2d03c65eee67b2357069bd0de3eda453d8a319 (patch) | |
| tree | 44137e7a1eb894a03de25830bae21837eb40814a | |
| parent | c2cc7435a96775ef4cd018930fdd83b8ba1dd45d (diff) | |
| download | python-setuptools-git-0e2d03c65eee67b2357069bd0de3eda453d8a319.tar.gz | |
Extract function for initializing the master working set. Fixes #373.
| -rw-r--r-- | pkg_resources/__init__.py | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index f033c10e..0721baa8 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -3053,20 +3053,34 @@ def _initialize(g): g[name] = getattr(_manager, name) _initialize(globals()) -# Prepare the master working set and make the ``require()`` API available -working_set = WorkingSet._build_master() -_declare_state('object', working_set=working_set) - -require = working_set.require -iter_entry_points = working_set.iter_entry_points -add_activation_listener = working_set.subscribe -run_script = working_set.run_script -# backward compatibility -run_main = run_script -# Activate all distributions already on sys.path, and ensure that -# all distributions added to the working set in the future (e.g. by -# calling ``require()``) will get activated as well. -add_activation_listener(lambda dist: dist.activate()) -working_set.entries=[] -# match order -list(map(working_set.add_entry, sys.path)) + +def _initialize_master_working_set(): + """ + Prepare the master working set and make the ``require()`` + API available. + + This function has explicit effects on the global state + of pkg_resources. It is intended to be invoked once at + the initialization of this module. + + Invocation by other packages is unsupported and done + at their own risk. + """ + working_set = WorkingSet._build_master() + _declare_state('object', working_set=working_set) + + require = working_set.require + iter_entry_points = working_set.iter_entry_points + add_activation_listener = working_set.subscribe + run_script = working_set.run_script + # backward compatibility + run_main = run_script + # Activate all distributions already on sys.path, and ensure that + # all distributions added to the working set in the future (e.g. by + # calling ``require()``) will get activated as well. + add_activation_listener(lambda dist: dist.activate()) + working_set.entries=[] + # match order + list(map(working_set.add_entry, sys.path)) + globals().update(locals()) +_initialize_master_working_set() |
