From 9b4ab3589c2d4a9f6c5f827974d54853c1123cb0 Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Sat, 21 Aug 2021 17:27:47 +0200 Subject: [PATCH] Added install_requires to setup.py #515 (#600) --- MANIFEST.in | 1 + MANIFEST.test_data.in | 1 + setup.py | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/MANIFEST.in b/MANIFEST.in index 72ddd680..fad95587 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,7 @@ include ACKNOWLEDGEMENTS AUTHORS LICENSE README include dependencies.ini run_tests.py utils/__init__.py utils/dependencies.py include utils/check_dependencies.py +include requirements.txt test_requirements.txt exclude .gitignore exclude *.pyc recursive-include config * diff --git a/MANIFEST.test_data.in b/MANIFEST.test_data.in index 7e5cec72..acfc3a86 100644 --- a/MANIFEST.test_data.in +++ b/MANIFEST.test_data.in @@ -1,6 +1,7 @@ include ACKNOWLEDGEMENTS AUTHORS LICENSE README include dependencies.ini run_tests.py utils/__init__.py utils/dependencies.py include utils/check_dependencies.py +include requirements.txt test_requirements.txt exclude .gitignore exclude *.pyc recursive-include config * diff --git a/setup.py b/setup.py index a415642d..be7073f7 100755 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- """Installation and deployment script.""" +import pkg_resources import sys try: @@ -156,6 +157,30 @@ def _make_spec_file(self): return python_spec_file +def parse_requirements_from_file(path): + """Parses requirements from a requirements file. + + Args: + path (str): path to the requirements file. + + Yields: + str: name and optional version information of the required package. + """ + with open(path, 'r') as file_object: + file_contents = file_object.read() + + for requirement in pkg_resources.parse_requirements(file_contents): + try: + name = str(requirement.req) + except AttributeError: + name = str(requirement) + + if name.startswith('pip '): + continue + + yield name + + dfvfs_description = ( 'Digital Forensics Virtual File System (dfVFS).') @@ -200,4 +225,6 @@ def _make_spec_file(self): ('share/doc/dfvfs', [ 'ACKNOWLEDGEMENTS', 'AUTHORS', 'LICENSE', 'README']), ], + install_requires=parse_requirements_from_file('requirements.txt'), + tests_require=parse_requirements_from_file('test_requirements.txt'), )