Skip to main content

import your library without __init__.py

Project description

dirimport: convenient library importer

Install

  • python -m venv your-dir
  • cd your-dir
  • ./bin/pip install dirimport

Install (devel)

Use

  • import dirimport
  • mod = dirimport.importall("/path/to/dirname")

import rules

  • file.py -> from .file import *
  • subpkg/ -> from . import subpkg
  • do it recursively

then, all symbols will be accessible after import.

example:

  • layout
    • symbol1 in dir1/file1.py
    • symbol2 in dir1/file2.py
    • symbol3 in dir1/pkg/file1.py
  • import
    • import dir1 with generated init.py
    • or dir1 = dirimport.importall("dir1") without init.py
  • result
    • symbol1 -> dir1.symbol1
    • symbol2 -> dir1.symbol2
    • symbol3 -> dir1.pkg.symbol2

CLI tools

# ./bin/dirimport
Usage: dirimport [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  diff
  eval
  generate
  • diff __init__.py
    • ./bin/dirimport diff your-library-dir
  • import and evaluate expression
    • ./bin/dirimport eval your-library-dir 'expression'
  • generate __init__.py
    • ./bin/dirimport generate your-library-dir

examples

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

dirimport-0.0.6-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file dirimport-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: dirimport-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for dirimport-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 5f72438a8ab23153a06052f23e34cba1f4034914a5a9c7c081c5f9135ff7566f
MD5 270903950c577a5be8202c36da932bd7
BLAKE2b-256 ef30bf7df0695fda5bb5ca9c1bc6831a7716c04fb0ed9e4fdfb6240eba589c66

See more details on using hashes here.

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