From 9df002e57ee8436bab2ef6f32d665ace56bbbb86 Mon Sep 17 00:00:00 2001 From: "Viktor A. Rozenko Voitenko" Date: Sat, 8 Apr 2023 01:02:54 -0400 Subject: [PATCH] feat(setuptools): add find_requirements function find_requirements utility function is supposed to simplify integration between `pipenv` and `setup.py` scripts. Instead of synchronizing them manually, users could just ```python # file: setup.py from setuptools import setup, find_packages from pipenv.setuptools import find_requirements setup( name="very-nice-package", version="0.1.0", author="John Doe", description="The Nicest Package", url="https://example.com/very-nice-package", python_requires=">=3.9, <4", packages=find_packages(), install_requires=find_requirements(), ) ``` This would fetch requirements from Pipfile.lock every time they run ```bash pip install . ``` --- pipenv/setuptools.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 pipenv/setuptools.py diff --git a/pipenv/setuptools.py b/pipenv/setuptools.py new file mode 100644 index 0000000000..9a4329f933 --- /dev/null +++ b/pipenv/setuptools.py @@ -0,0 +1,7 @@ +import json + + +def find_requirements(lockfile_path: str = "Pipfile.lock"): + with open(lockfile_path) as lockfile: + requirements: dict[str, dict] = json.load(lockfile)["default"] + return [name + info["version"] for name, info in requirements.items()]