diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index a3ac1e4..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,52 +0,0 @@ -name: CI/CD Pipeline - -on: - pull_request: - branches: - - main - - push: - branches: - - main - -jobs: - test: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install pytest - - - name: Run tests - run: pytest - - lint: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v3 - with: - python-version: 3.8 - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pylint - - - name: Run linter - run: pylint pipmanager diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml deleted file mode 100644 index c73e032..0000000 --- a/.github/workflows/pylint.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Pylint - -on: [push] - -jobs: - build: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: ["3.8", "3.9", "3.10"] - steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pylint - - name: Analysing the code with pylint - run: | - pylint $(git ls-files '*.py') diff --git a/pipmanager/pipmanager.egg-info/PKG-INFO b/pipmanager/pipmanager.egg-info/PKG-INFO index 9678552..c67aba3 100644 --- a/pipmanager/pipmanager.egg-info/PKG-INFO +++ b/pipmanager/pipmanager.egg-info/PKG-INFO @@ -5,311 +5,313 @@ Summary: A Python library and CLI for managing pip packages. Home-page: https://github.com/HamadMulti/devops-lab/pipmanager Author: Hamad Author-email: informhammadahmad@gmail.com +License: UNKNOWN +Description: # `pipmanager` + + **`pipmanager`** is a Python library and command-line tool that simplifies managing Python packages using `pip`. It allows you to list installed packages, check for outdated ones, install or uninstall packages, and upgrade all outdated packages. + + ## Features + + - **List Installed Packages**: Quickly view all installed Python packages. + - **Check for Outdated Packages**: Identify which packages have updates available. + - **Install a Package**: Easily install any Python package by name. + - **Uninstall a Package**: Remove any installed package with a single command. + - **Upgrade All Outdated Packages**: Automatically upgrade all outdated packages in one go. + - **Command-Line Interface (CLI)**: Manage packages directly from your terminal. + - **Library for Automation**: Use it programmatically in Python scripts. + + ## Setting Up a Virtual Environment + + Using a virtual environment is recommended to isolate project dependencies and avoid conflicts. + + ### Steps: + + 1. **Create a Virtual Environment**: + + ```bash + python -m venv venv + ``` + + This creates a directory named `venv` that contains the virtual environment. + + 2. **Activate the Virtual Environment**: + + - On Windows: + ```bash + venv\Scripts\activate + ``` + - On macOS/Linux: + ```bash + source venv/bin/activate + ``` + + 3. **Install All Dependencies**: + Install both runtime and development dependencies: + + ```bash + pip install -r requirements.txt + pip install -r requirements-dev.txt + ``` + + 4. **Verify the Setup**: + Ensure all dependencies are installed: + ```bash + pip list + ``` + + ### Requirements Files + + Include the following requirements files for runtime and development dependencies. + + #### **`requirements.txt`** (Runtime Dependencies) + + ```plaintext + click==8.1.3 + ``` + + #### **`requirements-dev.txt`** (Development Dependencies) + + ```plaintext + pytest==7.4.0 + pytest-mock==3.10.0 + pylint==2.17.5 + ``` + + ## Installation + + ### From PyPI + + To install the latest version from PyPI: + + ```bash + pip install pipmanager + ``` + + ### From Source + + If you're working with the source code, navigate to the project directory and install it locally: + + ```bash + pip install . + ``` + + ## Usage + + ### Command-Line Interface (CLI) + + Once installed, you can use the `pipmanager` command directly from your terminal. + + #### Commands: + + 1. **List Installed Packages** + + ```bash + pipmanager list + ``` + + Displays all currently installed Python packages. + + 2. **Check for Outdated Packages** + + ```bash + pipmanager outdated + ``` + + Lists all packages with available updates. + + 3. **Install a Package** + + ```bash + pipmanager install --package + ``` + + Example: + + ```bash + pipmanager install --package requests + ``` + + Installs the `requests` package. + + 4. **Uninstall a Package** + + ```bash + pipmanager uninstall --package + ``` + + Example: + + ```bash + pipmanager uninstall --package requests + ``` + + Uninstalls the `requests` package. + + 5. **Upgrade All Outdated Packages** + ```bash + pipmanager upgrade-all + ``` + Upgrades all outdated packages to their latest versions. + + ### Library Usage + + You can also use `pipmanager` programmatically in your Python scripts: + + #### Example Script: + + ```python + from pipmanager import PipManager + + # List installed packages + PipManager.list_packages() + + # Check for outdated packages + PipManager.check_updates() + + # Install a specific package + PipManager.install_package("numpy") + + # Uninstall a specific package + PipManager.uninstall_package("numpy") + + # Upgrade all outdated packages + PipManager.upgrade_all() + ``` + + ## How It Works + + - `pipmanager` uses Python’s `subprocess` module to run `pip` commands behind the scenes. + - Output from commands is displayed in the terminal, ensuring a user-friendly experience. + + ## Error Handling + + - If you provide an invalid package name, `pipmanager` will display an error message. + - The library ensures that all commands are safe and idempotent: + - Reinstalling an already installed package won't cause issues. + - Uninstalling a non-existent package will return a clear error. + + ## Contributing + + We welcome contributions to `pipmanager`! Follow these steps to contribute: + + 1. Fork the repository on GitHub. + 2. Clone your fork: + + ```bash + git clone https://github.com/HamadMulti/devops-lab.git + ``` + + 3. **Set Up a Virtual Environment**: + + ```bash + python -m venv venv + source venv/bin/activate # or venv\Scripts\activate on Windows + ``` + + 4. **Install Dependencies**: + + ```bash + pip install -r requirements.txt + ``` + + 5. Create a feature branch: + ```bash + git checkout -b feature/your-feature + ``` + 6. Make changes and write tests. + 7. Push your branch: + ```bash + git push origin feature/your-feature + ``` + 8. Open a pull request on the main repository. + + ## Testing + + To run the tests, use the following command: + + ```bash + pytest tests/ + ``` + + ## License + + This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details. + + ## Examples + + ### CLI Example + + ```bash + # Check installed packages + pipmanager list + + # Check outdated packages + pipmanager outdated + + # Install Flask + pipmanager install --package flask + + # Uninstall Flask + pipmanager uninstall --package flask + + # Upgrade all outdated packages + pipmanager upgrade-all + ``` + + ### Python Script Example + + ```python + from pipmanager import PipManager + + # Check for updates + PipManager.check_updates() + + # Install Flask + PipManager.install_package("flask") + + # Upgrade all outdated packages + PipManager.upgrade_all() + ``` + + ## Release Workflow + + The `main` branch always contains the production-ready code. Releases follow this workflow: + + 1. Create a release branch from `master`: + ```bash + git checkout -b release/ master + ``` + 2. Finalize release details (update version, changelog, etc.). + 3. Merge the release branch into `main` and tag it: + ```bash + git checkout main + git merge release/ + git tag -a v -m "Release " + git push origin main --tags + ``` + 4. Merge the release branch back into `master`: + ```bash + git checkout develop + git merge release/ + git push origin develop + ``` + + ## Future Enhancements + + - Add support for virtual environments. + - Enable rollback of package changes. + - Improve support for dependency resolution. + + ## Support + + For any questions or issues, feel free to: + + - Open a GitHub issue in the repository. + - Contact the maintainers directly. + +Platform: UNKNOWN Classifier: Programming Language :: Python :: 3 Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: OS Independent Requires-Python: >=3.6 Description-Content-Type: text/markdown - -# `pipmanager` - -**`pipmanager`** is a Python library and command-line tool that simplifies managing Python packages using `pip`. It allows you to list installed packages, check for outdated ones, install or uninstall packages, and upgrade all outdated packages. - -## Features - -- **List Installed Packages**: Quickly view all installed Python packages. -- **Check for Outdated Packages**: Identify which packages have updates available. -- **Install a Package**: Easily install any Python package by name. -- **Uninstall a Package**: Remove any installed package with a single command. -- **Upgrade All Outdated Packages**: Automatically upgrade all outdated packages in one go. -- **Command-Line Interface (CLI)**: Manage packages directly from your terminal. -- **Library for Automation**: Use it programmatically in Python scripts. - -## Setting Up a Virtual Environment - -Using a virtual environment is recommended to isolate project dependencies and avoid conflicts. - -### Steps: - -1. **Create a Virtual Environment**: - - ```bash - python -m venv venv - ``` - - This creates a directory named `venv` that contains the virtual environment. - -2. **Activate the Virtual Environment**: - - - On Windows: - ```bash - venv\Scripts\activate - ``` - - On macOS/Linux: - ```bash - source venv/bin/activate - ``` - -3. **Install All Dependencies**: - Install both runtime and development dependencies: - - ```bash - pip install -r requirements.txt - pip install -r requirements-dev.txt - ``` - -4. **Verify the Setup**: - Ensure all dependencies are installed: - ```bash - pip list - ``` - -### Requirements Files - -Include the following requirements files for runtime and development dependencies. - -#### **`requirements.txt`** (Runtime Dependencies) - -```plaintext -click==8.1.3 -``` - -#### **`requirements-dev.txt`** (Development Dependencies) - -```plaintext -pytest==7.4.0 -pytest-mock==3.10.0 -pylint==2.17.5 -``` - -## Installation - -### From PyPI - -To install the latest version from PyPI: - -```bash -pip install pipmanager -``` - -### From Source - -If you're working with the source code, navigate to the project directory and install it locally: - -```bash -pip install . -``` - -## Usage - -### Command-Line Interface (CLI) - -Once installed, you can use the `pipmanager` command directly from your terminal. - -#### Commands: - -1. **List Installed Packages** - - ```bash - pipmanager list - ``` - - Displays all currently installed Python packages. - -2. **Check for Outdated Packages** - - ```bash - pipmanager outdated - ``` - - Lists all packages with available updates. - -3. **Install a Package** - - ```bash - pipmanager install --package - ``` - - Example: - - ```bash - pipmanager install --package requests - ``` - - Installs the `requests` package. - -4. **Uninstall a Package** - - ```bash - pipmanager uninstall --package - ``` - - Example: - - ```bash - pipmanager uninstall --package requests - ``` - - Uninstalls the `requests` package. - -5. **Upgrade All Outdated Packages** - ```bash - pipmanager upgrade-all - ``` - Upgrades all outdated packages to their latest versions. - -### Library Usage - -You can also use `pipmanager` programmatically in your Python scripts: - -#### Example Script: - -```python -from pipmanager import PipManager - -# List installed packages -PipManager.list_packages() - -# Check for outdated packages -PipManager.check_updates() - -# Install a specific package -PipManager.install_package("numpy") - -# Uninstall a specific package -PipManager.uninstall_package("numpy") - -# Upgrade all outdated packages -PipManager.upgrade_all() -``` - -## How It Works - -- `pipmanager` uses Python’s `subprocess` module to run `pip` commands behind the scenes. -- Output from commands is displayed in the terminal, ensuring a user-friendly experience. - -## Error Handling - -- If you provide an invalid package name, `pipmanager` will display an error message. -- The library ensures that all commands are safe and idempotent: - - Reinstalling an already installed package won't cause issues. - - Uninstalling a non-existent package will return a clear error. - -## Contributing - -We welcome contributions to `pipmanager`! Follow these steps to contribute: - -1. Fork the repository on GitHub. -2. Clone your fork: - - ```bash - git clone https://github.com/HamadMulti/devops-lab.git - ``` - -3. **Set Up a Virtual Environment**: - - ```bash - python -m venv venv - source venv/bin/activate # or venv\Scripts\activate on Windows - ``` - -4. **Install Dependencies**: - - ```bash - pip install -r requirements.txt - ``` - -5. Create a feature branch: - ```bash - git checkout -b feature/your-feature - ``` -6. Make changes and write tests. -7. Push your branch: - ```bash - git push origin feature/your-feature - ``` -8. Open a pull request on the main repository. - -## Testing - -To run the tests, use the following command: - -```bash -pytest tests/ -``` - -## License - -This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details. - -## Examples - -### CLI Example - -```bash -# Check installed packages -pipmanager list - -# Check outdated packages -pipmanager outdated - -# Install Flask -pipmanager install --package flask - -# Uninstall Flask -pipmanager uninstall --package flask - -# Upgrade all outdated packages -pipmanager upgrade-all -``` - -### Python Script Example - -```python -from pipmanager import PipManager - -# Check for updates -PipManager.check_updates() - -# Install Flask -PipManager.install_package("flask") - -# Upgrade all outdated packages -PipManager.upgrade_all() -``` - -## Release Workflow - -The `main` branch always contains the production-ready code. Releases follow this workflow: - -1. Create a release branch from `master`: - ```bash - git checkout -b release/ master - ``` -2. Finalize release details (update version, changelog, etc.). -3. Merge the release branch into `main` and tag it: - ```bash - git checkout main - git merge release/ - git tag -a v -m "Release " - git push origin main --tags - ``` -4. Merge the release branch back into `master`: - ```bash - git checkout develop - git merge release/ - git push origin develop - ``` - -## Future Enhancements - -- Add support for virtual environments. -- Enable rollback of package changes. -- Improve support for dependency resolution. - -## Support - -For any questions or issues, feel free to: - -- Open a GitHub issue in the repository. -- Contact the maintainers directly. diff --git a/pipmanager/pipmanager.egg-info/SOURCES.txt b/pipmanager/pipmanager.egg-info/SOURCES.txt index 765cb03..e1f5185 100644 --- a/pipmanager/pipmanager.egg-info/SOURCES.txt +++ b/pipmanager/pipmanager.egg-info/SOURCES.txt @@ -2,6 +2,7 @@ README.md setup.py pipmanager/__init__.py pipmanager/core.py +pipmanager/manager.py pipmanager.egg-info/PKG-INFO pipmanager.egg-info/SOURCES.txt pipmanager.egg-info/dependency_links.txt diff --git a/pipmanager/pipmanager.egg-info/entry_points.txt b/pipmanager/pipmanager.egg-info/entry_points.txt index 36e331e..4870a2c 100644 --- a/pipmanager/pipmanager.egg-info/entry_points.txt +++ b/pipmanager/pipmanager.egg-info/entry_points.txt @@ -1,2 +1,3 @@ [console_scripts] pipmanager = cli:main + diff --git a/pipmanager/pipmanager/core.py b/pipmanager/pipmanager/core.py index 0310255..0ac0564 100644 --- a/pipmanager/pipmanager/core.py +++ b/pipmanager/pipmanager/core.py @@ -10,13 +10,13 @@ class PipManager: def list_packages(): """List all installed pip packages.""" logging.info("Fetching the list of installed packages...") - subprocess.run([sys.executable, "-m", "pip", "list"]) + return subprocess.run([sys.executable, "-m", "pip", "list"]) @staticmethod def check_updates(): """Check for outdated pip packages.""" logging.info("Checking for outdated packages...") - subprocess.run([sys.executable, "-m", "pip", "list", "--outdated"]) + return subprocess.run([sys.executable, "-m", "pip", "list", "--outdated"]) @staticmethod def install_package(package_name): diff --git a/pipmanager/pipmanager/manager.py b/pipmanager/pipmanager/manager.py new file mode 100644 index 0000000..80e8cd1 --- /dev/null +++ b/pipmanager/pipmanager/manager.py @@ -0,0 +1,49 @@ +import subprocess + +class PipManager: + @staticmethod + def list_packages(): + result = subprocess.run( + ["pip", "list"], capture_output=True, text=True + ) + return result.stdout + + @staticmethod + def check_updates(): + result = subprocess.run( + ["pip", "list", "--outdated"], capture_output=True, text=True + ) + return result.stdout + + @staticmethod + def install_package(package_name): + result = subprocess.run( + ["pip", "install", package_name], capture_output=True, text=True + ) + return result.stdout + + @staticmethod + def uninstall_package(package_name): + result = subprocess.run( + ["pip", "uninstall", "-y", package_name], capture_output=True, text=True + ) + return result.stdout + + @staticmethod + def upgrade_all(): + result = subprocess.run( + ["pip", "list", "--outdated"], capture_output=True, text=True + ) + outdated_packages = result.stdout.splitlines() + + upgrade_messages = [] + for package in outdated_packages: + package_name = package.split()[0] + upgrade_result = subprocess.run( + ["pip", "install", "--upgrade", package_name], + capture_output=True, + text=True + ) + upgrade_messages.append(upgrade_result.stdout) + + return "\n".join(upgrade_messages) diff --git a/pipmanager/tests/test_pipmanager.py b/pipmanager/tests/test_pipmanager.py index d31d73c..acf365d 100644 --- a/pipmanager/tests/test_pipmanager.py +++ b/pipmanager/tests/test_pipmanager.py @@ -1,64 +1,40 @@ import subprocess -import pytest -from pipmanager.core import PipManager +from pipmanager.manager import PipManager +from unittest.mock import patch -@pytest.fixture -def mock_subprocess_run(mocker): - """Fixture to mock subprocess.run.""" - return mocker.patch("subprocess.run") +class TestPipManager: -def test_list_packages(mock_subprocess_run): - mock_subprocess_run.return_value = subprocess.CompletedProcess( - args=["pip", "list"], returncode=0, stdout="package1 1.0.0\npackage2 2.0.0\n" - ) - result = PipManager.list_packages() - assert result == "package1 1.0.0\npackage2 2.0.0\n" + @patch('subprocess.run') + def test_list_packages(self, mock_subprocess): + mock_subprocess.return_value.stdout = "package1 1.0.0\npackage2 2.0.0\n" + result = PipManager.list_packages() + assert result == "package1 1.0.0\npackage2 2.0.0\n" -def test_check_updates(mock_subprocess_run): - mock_subprocess_run.return_value = subprocess.CompletedProcess( - args=["pip", "list", "--outdated"], - returncode=0, - stdout="package1 1.0.0 1.1.0\npackage2 2.0.0 2.1.0\n", - ) - result = PipManager.check_updates() - assert result == "package1 1.0.0 1.1.0\npackage2 2.0.0 2.1.0\n" + @patch('subprocess.run') + def test_check_updates(self, mock_subprocess): + mock_subprocess.return_value.stdout = "package1 1.0.0 1.1.0\npackage2 2.0.0 2.1.0\n" + result = PipManager.check_updates() + assert result == "package1 1.0.0 1.1.0\npackage2 2.0.0 2.1.0\n" -def test_install_package(mock_subprocess_run): - mock_subprocess_run.return_value = subprocess.CompletedProcess( - args=["pip", "install", "example-package"], - returncode=0, - stdout="Successfully installed example-package", - ) - result = PipManager.install_package("example-package") - assert result == "Successfully installed example-package" + @patch('subprocess.run') + def test_install_package(self, mock_subprocess): + mock_subprocess.return_value.stdout = "Successfully installed example-package" + result = PipManager.install_package("example-package") + assert result == "Successfully installed example-package" -def test_uninstall_package(mock_subprocess_run): - mock_subprocess_run.return_value = subprocess.CompletedProcess( - args=["pip", "uninstall", "-y", "example-package"], - returncode=0, - stdout="Successfully uninstalled example-package", - ) - result = PipManager.uninstall_package("example-package") - assert result == "Successfully uninstalled example-package" - -def test_upgrade_all(self, mock_subprocess): - mock_subprocess.return_value = subprocess.CompletedProcess( - args=["pip", "list", "--outdated"], - returncode=0, - stdout="package1 1.0.0 1.1.0\npackage2 2.0.0 2.1.0\n", - ) - mock_subprocess.side_effect = [ - subprocess.CompletedProcess( - args=["pip", "install", "--upgrade", "package1"], - returncode=0, - stdout="Successfully upgraded package1", - ), - subprocess.CompletedProcess( - args=["pip", "install", "--upgrade", "package2"], - returncode=0, - stdout="Successfully upgraded package2", - ), - ] - result = PipManager.upgrade_all() - assert result == "Successfully upgraded package1\nSuccessfully upgraded package2" + @patch('subprocess.run') + def test_uninstall_package(self, mock_subprocess): + mock_subprocess.return_value.stdout = "Successfully uninstalled example-package" + result = PipManager.uninstall_package("example-package") + assert result == "Successfully uninstalled example-package" + @patch('subprocess.run') + def test_upgrade_all(self, mock_subprocess): + mock_subprocess.side_effect = [ + # First call to list outdated packages + subprocess.CompletedProcess(args=["pip", "list", "--outdated"], returncode=0, stdout="package1 1.0.0 1.1.0\n"), + # Next calls for upgrading packages + subprocess.CompletedProcess(args=["pip", "install", "--upgrade", "package1"], returncode=0, stdout="Successfully upgraded package1") + ] + result = PipManager.upgrade_all() + assert result == "Successfully upgraded package1"