Skip to main content

Guess requirements.txt versions based on Git history

Project description

Python-Requirements-Guesser

⚠️ This is alpha quality software. Work in progress

Attempt to guess requirements.txt modules versions based on Git history.

What is the problem ?

Did you ever clone a repo with python code that didn't specify library versions in a requirements.txt file ? Or even worst: a repo without a requirements.txt...

Reproducing results is hard, it's even harder when you have mismatched library versions.

Solution

There is a fair chance that the owner of the repo you just cloned installed most of it's packages using

pip install <package name>

This would have installed the latest available version at the time the command was runned.

Based on this, we look at the git commit history to find out when a package was first imported in the code or when it was first added to the requirements.txt file.

We then query Pypi to retrieve the version available at the commit date.

Usage

Py-Requirements-Guesser should be runned inside a git repository.

py-requirements-guesser --write {requirements.txt path}

You will be prompted by a serie of choice to orient the guessing process.

Python Requirements Guesser

Installation

This package doesn't have any dependencies. To install the Py-Requirements-Guesser:

pip3 install py-requirements-guesser

Package name mapping - Pipreqs

There might be mismatches between the name of a package on Pypi and the name used to import it (Ex : pip install PyYAML & import yaml ). There doesn't seem to be a straightforward way to do the mapping between Pypi name and import name.

The great PipReqs package (which was an inspiration for this package) manually maintains a mapping file between Pypi names and the import names. They also maintain a list of the standard library module names.

For now, we grab the mapping and stdlib files at commit 90102acdbb23c09574d27df8bd1f568d34e0cfd3.

Thanks guys !

Additional arguments

Py-Requirements-Guesser can take 2 additional parameters :

--keep_unused_packages: By default, unused packages are ignored. This parameter will force version guessing for the packages in requirements.txt that are not imported in the code anywhere.

--force_guess {package1},{package2},..: By default, if your code contains a module named yaml.py, import yaml statements won't be analyzed. Use this argument if local modules have conflicting names with Pypi packages to force version guessing.

TODO

  • Guess/Pin the dependencies tree of the package Ex : Torch package will install numpy, etc
  • Poetry support ?
  • Jupyter notebook support
  • Add guessing choice where user can choose version between the time the package was first imported and the date of the last commit on a python file
  • Detect python & os versions. Some package versions might not be available for certain os or python versions
  • Better output/UX

License

GNU GPLV3 see License

Contributing

Pull requests are welcomed ! Fill up an issue if you encounter any problem !

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

py-requirements-guesser-0.1.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_requirements_guesser-0.1.0-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file py-requirements-guesser-0.1.0.tar.gz.

File metadata

  • Download URL: py-requirements-guesser-0.1.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.9

File hashes

Hashes for py-requirements-guesser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e7e7d1fff65733f2736e22d9a51926f9bb32006ecdf7453f77aec14cb79696a8
MD5 59c95e6edcbac471cce9435438516860
BLAKE2b-256 44edfb88075be6acc9d9b690555ad72ee0fba181fcec03c38e98dc3cdf62bc37

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_requirements_guesser-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.9

File hashes

Hashes for py_requirements_guesser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 130ae21072c4d895c067391bbabafbdbe10cbf325c3032871330453ccfd0d8f7
MD5 e3d0294fc9eb4c6d2a989d54dc7b7195
BLAKE2b-256 69934e2630c78c7001e5db99ccf059daa47b9e6f4fe48511b07d5dfc16e6496a

See more details on using hashes here.

Supported by

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