Skip to content

Commit aaaf5f3

Browse files
committed
use --install-options to select drivers to install
1 parent 8978078 commit aaaf5f3

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

Diff for: napalm/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,10 @@
1313
__version__ = pkg_resources.get_distribution('napalm').version
1414
except pkg_resources.DistributionNotFound:
1515
__version__ = "Not installed"
16+
17+
18+
SUPPORTED_DRIVERS = [
19+
"eos",
20+
"ios",
21+
"junos",
22+
]

Diff for: setup.py

+39-28
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,66 @@
11
"""setup.py file."""
2+
import napalm
3+
24
import uuid
35

6+
from distutils.core import Command
47
from setuptools import setup, find_packages
8+
from setuptools.command import install
9+
10+
511
from pip.req import parse_requirements
6-
from itertools import chain
712

13+
import pip
814
import 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

5060
setup(
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

Comments
 (0)