Skip to content
Snippets Groups Projects
Commit a44b314c authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

Implement requirements.txt file loading

parent 0b8cfa8a
Branches
Tags
No related merge requests found
......@@ -9,7 +9,8 @@
import os
import sys
import nose.tools
from .utils import uniq, egrep, find_file, find_header, find_library
from .utils import uniq, egrep, find_file, find_header, find_library, \
load_requirements
def test_uniq():
......@@ -87,3 +88,20 @@ def test_find_versioned_library():
for k in lib:
assert k.find('boost_system') >= 0
def test_requirement_readout():
from StringIO import StringIO as stringio
f = """ # this is my requirements file
package-a >= 0.42
package-b
package-c
#package-e #not to be included
package-z
"""
result = load_requirements(stringio(f))
expected = ['package-a >= 0.42', 'package-b', 'package-c', 'package-z']
nose.tools.eq_(result, expected)
......@@ -325,3 +325,13 @@ def egrep(filename, expression):
if p: retval.append(p)
return retval
def load_requirements(f=None):
"""Loads the contents of requirements.txt on the given path.
Defaults to "./requirements.txt"
"""
f = f if f is not None else open("requirements.txt", 'rt')
retval = [k.strip() for k in f]
return [k for k in retval if k and k[0] != '#']
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment