Skip to main content

A brute-force shortcut to fix python import hell. Acronym, standing for, um, Fix Up Python Imports. Sure, let's go with that.

Project description

fupi

A brute-force shortcut to fix python import hell. Acronym standing for... um, Fixing-Up Python Imports.

Sure, let's go with that.

Usage

Simply import fupi in your project:

import fupi

This automatically adds relevant directories (like src and test) to your Python path, making imports work seamlessly across your project structure.

Configuration

No configuration is needed if you use the defaults:

  • Add src and test folders and subfolders,
  • Skip folders setup, venv*, and *egg*.

.ENV File Config

To use different / more folder names, simply add the following to an existing .env file, or create a new *.env or fupi.env file:

FUPI_ADD_DIRS="src,test"
FUPI_SKIP_DIRS="setup,venv*,*egg*"

The FUPI_ADD_DIRS will be string-matched against folders in your project, and on exact match, will include that folder and all subfolders into your sys.path.

The FUPI_SKIP_DIRS is a collection of regex patterns to skip, with string begin and end tags added (^value$). Thus you can simply add a list of folder names, or use basic wildcard * characters. If you want to get crazy with regex, be my guest - but understand the value will be wrapped (^value$).

The FUPI_SKIP_DIRS will also always append patters to disqualify any path starting with a period('.') or an underscore('_') (i.e., '\.*' and '\_*'), which should catch most common skipped folders like .git, __pycache__, etc.

Environment Variable Config

Alternatively, you can add the above to os.envars before you import fupi. Note, this process does NOT use dotenv, which would also load into os.envars, although the behavior is similar, just restricted to only FUPI_* configs. Similar to the .env approach above, simply add a comma-delimited list of all folder names / regex patterns.

Manual Setting

You can also manually call the functions in the fupi libary with whatever settings you'd like. To take advantage of this option, you'll have to escape the default behavior of running all logic on import fupi, automatically.

To escape the auto-run, add a single .env or envvar as per below:

FUPI_ADD_DIRS="disable"

Then you can configure manually, with:

from fupi import fupi
fupi.add_dirs_and_children_to_syspath(
    add_dirs=['my','app','folders'], 
    skip_dirs=['not','*these*'])

Finally, if you want to roll-back to a previous state, the sys.path contents is logged in the object sys_path_history which captures the pre-execution snapshot at index[0], and subsequent snapshots every time a change is made. This would allow you to 'roll-back' to a pre-exexution state by simply:

sys.path = sys_path_history[0]['sys.path set 0']

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

fupi-0.6a0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

fupi-0.6a0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file fupi-0.6a0.tar.gz.

File metadata

  • Download URL: fupi-0.6a0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for fupi-0.6a0.tar.gz
Algorithm Hash digest
SHA256 723f93a055b25b3dae50422dac27cb554127600e58abe05b24d0b728989610c4
MD5 1984c75b12b2a9273363a64a5517e30a
BLAKE2b-256 aebe42c0672a2b48974cc2fbda175ca5e1731d9a05e2b5f96ee96c676542b8da

See more details on using hashes here.

File details

Details for the file fupi-0.6a0-py3-none-any.whl.

File metadata

  • Download URL: fupi-0.6a0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for fupi-0.6a0-py3-none-any.whl
Algorithm Hash digest
SHA256 50433ffcb3437ca011efd77bb1660f725c9f74bd14bbdd9cbe3fb315e5d4bb44
MD5 8be1e234a3471806e381dd9c832c2b82
BLAKE2b-256 c26675f7535a16c5ca8157b5f7fa6303f370494d58250857c033c3272375993d

See more details on using hashes here.

Supported by

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