Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bob
bob.extension
Commits
a44b314c
Commit
a44b314c
authored
Sep 12, 2014
by
André Anjos
💬
Browse files
Implement requirements.txt file loading
parent
0b8cfa8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
bob/extension/test_utils.py
View file @
a44b314c
...
...
@@ -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
)
bob/extension/utils.py
View file @
a44b314c
...
...
@@ -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
]
!=
'#'
]
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment