feat: function to install single package.

This commit is contained in:
Mr Finchum 2025-02-09 17:48:30 +01:00
parent 09a37ae628
commit 9680e33730
3 changed files with 18 additions and 1 deletions

View file

@ -1,5 +1,11 @@
# Changelog
## 0.7.0: Added Function to Install Packages
- Introduced the `install_package` function, allowing packages to be installed directly through the app.
- Useful for optional dependencies that need to be installed separately. This enables installation via the UI.
---
## 0.6.x
### 0.6.1: Classifier
- Added Classifier for pypi

View file

@ -11,7 +11,7 @@ readme = "README.md"
requires-python = ">=3.8"
dependencies = ["requests", "packaging"]
classifiers = [
"Development Status :: 4 - Beta",
"Development Status :: 3 - Alpha",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",

View file

@ -146,3 +146,14 @@ class PyPiUpdater:
"""Write data to JSON log file."""
with open(self.log_path, "w") as f:
json.dump(data, f, indent=4)
@staticmethod
def install_package(package_name):
"""Attempts to install a package via pip."""
try:
subprocess.run([sys.executable, "-m", "pip", "install", package_name], check = True)
print("Successfull")
return [True, f"{package_name} installed successfully!"]
except subprocess.CalledProcessError as e:
print("Failed")
return [False, f"Failed to install {package_name}:\n{e.stderr}"]