Skip to main content

A library for generating flexible Python requirements

Project description

Flexible Requirements Generator

This tool generates a flexible requirements.txt file from an existing one, helping to resolve version conflicts and compatibility issues in Python projects.

Features

  • Checks package compatibility with PyPI without installing packages
  • Supports both concurrent and sequential processing
  • Keeps compatible requirements, loosens incompatible ones, and comments out unavailable packages
  • Provides detailed information about each requirement's status
  • Handles platform-specific package availability
  • Includes comprehensive logging for better visibility and debugging

Installation

  1. Clone this repository:
    git clone https://github.com/yourusername/flexible-requirements-generator.git
    cd flexible-requirements-generator
    
  2. Install the required dependencies:
    pip install requests packaging
    

Usage

Run the script from the command line:

python flexible_requirements.py [input_file] [output_file] [--sequential] [--log {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
  • input_file: Path to the input requirements file (default: requirements.txt)
  • output_file: Path to the output flexible requirements file (default: flexible_requirements.txt)
  • --sequential: Use sequential processing instead of concurrent (optional)
  • --log: Set the logging level (default: INFO)

Example:

python flexible_requirements.py my_requirements.txt my_flexible_requirements.txt --sequential --log DEBUG

How it works

  1. The script reads the input requirements file.
  2. For each requirement, it checks the package's availability and version compatibility using the PyPI JSON API.
  3. It considers the current platform (e.g., Windows, Linux, macOS) when checking for compatible versions.
  4. Based on the results, it either:
    • Keeps the requirement as-is if it's compatible
    • Loosens the version constraint if no compatible version is found for the current platform
    • Comments out the requirement if the package is not available on PyPI or for the current platform
  5. The processed requirements are written to the output file with explanatory comments.
  6. Detailed logs are provided throughout the process for better visibility and debugging.

Output

The generated flexible requirements file includes:

  • The original requirements (kept, loosened, or commented out)
  • Comments explaining the status of each requirement
  • Information about compatible versions or reasons for changes

Performance

The script supports both concurrent and sequential processing. Concurrent processing is faster but may be limited by API rate limits. Sequential processing is slower but more reliable for large requirement files.

Limitations

  • Relies on the PyPI JSON API, so it requires an internet connection
  • Does not handle dependencies of packages, only direct requirements
  • May be affected by PyPI API rate limits when processing large files concurrently
  • Platform-specific package availability may result in different outputs on different systems

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

flexible_requirements-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

flexible_requirements-0.1.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file flexible_requirements-0.1.0.tar.gz.

File metadata

  • Download URL: flexible_requirements-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for flexible_requirements-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d320376b032386d6912ebab77d07ba98e6bc030717fea5a16fe081bde058fc71
MD5 b27e76ef78c6f0c7c10657fe5d289f1d
BLAKE2b-256 a81d8847d9abc07292ed42a3ea8fdb9b6f73a89b7859bc747ae2afddc15c26be

See more details on using hashes here.

File details

Details for the file flexible_requirements-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for flexible_requirements-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b39a21090f1045d978db7c65d2e33d30f76eea717bb21d1db8f6d0c7a357ccd8
MD5 f63015593254cd76d55ab94e578b535b
BLAKE2b-256 15c65e6f6681654b12fc2d37d84e6a70a920e28c392e3ac5a2adf2dfc33755d4

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