Tolerate missing bindep.txt when using --profiles
When just trying to determine the list of possible platform profiles, it seems silly to need to `touch bindep.txt`. Note that we'll still log the error about how neither bindep.txt nor other-requirements.txt exists Change-Id: I6ab187cdfb7d8fc5638880bcffea6800f5227c79
This commit is contained in:
parent
8c489f141d
commit
d5ee0cbb58
|
@ -68,11 +68,14 @@ PY2 = "base-py2"
|
|||
PY3 = "base-py3"
|
||||
|
||||
|
||||
def get_depends(filename=None):
|
||||
def get_depends(filename=None, default_blank=False):
|
||||
fd = get_depends_file(filename)
|
||||
if not fd:
|
||||
return None
|
||||
return Depends(fd.read())
|
||||
if default_blank:
|
||||
return Depends("")
|
||||
else:
|
||||
return None
|
||||
return Depends(fd.read(), filename)
|
||||
|
||||
|
||||
def get_depends_file(filename=None):
|
||||
|
@ -132,15 +135,18 @@ class Depends(object):
|
|||
(True, True): True,
|
||||
}
|
||||
|
||||
def __init__(self, depends_string):
|
||||
def __init__(self, depends_string, filename=None):
|
||||
"""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.
|
||||
:param filename: The string name of the file from which requirements
|
||||
were loaded.
|
||||
"""
|
||||
parser = makeGrammar(grammar, {})(depends_string)
|
||||
self._rules = parser.rules()
|
||||
self.filename = filename
|
||||
|
||||
def _partition(self, rule):
|
||||
"""Separate conditions into platform and user profiles.
|
||||
|
|
|
@ -53,7 +53,9 @@ def main(depends=None):
|
|||
args = parser.parse_args()
|
||||
|
||||
if depends is None:
|
||||
depends = bindep.depends.get_depends(args.filename)
|
||||
depends = bindep.depends.get_depends(
|
||||
args.filename,
|
||||
default_blank=args.profiles)
|
||||
if not depends:
|
||||
return 1
|
||||
|
||||
|
@ -61,10 +63,12 @@ def main(depends=None):
|
|||
logging.info("Platform profiles:")
|
||||
for profile in depends.platform_profiles():
|
||||
logging.info("%s", profile)
|
||||
logging.info("")
|
||||
logging.info("Configuration profiles:")
|
||||
for profile in depends.profiles():
|
||||
logging.info("%s", profile)
|
||||
|
||||
if depends.filename:
|
||||
logging.info("")
|
||||
logging.info("Configuration profiles:")
|
||||
for profile in depends.profiles():
|
||||
logging.info("%s", profile)
|
||||
return 0
|
||||
|
||||
profiles = args.profile + depends.platform_profiles()
|
||||
|
|
|
@ -70,6 +70,12 @@ class DistroFixture(fixtures.Fixture):
|
|||
|
||||
class TestDepends(TestCase):
|
||||
|
||||
def test_filename(self):
|
||||
depends = Depends("")
|
||||
self.assertIsNone(depends.filename)
|
||||
depends = Depends("", "/some/path/to/bindep.txt")
|
||||
self.assertEqual(depends.filename, "/some/path/to/bindep.txt")
|
||||
|
||||
def test_empty_file(self):
|
||||
depends = Depends("")
|
||||
self.assertEqual([], depends.profiles())
|
||||
|
|
|
@ -53,6 +53,8 @@ class TestMain(TestCase):
|
|||
self.useFixture(MonkeyPatch('sys.argv', ['bindep', '--profiles']))
|
||||
|
||||
class TestFactory:
|
||||
filename = 'some/bindep.txt'
|
||||
|
||||
def platform_profiles(self):
|
||||
return ['platform:ubuntu', 'platform:i386']
|
||||
|
||||
|
@ -69,6 +71,25 @@ class TestMain(TestCase):
|
|||
foo
|
||||
"""), logger.output)
|
||||
|
||||
def test_profiles_lists_profiles_no_file_loaded(self):
|
||||
logger = self.useFixture(FakeLogger())
|
||||
self.useFixture(MonkeyPatch('sys.argv', ['bindep', '--profiles']))
|
||||
|
||||
class TestFactory:
|
||||
filename = None
|
||||
|
||||
def platform_profiles(self):
|
||||
return ['platform:ubuntu', 'platform:i386']
|
||||
|
||||
def profiles(self):
|
||||
return []
|
||||
self.assertEqual(0, main(depends=TestFactory()))
|
||||
self.assertEqual(dedent("""\
|
||||
Platform profiles:
|
||||
platform:ubuntu
|
||||
platform:i386
|
||||
"""), logger.output)
|
||||
|
||||
def test_missing_default_requirements_file(self):
|
||||
fixture = self.useFixture(MainFixture())
|
||||
self.useFixture(MonkeyPatch('sys.argv', ['bindep']))
|
||||
|
|
Loading…
Reference in New Issue