damnever / pigar

:coffee: A tool to generate requirements.txt for Python project, and more than that. (IT IS NOT A PACKAGE MANAGEMENT TOOL)
https://damnever.github.io/pigar/
BSD 3-Clause "New" or "Revised" License
1.61k stars 90 forks source link
denpendenies distribution-search importerror pip pypi python requirements

pigar

NOTE: Pipenv or other tools is recommended for improving your development flow.

Installation

pigar can run on Python 3.7+.

To install it with pip, use:

[sudo] pip install pigar

To install it with conda, use:

conda install -c conda-forge pigar

To get the newest code from GitHub:

pip install git+https://github.com/damnever/pigar.git@[main or other branch] --upgrade

Usage

EXPERIMENTAL FEATURES

FAQ

Is `pigar` a dependency management tool? **No.** I've thought about this many times, but there is too much dirty work to be done to make `pigar`'s way reliable. I like the way `pigar` does the job, but sadly, `pigar` does a bad job of managing dependencies, `pigar` is more like a tool to assist an old project to migrate to a new development workflow.
(1) Why does `pigar` show multiple packages/distributions for the same import name? (2) Why does `pigar` generate different packages/distributions for the same import name in different environment? `pigar` can not handle those situations gracefully, you may need to remove the duplicate packages in requirements.txt manually, or select one of them when `pigar` asks you. Install the required packages/distributions(remove others) in local environment should fix it as well. Related issues: [#32](https://github.com/damnever/pigar/issues/32), [#68](https://github.com/damnever/pigar/issues/68), [#75](https://github.com/damnever/pigar/issues/75#issuecomment-605639825).
Why can't `pigar` find the packages/distributions that have not been explicit import? Some frameworks may use some magic to import the modules for users automatically, and `pigar` can not handle it, you may need to fix it manually or use the [EXPERIMENTAL FEATURES](https://github.com/damnever/pigar#experimental-features). Related issues: [#33](https://github.com/damnever/pigar/issues/33), [#103](https://github.com/damnever/pigar/issues/103)

More

pigar does not use regular expressions in such a violent way. Instead, it uses AST, which is a better method for extracting imported names from arguments of exec/eval/importlib, doctest of docstring, etc. However, pigar can not solve all the tricky problems, see FAQ.

Also, pigar can detect the difference between different Python versions. For example, you can find concurrent.futures from the Python 3.2 standard library, but you will need install futures in earlier versions of Python to get concurrent.futures, this is not a hardcode.

If you have any issues or suggestions, please submit an issue on GitHub. All contributions are appreciated!

LICENSE

The BSD 3-Clause License