Skip to main content

midir

A library for resolving relative module dependencies.

Description

midir is a Python library designed to handle relative module dependencies by resolving directory paths in an intelligent and system-agnostic way. This library can be used to introspect the file structure of your project and manipulate Python's sys.path, allowing for dynamic module imports based on directory hierarchy. It is especially helpful for larger projects where file structure can become complex and static imports cumbersome to manage.

Features

  1. get_caller() -> str: Returns the name of the file or the location (directory) where the current execution point is present.

  2. mipath(path: str = None) -> str | Path: Returns the canonical (absolute) path of the current execution point or a provided path.

  3. midir(path: str = None) -> str | Path: Returns the directory name where the current execution point is or from a provided path.

  4. root_levels(levels: int = 1) -> None: Makes directories available for import by adding them to sys.path. It starts from directory of the caller file and move up the directory hierarchy. The number of levels up to move is determined by input argument.

  5. root_suffix(suffix: str) -> None: Similar to root_levels, but instead of moving up a certain number of directories, it continues to move up until it finds a directory whose name ends with the provided suffix and adds that directory to sys.path.

  6. lsdir(path: str) -> List[str]: This function retrieves a sorted list of file and/or folder names from a specified directory path. Whether it returns file or folder names depends on the parameters set. It returns the full path of these files/folders if requested. Custom filter conditions can be applied. Raises errors if path isn't found or if no output requirements are specified. A warning is given if both file and folder parameters are set to true while a custom filter function is also specified.

Exceptions

  1. FolderNotFoundError: Custom exception raised when no folder matching the required conditions (in root_suffix) is found in the directory hierarchy.

Testing

cd midir
source bin/activate
pytest .
cd midir
source bin/activate
python -m tests.test_unit

Build instructions

  1. Building the package before uploading: 'python -m build' (from "midir").
  2. Upload the package to pypi: 'python -m twine upload --repository pypi dist/*'
  3. Install the package from pypi: 'python -m pip install midir'
  4. If any dependencies are required, edit the pyproject.toml file, "[project]" field, and add a dependencies key with a List\[str\] value, where each string is a pip-readable dependency.

Download files

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

Source Distribution

midir-1.2.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

midir-1.2.2-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file midir-1.2.2.tar.gz.

File metadata

  • Download URL: midir-1.2.2.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.7

File hashes

Hashes for midir-1.2.2.tar.gz
Algorithm Hash digest
SHA256 e49fe792bf79ce73b5f13b79516c732278f415266220c63da8a5f8d044e3ad53
MD5 fa88f95aefb0e3b7fa40e312c81b8865
BLAKE2b-256 32b2130c3f2a49ed4fba4f599fcc6d7459c7e13cce261bd12dd3189ea61ef373

See more details on using hashes here.

File details

Details for the file midir-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: midir-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.7

File hashes

Hashes for midir-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1de1763bc4000b5485f34c129f9a55959618228e1161a017ae683cf0f7652bfa
MD5 4f477248e9faedf849f97607bf036208
BLAKE2b-256 dec0c6f8f9e7e924f7dd5130fa1bb097fca1dc3560e3dbad52650ce827695b44

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.2.2 This release

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.0

2 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