4 releases
1.0.0-alpha.3 | Jul 12, 2023 |
---|---|
1.0.0-alpha.0 | Jul 10, 2023 |
#4 in #simplifies
54KB
1.5K
SLoC
FindPython
A utility to find python versions on your system.
Description
This library is a rewrite of pythonfinder project by @techalchemy. It simplifies the whole code structure while preserving most of the original features.
Installation
FindPython can be used in both Python and Rust projects.
To install FindPython in Python:
pip install findpython
To install FindPython in Rust:
cargo install findpyhton
Or use FindPython library in a Rust project:
cargo add findpython
Python Usage
>>> import findpython
>>> findpython.find(3, 9) # Find by major and minor version
<PythonVersion executable=/opt/homebrew/bin/python3.9, version=3.9.17, arch=64bit>
>>> findpython.find("3.9") # Find by version string
<PythonVersion executable=/opt/homebrew/bin/python3.9, version=3.9.17, arch=64bit>
>>> findpython.find("3.9-32") # Find by version string and architecture
<PythonVersion executable=C:/Python/3.9-32/python.exe, version=3.9.10, arch=32bit>
>>> findpython.find(name="python3") # Find by executable name
<PythonVersion executable=/Users/fming/wkspace/github/findpython/.venv/bin/python3, version=3.11.4, arch=64bit>
>>> findpython.find("python3") # Find by executable name without keyword argument, same as above
<PythonVersion executable=/Users/fming/wkspace/github/findpython/.venv/bin/python3, version=3.11.4, arch=64bit>
>>> findpython.find_all(major=3, minor=9) # Same arguments as `find()`, but return all matches
[<PythonVersion executable=/opt/homebrew/bin/python3.9, version=3.9.17, arch=64bit>,
<PythonVersion executable=/usr/bin/python3, version=3.9.6, arch=64bit>]
Rust Usage
use findpython::{Finder, MatchOptions};
fn main() {
let finder = Finder::default();
// Find by major and minor version
let py = finder.find(MatchOptions::default().major(3).minor(10)).unwrap();
println!("{:?}", py);
// Find all matches
let all_pythons = finder.find_all();
println!("{:?}", all_pythons);
}
CLI Usage
In addition, FindPython provides a CLI interface to find python versions:
Find python executables on your system
Usage: findpython [OPTIONS] [VERSION_SPEC]
Arguments:
[VERSION_SPEC] The version spec to find, e.g. 3|3.8|python3
Options:
-a, --all Return all matching Python versions
--resolve-symlinks Resolve symlinks and remove duplicate results
--no-same-file Remove duplicate results that are the same binary
--no-same-python Remove duplicate results that wrap the same Python interpreter
--providers <PROVIDERS> Select provider names(comma-separated) to use
-o, --output <OUTPUT> The output format [default: default] [possible values: default, json, path]
-h, --help Print help
-V, --version Print version
Integration
FindPython finds Python from the following places:
PATH
environment variable- pyenv
- asdf
- winreg (Windows only)
- Rye project manager backed by python-build-standalone
License
FindPython is released under MIT License.
Dependencies
~8–22MB
~279K SLoC