All Projects → sarugaku → requirementslib

sarugaku / requirementslib

Licence: MIT License
A tool for converting between pip-style and pipfile requirements - maintained by the pipenv team

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to requirementslib

passa
Resolver implementation and toolset for generating and interacting with Pipfile and Pipfile.lock.
Stars: ✭ 54 (-27.03%)
Mutual labels:  pip, pipfile, requirements, pipenv
Dephell
📦 🔥 Python project management. Manage packages: convert between formats, lock, install, resolve, isolate, test, build graph, show outdated, audit. Manage venvs, build package, bump version.
Stars: ✭ 1,730 (+2237.84%)
Mutual labels:  pip, pipfile, pipenv
serverless-python-requirements
⚡️🐍📦 Serverless plugin to bundle Python packages
Stars: ✭ 971 (+1212.16%)
Mutual labels:  pip, requirements, pipenv
resolvelib
Resolve abstract dependencies into concrete ones
Stars: ✭ 92 (+24.32%)
Mutual labels:  pip, requirements, pipenv
ochrona-cli
A command line tool for detecting vulnerabilities in Python dependencies and doing safe package installs
Stars: ✭ 46 (-37.84%)
Mutual labels:  pip, pipfile, requirements
pipfile-requirements
A CLI tool to covert Pipfile/Pipfile.lock to requirments.txt
Stars: ✭ 47 (-36.49%)
Mutual labels:  pipfile, pipenv
Pip Tools
A set of tools to keep your pinned Python dependencies fresh.
Stars: ✭ 5,387 (+7179.73%)
Mutual labels:  pip, requirements
Pipenv
Python Development Workflow for Humans.
Stars: ✭ 22,542 (+30362.16%)
Mutual labels:  pip, pipfile
Coronavirus Tracker Api
🦠 A simple and fast (< 200ms) API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak. It's written in python using the 🔥 FastAPI framework. Supports multiple sources!
Stars: ✭ 1,577 (+2031.08%)
Mutual labels:  pip, pipenv
index
A PEP 503-compliant Python package index specifically providing wheels built for Alpine Linux
Stars: ✭ 26 (-64.86%)
Mutual labels:  pip, pipenv
rfc-bibtex
A command line tool that creates bibtex entries for IETF RFCs and Internet Drafts.
Stars: ✭ 43 (-41.89%)
Mutual labels:  pip, pipenv
pc guidelines
Guidelines for using IvLabs PC. General instructions for maintaining and using any PC/laptop while using Ubuntu for Robotics/DL/RL research.
Stars: ✭ 23 (-68.92%)
Mutual labels:  pip
v-pip
🖼 Tiny vue wrapper for supporting native picture-in-picture mode.
Stars: ✭ 30 (-59.46%)
Mutual labels:  pip
TensorFlow-Raspberry-Pi 64-bit
TensorFlow installation wheels for Raspberry Pi 64 OS
Stars: ✭ 27 (-63.51%)
Mutual labels:  pip
project
☕️ Create node, rust, python or ruby project locally and on github (private or public)
Stars: ✭ 19 (-74.32%)
Mutual labels:  pip
rotten tomatoes cli
Rotten Tomatoes CLI
Stars: ✭ 14 (-81.08%)
Mutual labels:  pip
ausbills
🇦🇺 This is a package for obtaining parliament bills for Australian governments.
Stars: ✭ 24 (-67.57%)
Mutual labels:  pip
pip upgrade outdated
Install outdated python packages.
Stars: ✭ 62 (-16.22%)
Mutual labels:  pip
asymmetric
Ridiculously fast and easy module-to-API transformations. Learn in minutes, implement in seconds. Batteries included.
Stars: ✭ 35 (-52.7%)
Mutual labels:  pip
TyStrings
strings file tool for iOS / macOS developers
Stars: ✭ 15 (-79.73%)
Mutual labels:  pip

RequirementsLib: Requirement Management Library for Pip and Pipenv

Documentation Status

🐉 Installation

Install from PyPI:

$ pipenv install requirementslib

Install from Github:

$ pipenv install -e git+https://github.com/sarugaku/requirementslib.git#egg=requirementslib

🐉 Summary

