Restore 0.1.5 version from stash

This commit is contained in:
liaibo
2025-12-08 19:56:24 +08:00
parent de189e938d
commit 8db3f4e32d
8578 changed files with 2703426 additions and 217 deletions
@@ -0,0 +1,281 @@
Metadata-Version: 2.4
Name: pipmaster
Version: 1.0.10
Summary: A versatile Python package manager utility for simplifying package installation, updates, checks, and environment management.
Author-email: ParisNeo <parisneoai@gmail.com>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/ParisNeo/pipmaster
Project-URL: Repository, https://github.com/ParisNeo/pipmaster
Project-URL: Issues, https://github.com/ParisNeo/pipmaster/issues
Keywords: pip,package manager,installer,dependency,venv,environment
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: System :: Software Distribution
Classifier: Typing :: Typed
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: packaging>=21.0
Requires-Dist: ascii_colors>=0.8.0
Provides-Extra: audit
Requires-Dist: pip-audit>=2.5.0; extra == "audit"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.20; extra == "dev"
Requires-Dist: pip-audit>=2.5.0; extra == "dev"
Requires-Dist: sphinx>=5.0; extra == "dev"
Requires-Dist: sphinx-rtd-theme>=1.0; extra == "dev"
Requires-Dist: myst-parser>=0.17; extra == "dev"
Requires-Dist: ruff>=0.1.0; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: black; extra == "dev"
Requires-Dist: cowsay; extra == "dev"
Provides-Extra: all
Requires-Dist: pipmaster[audit]; extra == "all"
Requires-Dist: pipmaster[dev]; extra == "all"
Dynamic: license-file
# `pipmaster`: The Python Package Management Toolkit
<!-- Badges -->
[![PyPI version](https://badge.fury.io/py/pipmaster.svg)](https://badge.fury.io/py/pipmaster)
[![Python Versions](https://img.shields.io/pypi/pyversions/pipmaster.svg)](https://pypi.org/project/pipmaster/)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/ParisNeo/pipmaster/blob/main/LICENSE)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/ParisNeo/pipmaster/docs.yml?branch=main&label=docs)](https://github.com/ParisNeo/pipmaster/actions/workflows/docs.yml)
[![GitHub stars](https://img.shields.io/github/stars/ParisNeo/pipmaster.svg?style=social&label=Stars)](https://github.com/ParisNeo/pipmaster)
[![Documentation Status](https://readthedocs.org/projects/pipmaster/badge/?version=latest)](https://parisneo.github.io/pipmaster/)
Stop telling your users to `pip install -r requirements.txt`. Start building professional, self-sufficient Python applications that **just work**.
`pipmaster` is the ultimate toolkit for declarative and programmatic package management. It provides a robust, unified interface to backends like **`pip`** and **`uv`**, allowing you to automate installations, updates, and environment validation directly from your Python code. With both **synchronous and asynchronous APIs**, it's designed to guarantee that your applications work out-of-the-box by programmatically ensuring all dependencies are correctly installed.
**View the full documentation at [parisneo.github.io/pipmaster/](https://parisneo.github.io/pipmaster/).**
## Why `pipmaster`? The Power to Build Better Software
`pipmaster` bridges the gap between development and deployment, solving the classic "it works on my machine" problem.
* **Automate Your Setup:** Create a seamless first-time experience. Instead of manual setup steps, your application can configure its own environment on launch.
* **Write Self-Healing Applications:** Programmatically verify dependencies every time your app runs. If a user accidentally uninstalls a critical package, your application can detect it and fix itself.
* **Eliminate "Dependency Hell" for Users:** By managing dependencies automatically, you remove the biggest source of friction for non-technical users and simplify deployment for everyone.
* **Simplify Complex Projects:** Effortlessly manage dependencies across multiple virtual environments, build servers, or CI/CD pipelines from a single, consistent interface.
* **Code with Confidence:** Use the `dry_run` mode to safely preview any changes before they are made, and leverage the `verbose` flag for crystal-clear debugging.
* **Future-Proof Your Scripts:** With a multi-backend architecture (`pip`, `uv`, and `conda` planned), your automation scripts remain stable even as the packaging ecosystem evolves.
## Key Use Cases
`pipmaster` is the swiss army knife for anyone who builds and ships Python software.
* **Desktop GUI Applications (PyQt, Tkinter, etc.):** Ensure all UI libraries and dependencies are met on the very first launch, providing a smooth, installer-like experience.
* **Command-Line Tools (Click, Typer, Argparse):** Create a fantastic user experience by having your CLI tool install its own dependencies, making it instantly usable.
* **Data Science & ML Projects:** Guarantee that team members, servers, and Docker containers all share the exact same environment state by running an `ensure_requirements` check at the start of a script.
* **CI/CD & Automation Scripts:** Programmatically prepare a build environment, install testing tools, and deploy your application with reliable, repeatable Python code instead of brittle shell scripts.
* **Libraries and Frameworks:** Provide helper scripts for users to set up a correct environment, or use it internally to manage complex testing dependencies.
## Feature Overview
| Feature | `pip` Backend | `uv` Backend (Experimental) | `async` Support |
| -------------------------------------------- | :-----------: | :-------------------------: | :-------------: |
| **Ensure Package State (`ensure_packages`)** | ✅ | ❌ | ✅ |
| **Ensure from `requirements.txt`** | ✅ | ❌ | ✅ |
| Install / Upgrade Packages | ✅ | ✅ | ✅ |
| Uninstall Packages | ✅ | ✅ | ✅ |
| Check for Vulnerabilities (`pip-audit`) | ✅ | N/A | ✅ |
| Check Installed Status (`is_installed`) | ✅ | N/A | (Sync) |
| Create Virtual Environments | N/A | ✅ | N/A |
| Run Ephemeral Tools (`uvx`) | N/A | ✅ | N/A |
| Dry Run Mode | ✅ | ❌ | ✅ |
## Installation
`pipmaster` requires Python 3.8 or higher.
```bash
pip install pipmaster
```
### Optional Features
* **Vulnerability Auditing (`pip-audit`):**
```bash
pip install pipmaster[audit]
```
* **Development Environment (for contributors):**
```bash
git clone https://github.com/ParisNeo/pipmaster.git
cd pipmaster
pip install -e .[dev]
```
* **All Extras:**
```bash
pip install pipmaster[all]
```
## The Core Concept: Declarative & Idempotent Management
The `ensure_*` methods are the heart of `pipmaster`. They are **idempotent**, meaning you can run them a thousand times, and they will only perform an action if the environment is out of sync with your declarations.
They are also **efficient**. `pipmaster` checks all requirements first, then triggers a *single, batch installation command* only for the packages that are missing or outdated. This is far superior to running multiple `pip install` commands in a loop.
### `ensure_packages`: Define Dependencies Directly in Code
This is the most powerful feature for creating self-contained applications. Define dependencies as a simple string, a list, or a dictionary.
```python
import pipmaster as pm
# 1. Simple: Ensure a single package is present
pm.ensure_packages("rich")
# 2. List: Ensure multiple packages, with version specifiers
pm.ensure_packages(["pandas", "numpy>=1.20"], verbose=True)
# 3. Dictionary: A clean way to manage a set of requirements
requirements = {
"requests": ">=2.25.0",
"tqdm": None # Any version is acceptable
}
pm.ensure_packages(requirements, verbose=True)
```
### `ensure_requirements`: Automate Your `requirements.txt` Workflow
Use your existing `requirements.txt` files and let `pipmaster` handle the rest. It's the perfect one-line replacement for manual installation commands.
```python
import pipmaster as pm
# Create a demo file
with open("requirements-demo.txt", "w") as f:
f.write("rich\n")
f.write("packaging>=21.0\n")
# Ensure the environment matches the file
if pm.ensure_requirements("requirements-demo.txt", verbose=True):
print("\nEnvironment is in sync with requirements file!")
```
## Advanced Usage & Recipes
### Recipe 1: Conditional Installation from Git
Imagine you need cutting-edge features from a Git branch, but only if the user has an older version installed. `ensure_packages` handles this advanced logic with a special dictionary format.
```python
import pipmaster as pm
# This rule says: "We need diffusers version 0.25.0 or newer.
# If the installed version doesn't meet this, install from the main branch on GitHub."
conditional_requirement = {
"name": "diffusers",
"vcs": "git+https://github.com/huggingface/diffusers.git",
"condition": ">=0.25.0"
}
# First, let's install an old version to see it trigger
pm.install("diffusers==0.24.0", verbose=True)
print("\n--- Running ensure_packages with a conditional Git requirement ---")
pm.ensure_packages([conditional_requirement], verbose=True)
print(f"Post-check diffusers version: {pm.get_installed_version('diffusers')}")
print("\n--- Running it again (should do nothing) ---")
# Now that a newer version is installed, the condition is met, and pipmaster takes no action.
pm.ensure_packages([conditional_requirement], verbose=True)
```
### Recipe 2: Synchronous vs. Asynchronous API
Every core function has an `async` equivalent. Just prefix with `async_` and `await` the call.
```python
import pipmaster as pm
import asyncio
# Synchronous call
pm.install("httpx")
# Asynchronous equivalent
async def main():
await pm.async_install("httpx")
await pm.async_ensure_requirements("requirements.txt")
# asyncio.run(main()) # Uncomment to run
```
### Recipe 3: Using the `uv` Backend
Take advantage of `uv`'s incredible speed for creating environments and installing packages. This requires `uv` to be installed on your system's PATH.
```python
from pipmaster import get_uv_manager
import os
import shutil
temp_env_path = "./my_uv_test_env"
try:
# Get a manager that is NOT tied to the current environment
uv_manager = get_uv_manager()
# Create a new, empty venv
if uv_manager.create_env(path=temp_env_path):
print("uv environment created successfully.")
# The manager now targets the new environment for all subsequent calls
uv_manager.install_multiple(["numpy", "pandas"], verbose=True)
print("Packages installed in the new environment.")
# Use uvx to run a tool in an ephemeral environment
print("\n--- Running black --version with uv's tool runner ---")
uv_manager.run_with_uvx(["black", "--version"], verbose=True)
except FileNotFoundError:
print("Skipping uv examples: 'uv' executable not found in PATH.")
finally:
if os.path.exists(temp_env_path):
shutil.rmtree(temp_env_path)
```
### Recipe 4: Environment Inspection and Safety
Check packages without changing anything, and audit for security vulnerabilities.
```python
import pipmaster as pm
# --- Inspection (Fast, synchronous calls) ---
if pm.is_installed("requests", version_specifier=">=2.20"):
print(f"Requests version {pm.get_installed_version('requests')} is compatible.")
# --- Safety: Dry Run ---
print("\n--- Previewing changes with Dry Run ---")
pm.ensure_packages({"numpy": "<1.20"}, dry_run=True, verbose=True)
# --- Safety: Vulnerability Audit ---
print("\n--- Checking for Vulnerabilities ---")
try:
vulnerabilities_found, report = pm.check_vulnerabilities()
if vulnerabilities_found:
print("WARNING: Vulnerabilities found!")
else:
print("No known vulnerabilities found in the environment.")
except FileNotFoundError:
print("Skipping check: pip-audit not found. Install with 'pip install pipmaster[audit]'")
```
## Contributing
Contributions are welcome! If you find a bug, have a feature request, or want to contribute code, please check the GitHub Issues page before opening a new issue or submitting a pull request.
## License
This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,14 @@
pipmaster-1.0.10.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
pipmaster-1.0.10.dist-info/METADATA,sha256=ezWes4osqd27Y4XIy2-JjPyGVnHrhiHg5_9aqFFfcpU,13475
pipmaster-1.0.10.dist-info/RECORD,,
pipmaster-1.0.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
pipmaster-1.0.10.dist-info/licenses/LICENSE,sha256=HrhfyXIkWY2tGFK11kg7vPCqhgh5DcxleloqdhrpyMY,11558
pipmaster-1.0.10.dist-info/top_level.txt,sha256=zhMNQKOEMOKmfWczp5Sd-ISQ1egSg1l8AUjXwrrcIDU,10
pipmaster/__init__.py,sha256=BSJZ0WUTRHwVlwVgZ8OhDbb0qBEgLju2oPytAiTIsbw,2560
pipmaster/__pycache__/__init__.cpython-312.pyc,,
pipmaster/__pycache__/async_package_manager.cpython-312.pyc,,
pipmaster/__pycache__/package_manager.cpython-312.pyc,,
pipmaster/async_package_manager.py,sha256=D75CSRf71W3wtojJ5s-T5cSKjKf9Jrl9v9l9nEk-I8o,16661
pipmaster/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
pipmaster/cli/__pycache__/__init__.cpython-312.pyc,,
pipmaster/package_manager.py,sha256=aiLQkEL7pKq838McqXEJ1U1zWaf-gLKpmn4CUAsomfI,81873
@@ -0,0 +1,5 @@
Wheel-Version: 1.0
Generator: setuptools (80.9.0)
Root-Is-Purelib: true
Tag: py3-none-any
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.