Skip to content

Commit a3a3e4e

Browse files
committed
Added command to install requirements
1 parent afd1020 commit a3a3e4e

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

README.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ The project has been tested in the following versions of the interpreter:
5555
- Python 3.6
5656

5757
All other dependencies are indicated on the requirements.txt file.
58-
The included makefile can install them with the command:
5958

60-
``$ make requirements``
59+
These can be installed with:
60+
61+
``$ python setup.py requirements``
6162

6263
Installing
6364
~~~~~~~~~~

setup.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from setuptools import find_packages, setup
1111
from setuptools.command.test import test as test_command
12+
from distutils.cmd import Command
1213

1314
"""
1415
PyPI configuration module.
@@ -35,6 +36,7 @@ def read(*names, **kwargs):
3536
encoding=kwargs.get('encoding', 'utf8')
3637
).read()
3738

39+
3840
# Gets the version for the source folder __init__.py file
3941
with open(_source_package + '/__init__.py', 'rb', encoding='utf-8') as f:
4042
version_lib = f.read()
@@ -71,6 +73,34 @@ def run_tests(self):
7173
sys.exit(errcode)
7274

7375

76+
class _RequirementsCommand(Command):
77+
"""
78+
Requirements command.
79+
80+
Installs all the requirements defined in the requirements file with pip.
81+
"""
82+
description = 'install the requirements defined in requirements.txt'
83+
user_options = []
84+
85+
def initialize_options(self):
86+
pass
87+
88+
def finalize_options(self):
89+
pass
90+
91+
def run(self):
92+
# import here, cause outside the eggs aren't loaded
93+
import pip
94+
95+
with open('requirements.txt') as f:
96+
requirements = f.read().splitlines()
97+
98+
requirements = filter(lambda k: bool(k.strip()), requirements)
99+
requirements = filter(lambda k: not k.strip().startswith('#'), requirements)
100+
101+
for requirement in requirements:
102+
pip.main(['install', requirement])
103+
74104
setup(
75105
name='dice-notation',
76106
packages=find_packages(),
@@ -103,5 +133,8 @@ def run_tests(self):
103133
],
104134
tests_require=_tests_require,
105135
extras_require={'test': _tests_require},
106-
cmdclass={'test': _ToxTester},
136+
cmdclass={
137+
'test': _ToxTester,
138+
'requirements': _RequirementsCommand
139+
},
107140
)

0 commit comments

Comments
 (0)