RequirementsLib provides a simple layer for building and interacting with requirements in both the Pipfile format and the requirements.txt format. This library was originally built for converting between these formats in Pipenv.

🐉 Usage

Importing a lockfile into your setup.py file

You can use RequirementsLib to import your lockfile into your setup file for including your install_requires dependencies:

from requirementslib import Lockfile
lockfile = Lockfile.create('/path/to/project/dir')
install_requires = lockfile.as_requirements(dev=False)

Interacting with a Pipfile directly

You can also interact directly with a Pipfile:

>>> from requirementslib import Pipfile
>>> pf = Pipfile.load('/home/hawk/git/pypa-pipenv')
>>> pf.sections
[Section(name='packages', requirements=[]), Section(name='dev-packages', requirements=[Requirement(name='pipenv', vcs=None, req=FileRequirement(setup_path=None, path='.', editable=True, uri='file:///home/hawk/git/pypa-pipenv', link=<Link file:///home/hawk/git/pypa-pipenv>, name='pipenv', req=<Requirement: "-e file:///home/hawk/git/pypa-pipenv">), markers='', specifiers=None, index=None, editable=True, hashes=[], extras=None),...]

And you can even write it back out into Pipfile's native format:

>>> print(pf.dump(to_dict=False))
[packages]

[dev-packages]
pipenv = {path = ".", editable = true}
flake8 = ">=3.3.0,<4"
pytest = "*"
mock = "*"

[scripts]
tests = "bash ./run-tests.sh"

[pipenv]
allow_prereleases = true

Create a requirement object from requirements.txt format

>>> from requirementslib import Requirement
>>> r = Requirement.from_line('-e git+https://github.com/pypa/pipenv.git@master#egg=pipenv')
>>> print(r)
Requirement(name='pipenv', vcs='git', req=VCSRequirement(editable=True, uri='git+https://github.com/pypa/pipenv.git', path=None, vcs='git', ref='master', subdirectory=None, name='pipenv', link=<Link git+https://github.com/pypa/pipenv.git@master#egg=pipenv>, req=<Requirement: "-e git+https://github.com/pypa/pipenv.git@master#egg=pipenv">), markers=None, specifiers=None, index=None, editable=True, hashes=[], extras=[])

>>> r.as_pipfile()
{'pipenv': {'editable': True, 'ref': 'master', 'git': 'https://github.com/pypa/pipenv.git'}}

Or move from Pipfile format to requirements.txt:

>>> r = Requirement.from_pipfile(name='pythonfinder', indexes=[], pipfile={'path': '../pythonfinder', 'editable': True})
>>> r.as_line()
'-e ../pythonfinder'

Resolving Editable Package Dependencies

Requirementslib also can resolve the dependencies of editable packages by calling the run_requires method. This method returns a detailed dictionary containing metadata parsed from the package built in a transient folder (unless it is already on the system or the call is run in a virtualenv).

The output of run_requires is very detailed and in most cases will be sufficient:

>>> from pprint import pprint
>>> from requirementslib.models.requirements import Requirement
>>> r = Requirement.from_line("-e [email protected]:sarugaku/vistir.git#egg=vistir[spinner]")
>>> setup_info_dict = r.run_requires()
>>> from pprint import pprint
>>> pprint(setup_info_dict)
{'base_dir': '/tmp/requirementslib-t_ftl6no-src/src/vistir',
'build_backend': 'setuptools.build_meta',
'build_requires': ['setuptools>=36.2.2', 'wheel>=0.28.0'],
'extra_kwargs': {'build_dir': '/tmp/requirementslib-t_ftl6no-src/src',
                'download_dir': '/home/hawk/.cache/pipenv/pkgs',
                'src_dir': '/tmp/requirementslib-t_ftl6no-src/src',
                'wheel_download_dir': '/home/hawk/.cache/pipenv/wheels'},
'extras': {'spinner': [Requirement.parse('cursor'),
                        Requirement.parse('yaspin')],
            'tests': [Requirement.parse('pytest'),
                    Requirement.parse('pytest-xdist'),
                    Requirement.parse('pytest-cov'),
                    Requirement.parse('pytest-timeout'),
                    Requirement.parse('hypothesis-fspaths'),
                    Requirement.parse('hypothesis')]},
'ireq': <InstallRequirement object: vistir[spinner] from git+ssh://[email protected]/sarugaku/vistir.git#egg=vistir editable=True>,
'name': 'vistir',
'pyproject': PosixPath('/tmp/requirementslib-t_ftl6no-src/src/vistir/pyproject.toml'),
'python_requires': '>=2.6,!=3.0,!=3.1,!=3.2,!=3.3',
'requires': {'backports.functools_lru_cache;python_version<="3.4"': Requirement.parse('backports.functools_lru_cache; python_version <= "3.4"'),
            'backports.shutil_get_terminal_size;python_version<"3.3"': Requirement.parse('backports.shutil_get_terminal_size; python_version < "3.3"'),
            'backports.weakref;python_version<"3.3"': Requirement.parse('backports.weakref; python_version < "3.3"'),
            'colorama': Requirement.parse('colorama'),
            'pathlib2;python_version<"3.5"': Requirement.parse('pathlib2; python_version < "3.5"'),
            'requests': Requirement.parse('requests'),
            'six': Requirement.parse('six'),
            'spinner': [Requirement.parse('cursor'),
                        Requirement.parse('yaspin')]},
'setup_cfg': PosixPath('/tmp/requirementslib-t_ftl6no-src/src/vistir/setup.cfg'),
'setup_py': PosixPath('/tmp/requirementslib-t_ftl6no-src/src/vistir/setup.py')}

As a side-effect of calls to run_requires, new metadata is made available on the requirement itself via the property requirement.req.dependencies:

>>> pprint(r.req.dependencies)
({'backports.functools_lru_cache;python_version<="3.4"': Requirement.parse('backports.functools_lru_cache; python_version <= "3.4"'),
'backports.shutil_get_terminal_size;python_version<"3.3"': Requirement.parse('backports.shutil_get_terminal_size; python_version < "3.3"'),
'backports.weakref;python_version<"3.3"': Requirement.parse('backports.weakref; python_version < "3.3"'),
'colorama': Requirement.parse('colorama'),
'pathlib2;python_version<"3.5"': Requirement.parse('pathlib2; python_version < "3.5"'),
'requests': Requirement.parse('requests'),
'six': Requirement.parse('six'),
'spinner': [Requirement.parse('cursor'), Requirement.parse('yaspin')]},
[],
['setuptools>=36.2.2', 'wheel>=0.28.0'])

🐉 Integrations

🐉 Contributing

  1. Fork the repository and clone the fork to your local machine: git clone [email protected]:yourusername/requirementslib.git
  2. Move into the repository directory and update the submodules: git submodule update --init --recursive
  3. Install the package locally in a virtualenv using pipenv: pipenv install --dev
    1. You can also install the package into a virtualenv by running pip install -e .[dev,tests,typing] to ensure all the development and test dependencies are installed
  4. Before making any changes to the code, make sure to file an issue. The best way to ensure a smooth collaboration is to communicate before investing significant time and energy into any changes! Make sure to consider not just your own use case but others who might be using the library
  5. Create a new branch. For bugs, you can simply branch to bugfix/<issuenumber>. Features can be branched to feature/<issuenumber>. This convention is to streamline the branching process and to encourage good practices around filing issues and associating pull requests with specific issues. If you find yourself addressing many issues in one pull request, that should give you pause
  6. Make your desired changes. Don't forget to add additional tests to account for your new code -- continuous integration will fail without it
  7. Test your changes by running pipenv run pytest -ra tests or simply pytest -ra tests if you are inside an activated virtual environment
  8. Create a corresponding .rst file in the news directory with a one sentence description of your change, e.g. Resolved an issue which sometimes prevented requirements from being converted from Pipfile entries to pip lines correctly
  9. Commit your changes. The first line of your commit should be a summary of your changes, no longer than 72 characters, followed by a blank line, followed by a bulleted description of your changes. Don't forget to add separate lines with the phrase - Fixes #<issuenumber> for each issue you are addressing in your pull request
  10. Before submitting your pull request, make sure to git remote add upstream [email protected]:sarugaku/requirementslib.git and then git fetch upstream && git pull upstream master to ensure your code is in sync with the latest version of the master branch,
  11. Create a pull request describing your fix, referencing the issues in question. If your commit message from step 8 was detailed, you should be able to copy and paste it
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].