Skip to main content

A tool to check and compare dependencies(requirements.txt and so on) files for Python projects.

Project description

reqs-check

reqs-check is a tool to check and compare dependencies files(requirements.txt, pyproject.toml, etc...) for Python projects.

Installation

To install reqs-check, use pip:

pip install reqs-check

Usage

 Usage: reqs-check [OPTIONS] COMMAND [ARGS]...                                                                       
                                                                                                                     
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --install-completion          Install completion for the current shell.                                           │
│ --show-completion             Show completion for the current shell, to copy it or customize the installation.    │
│ --help                        Show this message and exit.                                                         │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ check      Check requirements files for differences or duplicates.                                                │
│ lint       Lint the requirements files for best practices.                                                        │
│ versions   Check the latest version of packages or update/add packages in a requirements file.                    │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

check

 Usage: reqs-check check [OPTIONS] FILES...                                                                          
                                                                                                                     
 Check requirements files for differences or duplicates.                                                             
                                                                                                                     
╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    files      FILES...  Paths to the requirements.txt files [default: None] [required]                          │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --diff                Show diff between files                                                                     │
│ --duplicates          Find duplicate packages in the dependencies files                                           │
│ --help                Show this message and exit.                                                                 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

lint

 Usage: reqs-check lint [OPTIONS] FILES...                                                                           
                                                                                                                     
 Lint the requirements files for best practices.                                                                     
                                                                                                                     
╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    files      FILES...  Paths to the requirements.txt files [default: None] [required]                          │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --help          Show this message and exit.                                                                       │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

versions

 Usage: reqs-check versions [OPTIONS] TARGET                                                                         
                                                                                                                     
 Check the latest version of packages or update/add packages in a requirements file.                                 
                                                                                                                     
╭─ Arguments ───────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ *    target      TEXT  Path to the requirements.txt file or package name [default: None] [required]               │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --fix   -f            Update the file with the latest versions of unversioned packages                            │
│ --add   -a      TEXT  Add packages with their latest versions to the requirements file [default: None]            │
│ --help                Show this message and exit.                                                                 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

Examples

Let's consider the following files:

requirements1.txt

pandas==1.1.5
numpy==1.19.5
scipy~=1.5.4
matplotlib==3.3.4

and

requirements2.txt

pandas==1.1.5
numpy==1.19.3
matplotlib==3.2.1
requests>=2.24.0
scipy==1.5.4
numpy==1.19
requests

Compare requirements files

Note: The files are in the directory examples/ of the github repository.

This command compares two requirements.txt files and highlights the differences.

reqs-check check requirements1.txt requirements2.txt

Output:

+------------+---------------------+---------------------+
| Package    | requirements1.txt   | requirements2.txt   |
+============+=====================+=====================+
| numpy      | ==1.19.5            | ==1.19.3            |
+------------+---------------------+---------------------+
| scipy      | ~=1.5.4             | ==1.5.4             |
+------------+---------------------+---------------------+
| matplotlib | ==3.3.4             | ==3.2.1             |
+------------+---------------------+---------------------+
| requests   | Not Present         | >=2.24.0            |
+------------+---------------------+---------------------+

Note: The values are color-coded for better readability in the terminal.

Find duplicates in requirements files

This command finds duplicated packages in the requirements.txt files(at least one).

reqs-check check --duplicates requirements1.txt requirements2.txt

Output:

🚫 Duplicates in requirements2.txt:
  numpy:
    - ==1.19.3 (line 2)
    - ==1.19 (line 6)
  requests:
    - >=2.24.0 (line 4)
    - Any (line 7)

You can see that the output shows the duplicated packages in the second file requirements2.txt while the first file requirements1.txt has no duplicated packages.

For the next examples, let's consider the following file:

requirements3.txt

pandas==1.1.5
numpy==1.19.5
scipy~=1.5.4
matplotlib==3.3.4
pandas
numpy>=1.15
-e git+https://github.com/user/repo.git#egg=package

Lint requirements files

This command checks a requirements.txt file for best practices, such as specifying version numbers and avoiding editable installs.

reqs-check lint requirements3.txt 
🚫 Issues found in requirements3.txt:
  - Line 5: 'pandas' does not specify a version.
  - Line 7: '-e git+https://github.com/user/repo.git#egg=package' does not specify a version.
  - Line 7: '-e git+https://github.com/user/repo.git#egg=package' uses editable installs, which are not recommended for production.

Check and update packages versions

  • Check the latest version of packages that you specify(comma separated)

    reqs-check versions pandas,requests
    

    Output:

    📋 Latest versions for packages:
      pandas==2.2.2
      requests==2.32.3
    
    
  • Check if there are any unversioned packages in the requirements file:

    reqs-check versions requirements3.txt
    

    Output:

    🚫 Found 1 unversioned package in requirements3.txt:
      pandas
    💡 Use the option `--fix` to update the unversioned packages in the file:
        `reqs-check versions requirements3.txt --fix`
    

Update requirements file with the latest versions

  • Fix unversioned packages in a requirements file:
    reqs-check versions requirements3.txt --fix
    
    Output:
    ✅ Fixed 1 package in requirements3.txt:
      pandas==2.2.2
    
  • Add versioned(with the latest version) packages in a requirements file:
    reqs-check versions requirements3.txt --add requests,bson
    
    Output:
    ✅ Added 3 packages to requirements3.txt:
      pandas==2.2.2
      requests==2.32.3
      bson==0.5.10
    

Next Steps

We plan to add more features to reqs-check to resolve some use cases that we've had to deal with.

Planned features

  • Support for additional file formats (e.g., Pipfile, pyproject.toml).

  • Support for additional checks (e.g., security vulnerabilities).

  • Integration with CI/CD pipelines for automated checks.

  • Detailed reports in various formats (e.g., JSON, HTML).

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reqs-check-0.3.0.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

reqs_check-0.3.0-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file reqs-check-0.3.0.tar.gz.

File metadata

  • Download URL: reqs-check-0.3.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for reqs-check-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8f20782b47dd44786ae464b3f80dc1cdf22e54216ce17da49f09d3f16105f16c
MD5 e8ac67ef2d6a47872251ae44ab2a5b16
BLAKE2b-256 93eaf59973a9bc080b1c5b1447a4ee12a49d6fffbb13c0cea1be7888d556f4bb

See more details on using hashes here.

File details

Details for the file reqs_check-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: reqs_check-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for reqs_check-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 226aacdc06f55dde1b7f786bc39a2528d601039e2d70c4e74487d7d7892c7088
MD5 45a3b9a1ac0724610b169c343f06d293
BLAKE2b-256 c32b89640f1801c95b4ba9fcafed86f99d37189b29555e36f92bd5ba9ca6479c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page