Skip to content

Latest commit

 

History

History
67 lines (49 loc) · 2 KB

README.md

File metadata and controls

67 lines (49 loc) · 2 KB

Python Requirements Updater

Not a pur, but pru. Update and resolve requirements.txt based on the Python environment and pip used. Unlike Poetry and other dependencies management packages, you can use pru outside your project and exclude it from your project dependency. Just run pru whenever you feel like installing the latest package and update requirements.txt accordingly.

Installation

pip install pru

Usage

Using CLI:

pru

Explicit run using CLI:

pru "requirements.txt" upgrade_requirements --cmd "pip install --upgrade"

Using python:

from pru import (
    get_installed_requirements_packages_and_version,
    get_installed_packages_name_and_version,
    replace_requirements_packages_versions,
    upgrade_requirements,
)


file_path = 'requirements.txt'
# print(get_installed_requirements_packages_and_version(file_path))
# print(get_installed_packages_name_and_version())
# replace_requirements_packages_versions(file_path)
upgrade_requirements(file_path, command='pip install --upgrade')

Very useful on workflow:

      - name: Upgrade pip and install dependencies
        run: |
          python -m pip install --upgrade pip
          pru

Or to debug installed package on workflow:

      - name: Run pru if tests fail
        if: steps.pytest.outcome != 'success'
        run: |
          python_version_minor=$(python -c "import sys; print(f'{sys.version_info.minor}')")
          pru -r pytests/requirements/3_${python_version_minor}/requirements.txt
          echo "Contents of pytests/requirements/3_${python_version_minor}/requirements.txt:"
          cat pytests/requirements/3_${python_version_minor}/requirements.txt

Known Issue

In python3.7, pru "sometimes" can't install and update requirements using a single call of upgrade_requirements. To fix this, simply run two times.