Add Depends object.

This commit is contained in:
Robert Collins 2013-06-10 08:36:37 +12:00
parent 720f270e71
commit 262ccf03f6
4 changed files with 76 additions and 2 deletions

34
bindep/depends.py Normal file
View File

@ -0,0 +1,34 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
class Depends(object):
"""Project dependencies."""
def __init__(self, depends_string):
"""Construct a Depends instance.
:param depends_string: The string description of the requirements that
need to be satisfied. See the bindep README.rst for syntax for the
requirements list.
"""
def profiles(self):
return []
def platform_profiles(self):
return []

View File

@ -19,18 +19,25 @@ import logging
import optparse
import sys
from bindep.depends import Depends
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format="%(msg)s")
def main(depfactory=None):
if depfactory is None:
try:
open('other-requirements.txt', 'rt')
content = open('other-requirements.txt', 'rt').read()
except IOError:
logging.error('No other-requirements.txt file found.')
return 1
depends = Depends(content)
else:
depends = depfactory()
parser = optparse.OptionParser()
parser.add_option("--profiles", action="store_true",
parser.add_option(
"--profiles", action="store_true",
help="List the platform and configuration profiles.")
opts, args = parser.parse_args()
if opts.profiles:

View File

@ -0,0 +1,31 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from testtools import TestCase
from bindep.depends import Depends
class TestFactory(TestCase):
def test_empty_file(self):
depends = Depends("")
self.assertEqual([], depends.profiles())
def test_platform_profiles_succeeds(self):
depends = Depends("")
self.assertIsInstance(depends.platform_profiles(), list)

View File

@ -47,9 +47,11 @@ class TestMain(TestCase):
def test_profiles_lists_profiles(self):
logger = self.useFixture(FakeLogger())
self.useFixture(MonkeyPatch('sys.argv', ['bindep', '--profiles']))
class TestFactory:
def platform_profiles(self):
return ['platform:ubuntu', 'platform:i386']
def profiles(self):
return ['bar', 'foo']
self.assertEqual(0, main(depfactory=TestFactory))