Giter Club home page Giter Club logo

pathtub's Introduction

This project is archived, but feel free to look around! :)

🛁 pathtub

Reading and editing Windows PATH variables and ensuring python finds your DLLs.

    ✅ Ensuring that a folder exists in Path.
    🔗 Ensuring that DLL(s) are found by python.
    🧽 Cleaning the PATH (duplicates, removed folders, sorting)
    ✏️ Adding or removing folders to/from Path (temporary or permanently)

Installing

pip install pathtub

Usage

✅ Ensuring folder is in PATH

from pathtub import ensure
folder_to_add = r'C:\something to add to path\folder'
# 1) Check Process PATH
# 2) Add to Process PATH if not found
# 3) Add also to User PATH (permanent), if 2) happens
ensure(folder_to_add, permanent=True)

What is ensure()?

ensure(folder) checks if folder is in Process PATH

  • If folder is in Process PATH, does nothing
  • If folder is not in Process PATH, adds it to Process PATH
  • If folder is not in Process PATH and permanent=True, adds also to the User PATH or System PATH, depending on the permanent_mode.

⚠️ If you want to ensure a DLL folder is visible to python, use ensure_dll instead.

🔗 Ensuring that DLL(s) are found

  • ensure_dll() is for making sure that python finds needed DLL's (and the DLL's find their dependencies, if any.)
  • If folder is not yet added, it adds folder to Process PATH and, in case of Python 3.8+, also uses the os.add_dll_directory (More info). If folder is already added, does nothing.
from pathtub import ensure_dll
dll_folder = r'C:\path to\libusb-1.0.21\MS32\dll'
ensure_dll(dll_folder)
  • Folders added with ensure_dll can be removed with forget_dll in the same process.
  • More info related to ensure_dll here.

🧽 Cleaning PATH

from pathtub import clean
# Default parameter values shown
clean(sort=True, remove_non_existent=True, remove_user_duplicates=True)

What does it do

  • Removes duplicates and empty entries (;;) from the "User PATH" and "System PATH" (trailing backslash neglected when comparing two folders). Editing "System PATH" needs that python is executed with Admin rights.
  • Sorts PATH(s) alphabetically (optional, enabled by default). Controlled with the sort parameter.
  • Removes folders from PATH(s) that do not exist on the filesystem (optional, enabled by default). Controlled with the remove_non_existent -parameter.
  • Removing from "User PATH" the entries that are in the "System PATH" (optional, enabled by default). Controlled with the remove_user_duplicates-parameter.

Screenshots of User PATH before and after clean:

User PATH

Rest of the docs

Did not find what you were looking for? See the Rest of the docs.

pathtub's People

Contributors

fohrloop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pombredanne

pathtub's Issues

Clean is case-sensitive

On a case-sensitive filesystem (ie.: the default), the clean command leaves paths pointing to the same folder but with different cases.
Eg.:
C:\WINDOWS
C:\Windows

DLL folder not ensured with pathtub.ensure()

Steps to reproduce

  • pathtub 1.1.1
  • pyusb
  • Python 3.8.2 32.bit
from pathtub import ensure
dll_folder = r'C:\path to\libusb-1.0.21\MS64\dll'
import usb.backend.libusb1

ensure(dll_folder)
usb.backend.libusb1._load_library()

Expected behaviour

  • The DLL is found after adding to to Windows (Process) PATH
  • usb.backend.libusb1._load_library() returns without Exceptions

Actual behaviour

  • The DLL is not found by the pyusb library DLL search
  • usb.backend.libusb1._load_library() throws LibraryNotLoadedException

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.