A different kind of relative import
Project description
Introduction
More akin to require_relative of Ruby than Python’s import_relative .
When you have a large package that contains nested submodules this allows the nested submodules to refer to one another without having to pull in or know much about or explicitly import entire top-level tree.
Synopsis
from import_relative import import_relative, get_srcdir # Below "trepan" is my top-level namespace # 'io' is the directory this file is in. Mbase = import_relative('base', '.', 'trepan) # Adds trepan.io.base # The following adds trepan.lib.bytecode Mbytecode = import_relative('bytecode', '..lib', 'trepan) class MyClass(Mio.InputBase): # Use name from Mio ... # like os.path.realpath(os.path.dirname(__file__)) srcdir = get_srcdir()
No import path searching is done. If the imports are not there, we fail.
Rationale
In my development, each module (which is a file in Python) can be run standalone. When called as a main program, it runs demo code. Each module is responsible for importing those other modules it needs.
I have not been able to get relative imports to work nor have I been able to use importlib either in Python 2 or 3. They seem to error out because they can’t find upper levels or something like that.
Bugs
Sorry, we don’t do “from lists”.
Various packing systems like pip and loaders may not work with this. This code is fragile.
I keep wanting to believe that there is already a way to develop out of the source code tree (not a copy of it as distutils is wont to do), not fiddle with search paths, and have demo code in modules so they can be run equally well as a main program and embedded as a module in the entire system.
Until then, I have this.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file import_relative-0.2.3.tar.gz
.
File metadata
- Download URL: import_relative-0.2.3.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ed62f11ec8fc525686135d55a117e317b62ee8a612b4415436b6fb03d9724ea |
|
MD5 | bff51a275f56e2d10200a06629c3535c |
|
BLAKE2b-256 | 124fc1c0d702e3b467cae212d92f747591b429185e9c5824f607bed231dc64f6 |
File details
Details for the file import_relative-0.2.3-py3.3.egg
.
File metadata
- Download URL: import_relative-0.2.3-py3.3.egg
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdd6af83c1216177667f05b6e9b4386b3bb6167fe63c4fbae23ead2b5162b365 |
|
MD5 | 9da122a1bbd1a28f2cd065164f121af8 |
|
BLAKE2b-256 | 4ce0da0964c5f61c84a57695b2b04aa8498af6eb07b376c162b97f858dd39c49 |
File details
Details for the file import_relative-0.2.3-py3.2.egg
.
File metadata
- Download URL: import_relative-0.2.3-py3.2.egg
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 826f2c82ee0ba8840843dbfe7820983c20558402fa533a3aa1e52cf9c6735838 |
|
MD5 | e739335eb2289f9b2f8de3eed8ba9d39 |
|
BLAKE2b-256 | 1724cfd95643b48dd8328ffaf92c9b394843662c2b836aabab20f846710d7aaa |
File details
Details for the file import_relative-0.2.3-py2.7.egg
.
File metadata
- Download URL: import_relative-0.2.3-py2.7.egg
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b8c10221510c3643a57c2b5f7fd8db5853d5cf0a7baf866a5c9763642dfcf04a |
|
MD5 | 5695dfbaa9c294860e9559193cc42586 |
|
BLAKE2b-256 | 309cd3840ed15db5faa99fd5199c174939a8711a2ea289ba5a3728797968036e |
File details
Details for the file import_relative-0.2.3-py2.6.egg
.
File metadata
- Download URL: import_relative-0.2.3-py2.6.egg
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bcb4359f2236aada8ca0d396ff23c227b09e21ba2931882837ea1ea1711f605 |
|
MD5 | d19c02d08ef838d62e3c30fa22b7e5ce |
|
BLAKE2b-256 | 31fa1e3b70ada02ba4308cfaa689abd60cb6dc0e180d48df03d0003bfc783586 |
File details
Details for the file import_relative-0.2.3-py2.5.egg
.
File metadata
- Download URL: import_relative-0.2.3-py2.5.egg
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f2a134dc5c84a462ddaf005cdda47aeefeac7ef4efdfb9aee13b3e95349bb02 |
|
MD5 | a02c669bd6a728201270c72218767316 |
|
BLAKE2b-256 | 02f7984b2a3071c009d70918277d9ce63599d81a83e0702b3cb5abde9ae55c28 |
File details
Details for the file import_relative-0.2.3-py2.4.egg
.
File metadata
- Download URL: import_relative-0.2.3-py2.4.egg
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18bf508e36509dce629f615aafd5027614b030405a6708618d4f70a7e686e91e |
|
MD5 | 315b6ef3bc739e8c5604c5b51a31e029 |
|
BLAKE2b-256 | 0822f257265c754b4a86d5184cc688755649e9806f850627bb403d8c73570a50 |