Next steps for editable / develop proof of concept

This isn’t polished or anything (it’s from my work in progress experiments), but it works:

import os
import sys
import importlib.util


name = __name__
location_of_replacement = r"E:\Work\Projects\editable_poc\data"
target = os.path.join(location_of_replacement, name)
init = os.path.join(target, "__init__.py")
spec = importlib.util.spec_from_file_location(name, init)
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)

You’d need to add @bernatgabor’s code for excluding submodules. Also, people should be aware that this doesn’t help with the case where someone omits a critical file from package_data - in that case, an editable install and a proper install will still behave differently. I haven’t been able to think of any way to avoid this other than some form of link farm.

2 Likes