11"""setup.py file."""
2+ import napalm
3+
24import uuid
35
6+ from distutils .core import Command
47from setuptools import setup , find_packages
8+ from setuptools .command import install
9+
10+
511from pip .req import parse_requirements
6- from itertools import chain
712
13+ import pip
814import sys
915
10- __author__ = 'David Barroso <[email protected] >' 1116
17+ __author__ = 'David Barroso <[email protected] >' 1218
13- def extract_drivers (opt ):
14- return set ([r .replace ("--drivers=" , "" ).strip () for r in opt .split ("," )])
1519
20+ def process_requirements (dep ):
21+ print ("PROCESSING DEPENDENCIES FOR {}" .format (dep ))
22+ u = uuid .uuid1 ()
23+ iter_reqs = parse_requirements ("requirements/{}" .format (dep ), session = u )
24+ [pip .main (['install' , (str (ir .req ))]) for ir in iter_reqs ]
1625
17- def process_requirements ():
18- develop = False
19- if 'egg_info' in sys .argv :
20- return []
21- elif 'develop' in sys .argv :
22- develop = True
2326
24- requirements = set ()
25- for r in sys . argv :
26- if r . startswith ( "--drivers" ):
27- requirements |= extract_drivers ( r )
27+ def custom_command_driver ( driver ):
28+ class CustomCommand ( Command ) :
29+ """A custom command to run Pylint on all Python source files."""
30+ user_options = []
2831
29- # let's remove the options
30- sys . argv = [ o for o in sys . argv if not o . startswith ( "--drivers" )]
32+ def initialize_options ( self ):
33+ pass
3134
32- requirements = requirements or set ([ 'all' ])
33- requirements . add ( 'base' )
35+ def finalize_options ( self ):
36+ pass
3437
35- u = uuid .uuid1 ()
38+ def run (self ):
39+ """Run command."""
40+ process_requirements (driver )
3641
37- iter_reqs = chain (* [parse_requirements ("requirements/{}" .format (r ), session = u )
38- for r in requirements ])
42+ return CustomCommand
3943
40- if develop :
41- import pip
42- [pip .main (['install' , (str (ir .req ))]) for ir in iter_reqs ]
4344
44- return [str (ir .req ) for ir in iter_reqs ]
45+ class CustomInstall (install .install ):
46+ """A custom command to run Pylint on all Python source files."""
4547
48+ def run (self ):
49+ """Run command."""
50+ if any ([d in sys .argv for d in napalm .SUPPORTED_DRIVERS ]):
51+ process_requirements ('base' )
52+ else :
53+ process_requirements ('all' )
54+ install .install .run (self )
4655
47- reqs = process_requirements ()
4856
57+ custom_commands = {d : custom_command_driver (d ) for d in napalm .SUPPORTED_DRIVERS }
58+ custom_commands ['install' ] = CustomInstall
4959
5060setup (
61+ cmdclass = custom_commands ,
5162 name = "napalm" ,
52- version = '2.0.0a1 ' ,
63+ version = '2.0.0a3 ' ,
5364 packages = find_packages (exclude = ("test*" , )),
5465 test_suite = 'test_base' ,
5566 author = "David Barroso, Kirk Byers, Mircea Ulinic" ,
@@ -69,7 +80,7 @@ def process_requirements():
6980 ],
7081 url = "https://github.com/napalm-automation/napalm" ,
7182 include_package_data = True ,
72- install_requires = reqs ,
83+ install_requires = [] ,
7384 entry_points = {
7485 'console_scripts' : [
7586 'cl_napalm_configure=napalm.base.clitools.cl_napalm_configure:main' ,
0 commit comments