99
1010from setuptools import find_packages , setup
1111from setuptools .command .test import test as test_command
12+ from distutils .cmd import Command
1213
1314"""
1415PyPI 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
3941with 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+
74104setup (
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