[Python-ideas] pathlib.Path should handle Pythonpath or package root
george at fischhof.hu
Wed Jul 19 08:01:37 EDT 2017
Sorry it was misunderstandable.
I do not want to touch the import.
I just would like to access the package root (of my current script).
Practically in a Path object if the package resides in the file system.
Parent is not enough, because the place of actual running script can vary.
2017-07-19 3:51 GMT+02:00 Nick Coghlan <ncoghlan at gmail.com>:
> On 19 July 2017 at 06:40, George Fischhof <george at fischhof.hu> wrote:
> > I think yes ;-)
> > I would like to use (or I think it would be good to use) something like
> > pathlib.Path(package_root)
> > so I could use
> > importlib.import_module(pathlib.Path(package_root) / plugins /
> No, as that's fundamentally incompatible with how Python's import
> system works - the filesystem is *a* way of representing package
> namespacing, but far from the only way. Managing the import state also
> has nothing whatsoever to do with pathlib.
> That said, the idea of better encapsulating the import state so we can
> more readily have constrained "import engines" *is* a reasonable one,
> it just runs into significant practical problems related to the
> handling of transitive imports in both Python modules and (especially)
> extension modules.
> The last serious attempt at pursuing something like that is documented
> in PEP 406, "Improved Encapsulation of Import State":
> Unfortunately, the main outcome of Greg Slodkowicz's GSoC work on the
> idea was to conclude that that particular approach wasn't viable due
> to the fact that import system plugins at that time were pretty much
> required to directly manipulate global state, which ran directly
> counter to the goal of encapsulation.
> However, we also haven't had anyone seriously revisit the idea since
> the updated import plugin API was defined in PEP 451 - that
> deliberately moved a lot of the global state management out of the
> plugins and into the import system, so it should be more amenable to
> an "import engine" style approach to state encapsulation.
> Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas