Update state of pkg_resources after using virtualenv's "activate_this.py"

The virtualenv package provides an activate_this.py script to allow activating a virtualenv at runtime (saving the overhead of spooling up a second Python process).

However, pkg_resources prepares some internal state (working_set, etc) depending on which virtualenv is active when it’s imported.
Is it possible to manually tell pkg_resources to update its internal state? I pkg_resources to provide information on the new virtualenv after it’s activated, and I’ll happily inform it after the activation has completed :slight_smile:

I haven’t found a way to request that working_set entirely refresh itself, but I am using pkg_resources.working_set.add_entry(...) to add new sys.path items manually, and that’s sufficient for my purposes :sunglasses:

I don’t think there is a supported way to manually refresh the master working set, there are some hacks to trigger it to scan the paths again (working_set.require() or something), but hacks are hacks. The general recommendation is to not use pkg_resources (importlib.metadata is much better implementation and supported), and if you must, don’t use the master working set but create one yourself.