pipreqs

repository·master·Indexed 27 days ago

https://github.com/bndr/pipreqs

A tool that generates a requirements.txt file for a project by scanning its imports rather than listing all packages installed in the current environment. Version 0.5.0 supports dynamic versioning schemes (compat, gt, no-pin), Jupyter notebook scanning, and utilities to compare or clean existing requirements files.

Tokens
2K
Snippets
6
Records
14
Agent score
90%

What's inside pipreqs

  1. Install pipreqs

    master

    Install pipreqs using pip to generate requirements.txt files based on the imports used in your project.

    If you do not need support for scanning Jupyter Notebook files, you can install a minimal version without the notebook-related dependencies.

    # Standard installation
    pip install pipreqs
    
    # Minimal installation (without Jupyter Notebook support)
    pip install --no-deps pipreqs
    pip install yarg==0.1.9 docopt==0.6.2
  2. Set up pipreqs for local development

    master

    To contribute to pipreqs, follow these steps to set up your local development environment using Poetry:

    1. Fork the repository on GitHub.
    2. Clone your fork locally.
    3. Install dependencies using Poetry with the dev group.
    4. Create a new branch for your changes.

    Note: pipreqs uses Poetry for dependency management. You must have Poetry installed in your environment.

    $ git clone git@github.com:your_name_here/pipreqs.git
    $ cd pipreqs/
    $ poetry install --with dev
    $ git checkout -b name-of-your-bugfix-or-feature
  3. Verify changes with flake8, unittest, and tox

    master

    Before committing your changes, ensure they pass linting and testing. Use poetry run to execute the following commands:

    • Linting: Run flake8 on the pipreqs directory and the tests directory.
    • Unit Tests: Run the unittest discovery.
    • Multi-version Testing: Run tox to test against multiple Python versions. (It is recommended to use pyenv or asdf to manage these Python versions).

    To run only a specific subset of tests (e.g., tests.test_pipreqs), use the unittest discovery command.

    $ poetry run flake8 pipreqs tests
    $ poetry run python -m unittest discover
    $ poetry run tox
    
    # To run a subset of tests:
    $ poetry run python -m unittest tests.test_pipreqs
  4. Submit a Pull Request to pipreqs

    master

    When your changes are ready, push your branch to GitHub and submit a pull request. Ensure your PR adheres to these guidelines:

    1. Include tests: All new functionality must be accompanied by tests.
    2. Update documentation: If adding functionality, include a docstring in the new function and update the feature list in README.rst.
    3. Compatibility: Ensure the PR works for all currently supported Python and PyPy versions. Verify that tests pass on the CI (Travis CI) for all supported versions.
  5. Configure dynamic versioning with --mode

    master

    Use the --mode flag to control how versions are written to the requirements.txt file using one of the following schemes:

    • <compat>: e.g., Flask~=1.1.2
    • <gt>: e.g., Flask>=1.1.2
    • <non-pin>: e.g., Flask
  6. Reference pipreqs CLI options

    master

    The following options are available for the pipreqs command line interface:

    OptionDescription
    <path>The directory containing application files (defaults to current directory)
    --use-localUse ONLY local package info instead of querying PyPI
    --pypi-server <url>Use custom PyPi server
    --proxy <url>Use Proxy (passed to requests library)
    --debugPrint debug information
    --ignore <dirs>...Ignore extra directories, separated by commas
    --no-follow-linksDo not follow symbolic links in the project
    --ignore-errorsIgnore errors while scanning files
    --encoding <charset>Use encoding parameter for file open
    --savepath <file>Save the list of requirements in the given file
    --printOutput the list of requirements to standard output
    --forceOverwrite existing requirements.txt
    --diff <file>Compare modules in requirements.txt to project imports
    --clean <file>Clean up requirements.txt by removing modules not imported in project
    --mode <scheme>Enables dynamic versioning with <compat>, <gt> or <non-pin> schemes
    --scan-notebooksLook for imports in jupyter notebook files
  7. Configure dynamic versioning schemes in pipreqs

    master

    When generating requirements, you can control how versions are pinned using the --mode flag. This is useful for creating more flexible dependency files.

    SchemeResult ExampleDescription
    compatFlask~=1.1.2Uses compatible release specifier.
    gtFlask>=1.1.2Uses greater-than-or-equal-to specifier.
    no-pinFlaskDoes not include any version pinning.