Skip to main content

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.

Release files for import_relative 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for import_relative 0.2.3
File Size Uploaded
import_relative-0.2.3.tar.gz 19.8 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for import_relative 0.2.3
File
import_relative-0.2.3-py3.3.egg Legacy Egg format - - Details
import_relative-0.2.3-py3.2.egg Legacy Egg format - - Details
import_relative-0.2.3-py2.7.egg Legacy Egg format - - Details
import_relative-0.2.3-py2.6.egg Legacy Egg format - - Details
import_relative-0.2.3-py2.5.egg Legacy Egg format - - Details
import_relative-0.2.3-py2.4.egg Legacy Egg format - - Details

Total release size: 65.1 kB

Release files / import_relative-0.2.3.tar.gz

Download URL import_relative-0.2.3.tar.gz
Size 19.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3ed62f11ec8fc525686135d55a117e317b62ee8a612b4415436b6fb03d9724ea
BLAKE2b-256 checksum
How to use checksums
124fc1c0d702e3b467cae212d92f747591b429185e9c5824f607bed231dc64f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / import_relative-0.2.3-py3.3.egg

Download URL import_relative-0.2.3-py3.3.egg
Size 7.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
bdd6af83c1216177667f05b6e9b4386b3bb6167fe63c4fbae23ead2b5162b365
BLAKE2b-256 checksum
How to use checksums
4ce0da0964c5f61c84a57695b2b04aa8498af6eb07b376c162b97f858dd39c49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / import_relative-0.2.3-py3.2.egg

Download URL import_relative-0.2.3-py3.2.egg
Size 7.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
826f2c82ee0ba8840843dbfe7820983c20558402fa533a3aa1e52cf9c6735838
BLAKE2b-256 checksum
How to use checksums
1724cfd95643b48dd8328ffaf92c9b394843662c2b836aabab20f846710d7aaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / import_relative-0.2.3-py2.7.egg

Download URL import_relative-0.2.3-py2.7.egg
Size 7.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
b8c10221510c3643a57c2b5f7fd8db5853d5cf0a7baf866a5c9763642dfcf04a
BLAKE2b-256 checksum
How to use checksums
309cd3840ed15db5faa99fd5199c174939a8711a2ea289ba5a3728797968036e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / import_relative-0.2.3-py2.6.egg

Download URL import_relative-0.2.3-py2.6.egg
Size 7.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
3bcb4359f2236aada8ca0d396ff23c227b09e21ba2931882837ea1ea1711f605
BLAKE2b-256 checksum
How to use checksums
31fa1e3b70ada02ba4308cfaa689abd60cb6dc0e180d48df03d0003bfc783586
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / import_relative-0.2.3-py2.5.egg

Download URL import_relative-0.2.3-py2.5.egg
Size 7.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
9f2a134dc5c84a462ddaf005cdda47aeefeac7ef4efdfb9aee13b3e95349bb02
BLAKE2b-256 checksum
How to use checksums
02f7984b2a3071c009d70918277d9ce63599d81a83e0702b3cb5abde9ae55c28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / import_relative-0.2.3-py2.4.egg

Download URL import_relative-0.2.3-py2.4.egg
Size 7.6 kB
Tags Egg
SHA-256 checksum
How to use checksums
18bf508e36509dce629f615aafd5027614b030405a6708618d4f70a7e686e91e
BLAKE2b-256 checksum
How to use checksums
0822f257265c754b4a86d5184cc688755649e9806f850627bb403d8c73570a50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.3 This release

7 release files

0.2.2

5 release files

0.2

2 release files

0.1.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page