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 detects and adds relevant directories (src, test, app) and their children to your Python path, making imports work seamlessly across your project structure regardless of how bad you screw it up. This allow you to run components independently, run tests from anywhere, etc.
This can be a bit dangerous in larger projects, as you have no idea what you're actually importing. You can create local fupi.env files to limit the scope to what you care about, which will help. This is a "move fast and break things" type of project.
Also, you may consider commenting out import fupi once you get deployment and testing automated / located to a centralized starting point, again to make sure you're not hiding import bugs - by that point you won't likely need this brute-force tool. Fupi is really a tool to speed up rapid-deploy tests / POCs / etc., where you're coding fast and loose, and especially for one-person projects (of which AI is increasing the number and velocity).
Configuration
No configuration is needed if you use the defaults:
- Adds
src,test,appfolders and subfolders to sys.path... - Skipping most common non-application file folders, like
.git,venv*,__pycache__,setup, etc.
.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 program will evaluate every *.env file it finds in the current working directory, it's parent, and all it's children. It then picks the best one that contains the two envars below:
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. Or, you can reset the sys.path using the roll-back ability, below.
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*'])
Rollback
Finally, if you want to roll-back to a previous state, sys.path contents are logged in the object sys_path_history
which captures the pre-import 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 = fupi.sys_path_history['history'][0]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fupi-1.2.tar.gz.
File metadata
- Download URL: fupi-1.2.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cc6ea8162091629339a7072393a159e63467c39bf73b0557678e57fd238e4ff
|
|
| MD5 |
702f1fed80b179be281f8902fdbc962f
|
|
| BLAKE2b-256 |
d6ff41fb70919ac66775ff2ab15f733bc23156616d68c43c15ebc1a73f5c653c
|
File details
Details for the file fupi-1.2-py3-none-any.whl.
File metadata
- Download URL: fupi-1.2-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9fbf79fda5160ce93af7ee7b3b5f6501ffef9576230abaa5b1dd7a4b00d2196
|
|
| MD5 |
51a34a3248484a02911afa3d9b664a22
|
|
| BLAKE2b-256 |
3e222a8fa3162e61221b76c3911866d4f69280b043e3acc4ac81a601d6040f9f
|