Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sciyoshi/dotmod
Import Python packages from folders with dotted names
https://github.com/sciyoshi/dotmod
Last synced: 3 months ago
JSON representation
Import Python packages from folders with dotted names
- Host: GitHub
- URL: https://github.com/sciyoshi/dotmod
- Owner: sciyoshi
- License: mit
- Created: 2014-09-10T19:10:56.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-01T20:13:38.000Z (almost 9 years ago)
- Last Synced: 2024-09-15T09:02:53.708Z (4 months ago)
- Language: Python
- Size: 3.91 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- starred-awesome - dotmod - Import Python packages from folders with dotted names (Python)
README
# dotmod
[![Build Status](https://travis-ci.org/sciyoshi/dotmod.svg?branch=master)](https://travis-ci.org/sciyoshi/dotmod)
This project adds support for dotted folder names to Python's import system!
## Installation
Install it using `pip`:
pip install dotmod
To use it, simply add the following line of code to one of your files:
import dotmod
This will install a global import hook that will check for folders with
dotted names.## Why?
If you are distributing a large application or library as separate components,
the normal way is to use namespace packages. Before Python 3.3, this was
accomplished by using `pkgutil.extend_path` or `pkg_resources.declare_namespace`
(see [the (rejected) PEP-402](http://legacy.python.org/dev/peps/pep-0402/#the-problem)
for details).Python 3.3 added support for namespace packages without an `__init__.py` file,
so that a package could be split up across different locations in the filesystem.
The downside to this approach is that `sys.path` needs to be extended for each
one of these locations.`dotmod` provides an approach that is compatible across Python releases. It
works by adding an import hook that checks for packages and modules with dotted
names as a fallback. For example, consider the following directory tree:spam/
|- __init__.py
|- sausage.py
`- eggs/
|- __init__.py
`- ham.py
spam.bacon/
|- __init__.py
`- beans.pyWith `dotmod`, when a module attempts to import `spam.bacon.beans`, the hook
will notice that there is no `bacon` module in the `spam/` folder, and will
then check `spam.bacon/` for the module instead.