Skip to main content

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

import_relative-0.2.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distributions

import_relative-0.2.2-py3.3.egg (7.6 kB view details)

Uploaded Source

import_relative-0.2.2-py3.2.egg (7.6 kB view details)

Uploaded Source

import_relative-0.2.2-py2.7.egg (7.5 kB view details)

Uploaded Source

import_relative-0.2.2-py2.6.egg (7.5 kB view details)

Uploaded Source

File details

Details for the file import_relative-0.2.2.tar.gz.

File metadata

File hashes

Hashes for import_relative-0.2.2.tar.gz
Algorithm Hash digest
SHA256 f2c00cb1e7340ea677109e00b2355a3f7780383055ca88ceda2d792fe6b2d2fb
MD5 034389e14cb3ca50d151f860714820af
BLAKE2b-256 d80c978d17c9f1ceca4c7843936d30ebfa9ab1b881900dd8ae4f854baab1a618

See more details on using hashes here.

Provenance

File details

Details for the file import_relative-0.2.2-py3.3.egg.

File metadata

File hashes

Hashes for import_relative-0.2.2-py3.3.egg
Algorithm Hash digest
SHA256 ae17effe39a1e4e504ae1a57d8dc89e9a29ca4afc3af0280e13dd8692b86ffa7
MD5 12c868cbf73e5f8330d5a4b220db67ac
BLAKE2b-256 f0147f82026189daeddd728deeb3c8ea3dff3a3b23d99b09da4ea41db85023fc

See more details on using hashes here.

Provenance

File details

Details for the file import_relative-0.2.2-py3.2.egg.

File metadata

File hashes

Hashes for import_relative-0.2.2-py3.2.egg
Algorithm Hash digest
SHA256 1f682cc8d6808887c331cbaacf1748ec7b557d1ab5c626480d7b3d461c33d2c9
MD5 be0826f0e1dc8182292ed256c477ce2a
BLAKE2b-256 93efbe993e5bcf37dbf48555d402d5ef1d50d6bcec30311820213847299f7107

See more details on using hashes here.

Provenance

File details

Details for the file import_relative-0.2.2-py2.7.egg.

File metadata

File hashes

Hashes for import_relative-0.2.2-py2.7.egg
Algorithm Hash digest
SHA256 9a5c776ef226245d1f6e2976ccc2ddbf32af783284ef3616846f9a76b997e2d2
MD5 f865d3c2bcb729ac0c9b1b93902eee57
BLAKE2b-256 18c8fa1c0ed25308b3aeba1fd2976c9641109583ecaa5e2c9248e89880368e3f

See more details on using hashes here.

Provenance

File details

Details for the file import_relative-0.2.2-py2.6.egg.

File metadata

File hashes

Hashes for import_relative-0.2.2-py2.6.egg
Algorithm Hash digest
SHA256 1c91816528158212d30cb81299ad457b427650a26a9d1bd2a0dc46830b6d1f95
MD5 3d051c5ef05bb0e689b8f2a0cec14b81
BLAKE2b-256 5d80877de071aba1a23d9855e5e88c2a852700488fe08ed5835e398be3be11d4

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page