Registry / devops / whichcraft

whichcraft

JSON →
library0.6.1pypypi✓ verified 86d ago

whichcraft is a Python package that provides cross-platform and cross-Python `shutil.which` functionality. It serves as a shim for the `shutil.which` function, designed to work consistently across Python 2.7 and various Python 3 versions, including environments like Windows where system commands might behave differently. Its primary goal is to offer a reliable way to locate executables on the system PATH, similar to the Unix `which` command.

pip install whichcraft
INSTALL
IMPORT
SIG · WHICHCRAFT
W
whichcraft
devopspythonv0.6.1
Install
1.5s avg
Import
9ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.009s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.008s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

which
from whichcraft import which

This quickstart demonstrates how to import the `which` function and use it to find the path to various executables. It shows successful discovery, a non-existent command returning `None`, and highlights the cross-platform behavior for common commands like 'date'.

from whichcraft import which # Find the path to a common executable python_path = which('python') print(f"Python executable found at: {python_path}") # Try to find a command that might not exist non_existent_command = which('nonexistent_command_123') print(f"Non-existent command found at: {non_existent_command}") # Example of a command that might behave differently across OS (e.g., 'date') date_command = which('date') print(f"'date' command found at: {date_command}")
Debug
Known issues
gotchaThe behavior of `whichcraft.which('date')` (or similar internal system commands) differs between Windows and Unix-like systems. On Unix-like systems (Linux, macOS), `date` is typically a standalone executable returning its path. On Windows, `date` is often an internal shell command (cmd.exe built-in) and thus `whichcraft.which` will return `None`, as it only searches for external executables on the PATH.
fix
When using `whichcraft.which` for common system commands, be aware of OS-specific differences. For commands that are shell built-ins on some platforms, `which` will return `None`. Consider using platform-agnostic Python equivalents (e.g., `datetime` module for dates) or OS-specific checks if relying on such commands.
affects: All versions
deprecatedFor Python 3.3 and newer, the functionality provided by `whichcraft` is natively available in the standard library as `shutil.which`. While `whichcraft` still works, it may not be necessary for projects targeting only modern Python 3 versions, as its primary value was cross-version (Python 2.7 and Python 3.x) compatibility and Windows support for older Python 3 versions.
fix
For new projects or existing projects targeting Python 3.3+, consider using `from shutil import which` directly. Only use `whichcraft` if you need Python 2.7 compatibility or require its specific cross-platform shim for certain edge cases.
affects: <= 0.6.1 (all versions)
Errors
Common errors & fixes
which('my_command') returns None on Windows when I expect a path, but works on Linux.
The command you are searching for (`my_command`) might be an internal shell command (e.g., `date`, `dir`) on Windows, not a standalone executable file that exists on the system's PATH. `whichcraft.which` primarily finds external executable files.
fix
Verify if `my_command` is an actual executable file (`.exe`, `.bat`, `.cmd`) on Windows and if its directory is included in the system's PATH environment variable. If it's a shell built-in, `whichcraft` cannot locate it. For such commands, consider using `subprocess` with `shell=True` (with caution) or Python's native functionalities.
ImportError: cannot import name 'which' from 'whichcraft' (or similar import errors)
This typically means the `whichcraft` package is either not installed, or there's a typo in the import statement, or there's a naming conflict with another module or file named `whichcraft.py` in your project's directory or Python path.
fix
First, ensure the library is installed: `pip install whichcraft`. Second, double-check the import statement: `from whichcraft import which`. Third, if you have a file named `whichcraft.py` in your current working directory or a directory on your `PYTHONPATH`, Python might be trying to import from your local file instead of the installed package. Rename your local file or ensure it's not shadowing the package.
Upgrade
Version history
0.6.1latest on PyPI · released Sep 6, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
whichcraft — pip install whichcraft · libregistry