Add bindep.txt as default filename

We use bindep.txt as default file and for compatibility handle
other-requirements.txt as well.
* If both files exist, bindep will fail.
* If neither of the files exist, bindep will fail.
* If a command line arg is given, it will be the only file looked at.

Adjust testsuite for change.

Change-Id: If9aaf24b1c7f489d8c7388707afc3316ca6f84f0
This commit is contained in:
Andreas Jaeger 2016-08-02 20:00:36 +02:00
parent 71ba17ac71
commit 1bbf6a77cf
4 changed files with 44 additions and 8 deletions

View File

@ -1,3 +1,10 @@
Change of default file
======================
File bindep.txt is now the default bindep file. For compatibility with
previous releases, bindep will check other-requirements.txt if
bindep.txt does not exist.
Backward-Incompatible Changes Between 1.0.0 and 2.0.0
=====================================================

View File

@ -11,13 +11,16 @@ installed before `pip` can be used - such as `virtualenv` and `pip` itself.
Basics
======
Create a file called ``other-requirements.txt`` and in that list any
Create a file called ``bindep.txt`` and in that list any
requirements your application / library has. In your README or INSTALL or
other documentation you can tell users to run `bindep` to report on missing
dependencies. Users without `bindep` installed can consult the
``other-requirements.txt`` file by hand if they choose, or install `bindep`
``bindep.txt`` file by hand if they choose, or install `bindep`
first and then use it.
If no ``bindep.txt`` file exists, `bindep` will look at the
old location ``other-requirements.txt``.
The output from bindep is fairly verbose normally, but passing an option of
-b/--brief outputs just the missing packages one per line, suitable for feeding
to your package management tool of choice.

View File

@ -17,6 +17,7 @@
import logging
import optparse
import os.path
import sys
import bindep.depends
@ -35,8 +36,9 @@ def main(depends=None):
help="List only missing packages one per line.")
parser.add_option(
"-f", "--file", action="store", type="string", dest="filename",
default="other-requirements.txt",
help="Package list file (default: other-requirements.txt).")
default="",
help="Package list file (default: bindep.txt or "
"other-requirements.txt).")
parser.add_option(
"--profiles", action="store_true",
help="List the platform and configuration profiles.")
@ -44,12 +46,35 @@ def main(depends=None):
if depends is None:
if opts.filename == "-":
fd = sys.stdin
else:
elif opts.filename:
try:
fd = open(opts.filename, 'rt')
except IOError:
logging.error('No %s file found.' % opts.filename)
logging.error('Error reading file %s.' % opts.filename)
return 1
else:
if (os.path.isfile('bindep.txt') and
os.path.isfile('other-requirements.txt')):
logging.error('Both bindep.txt and other-requirements.txt '
'files exist, choose one.')
return 1
if os.path.isfile('bindep.txt'):
try:
fd = open('bindep.txt', 'rt')
except IOError:
logging.error('Error reading file bindep.txt.')
return 1
elif os.path.isfile('other-requirements.txt'):
try:
fd = open('other-requirements.txt', 'rt')
except IOError:
logging.error('Error reading file other-requirements.txt.')
return 1
else:
logging.error('Neither file bindep.txt nor file '
'other-requirements.txt exist.')
return 1
depends = bindep.depends.Depends(fd.read())
if opts.profiles:
logging.info("Platform profiles:")

View File

@ -71,7 +71,8 @@ class TestMain(TestCase):
self.useFixture(MonkeyPatch('sys.argv', ['bindep']))
self.assertEqual(1, main())
self.assertEqual(
'No other-requirements.txt file found.\n', fixture.logger.output)
'Neither file bindep.txt nor file other-requirements.txt exist.\n',
fixture.logger.output)
def test_empty_requirements_file(self):
fixture = self.useFixture(MainFixture())
@ -96,7 +97,7 @@ class TestMain(TestCase):
'bindep', '--file', 'alternative-requirements.txt']))
self.assertEqual(1, main())
self.assertEqual(
'No alternative-requirements.txt file found.\n',
'Error reading file alternative-requirements.txt.\n',
fixture.logger.output)
def test_stdin_requirements_file(self):