Skip to content

Commit

Permalink
use --install-options to select drivers to install
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed Oct 21, 2017
1 parent 8978078 commit aaaf5f3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
7 changes: 7 additions & 0 deletions napalm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@
__version__ = pkg_resources.get_distribution('napalm').version
except pkg_resources.DistributionNotFound:
__version__ = "Not installed"


SUPPORTED_DRIVERS = [
"eos",
"ios",
"junos",
]
67 changes: 39 additions & 28 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,66 @@
"""setup.py file."""
import napalm

import uuid

from distutils.core import Command
from setuptools import setup, find_packages
from setuptools.command import install


from pip.req import parse_requirements
from itertools import chain

import pip
import sys

__author__ = 'David Barroso <[email protected]>'

__author__ = 'David Barroso <[email protected]>'

def extract_drivers(opt):
return set([r.replace("--drivers=", "").strip() for r in opt.split(",")])

def process_requirements(dep):
print("PROCESSING DEPENDENCIES FOR {}".format(dep))
u = uuid.uuid1()
iter_reqs = parse_requirements("requirements/{}".format(dep), session=u)
[pip.main(['install', (str(ir.req))]) for ir in iter_reqs]

def process_requirements():
develop = False
if 'egg_info' in sys.argv:
return []
elif 'develop' in sys.argv:
develop = True

requirements = set()
for r in sys.argv:
if r.startswith("--drivers"):
requirements |= extract_drivers(r)
def custom_command_driver(driver):
class CustomCommand(Command):
"""A custom command to run Pylint on all Python source files."""
user_options = []

# let's remove the options
sys.argv = [o for o in sys.argv if not o.startswith("--drivers")]
def initialize_options(self):
pass

requirements = requirements or set(['all'])
requirements.add('base')
def finalize_options(self):
pass

u = uuid.uuid1()
def run(self):
"""Run command."""
process_requirements(driver)

iter_reqs = chain(*[parse_requirements("requirements/{}".format(r), session=u)
for r in requirements])
return CustomCommand

if develop:
import pip
[pip.main(['install', (str(ir.req))]) for ir in iter_reqs]

return [str(ir.req) for ir in iter_reqs]
class CustomInstall(install.install):
"""A custom command to run Pylint on all Python source files."""

def run(self):
"""Run command."""
if any([d in sys.argv for d in napalm.SUPPORTED_DRIVERS]):
process_requirements('base')
else:
process_requirements('all')
install.install.run(self)

reqs = process_requirements()

custom_commands = {d: custom_command_driver(d) for d in napalm.SUPPORTED_DRIVERS}
custom_commands['install'] = CustomInstall

setup(
cmdclass=custom_commands,
name="napalm",
version='2.0.0a1',
version='2.0.0a3',
packages=find_packages(exclude=("test*", )),
test_suite='test_base',
author="David Barroso, Kirk Byers, Mircea Ulinic",
Expand All @@ -69,7 +80,7 @@ def process_requirements():
],
url="https://github.com/napalm-automation/napalm",
include_package_data=True,
install_requires=reqs,
install_requires=[],
entry_points={
'console_scripts': [
'cl_napalm_configure=napalm.base.clitools.cl_napalm_configure:main',
Expand Down

0 comments on commit aaaf5f3

Please sign in to comment.