-
Notifications
You must be signed in to change notification settings - Fork 554
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use --install-options to select drivers to install
- Loading branch information
Showing
2 changed files
with
46 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
|
@@ -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', | ||
|