A simple library for finding a superordinate path and attaching it to the module search path.
Project description
summary
This is a very simple (small) software library. It is used only for one thing.
Suppose you are working in a project with a directory structure like this:
project_folder
|-scripts_folder
| |-python_libs
| | |-my_python_lib
| | | * __init__.py
|-sub_folder_1
| | * my_python_script.py
Suppose you want your python script my_python_script.py to consume the my_python_lib library.
Then, at the top of your script, you would put the following code.
import os
import lib_attacher
# Get the folder containing your script file.
this_folder=os.path.dirname(os.path.realpath(__file__))
# Attach to the parent folder of your library
attached = lib_attacher.attach_folder_in_hierarchy(
start_folder=this_folder,
target_sub_path="scripts_folder/python_libs")
# Check to make sure it worked
if attached is None:
raise Exception("Failed to find python_libs folder.")
# Now you can import your library.
import my_python_lib
If you subsequently move your my_python_script.py file around, it will still work. For example,
it will also work from any of these locations:
project_folder
|-sub_folder_1
| |-sub_folder_2
| | | * my_python_script.py
project_folder
|-sub_folder_1
| |-sub_folder_2
| | |-sub_folder_3
| | | | * my_python_script.py
project_folder
| * my_python_script.py
If, by some chance, there are multiple scripts_folder/python_libs folders, you can specify the
extra_sub_path parameter to ensure that you match the target folder exactly (without ambiguity).
# Attach to the parent folder of your library
attached = lib_attacher.attach_folder_in_hierarchy(
start_folder=this_folder,
target_sub_path="scripts_folder/python_libs",
extra_sub_path="my_python_lib/__init__.py")
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 lib_attacher-0.0.1.tar.gz.
File metadata
- Download URL: lib_attacher-0.0.1.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d63028948500f36cb4263aba714b1efa35ef2109515210540593a8f23366b5f
|
|
| MD5 |
94f5b7b2e92367553ee0fb34d56f0f6a
|
|
| BLAKE2b-256 |
49b7c9312fd882f3d984df97e2425c4bb6112c12786db39fd2d1d49ff35f02a0
|
File details
Details for the file lib_attacher-0.0.1-py3-none-any.whl.
File metadata
- Download URL: lib_attacher-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
360b900969a7ba3fa2ff8b36009d51d0945a9788f9cdeaf3064b8b0f1fe9b103
|
|
| MD5 |
35001eea24e1100b1289d8f3c7b330e9
|
|
| BLAKE2b-256 |
374ef782164c2f25b3c2afacdc9e6a632b9f91acc97ee0e030c89541e56da259
|