findpython

Crates.iofindpython
lib.rsfindpython
version1.0.0-alpha.3
sourcesrc
created_at2023-07-10 10:05:43.884877
updated_at2023-07-12 08:32:05.660695
descriptionFind python executables on your system
homepage
repositoryhttps://github.com/frostming/findpython
max_upload_size
id912784
size80,871
Frost Ming (frostming)

documentation

README

FindPython

A utility to find python versions on your system.

Tests PyPI PyPI - Python Version pdm-managed

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
Expand this section to see findpython's availability in the package ecosystem Packaging status

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:

License

FindPython is released under MIT License.

Commit count: 53

cargo fmt