refactor requirements loading

move file line processing to a separate function and add more file
patterns so we are more restrictive with the files that are loaded by
default
This commit is contained in:
Doug Hellmann 2014-11-11 15:44:34 -05:00
parent a3bf1a758c
commit adcbfadc1a
1 changed files with 22 additions and 12 deletions

View File

@ -8,24 +8,34 @@ from . import models
LOG = logging.getLogger(__name__)
def read_requirements_file(file_obj):
for line in file_obj.lines:
text = line.content.strip()
if not text or text.startswith('#'):
continue
try:
# FIXME(dhellmann): Use pbr's requirements parser.
dist_name = pkg_resources.Requirement.parse(text).project_name
except ValueError:
LOG.warn('could not parse dist name from %r',
line.content)
continue
yield dist_name, line
class RequirementsHandler(base.FileHandler):
INTERESTING_PATTERNS = ['*requirements*.txt']
INTERESTING_PATTERNS = [
'requirements.txt',
'requirements-py*.txt',
'test-requirements.txt',
'test-requirements-py*.txt',
]
def process_file(self, session, file_obj):
LOG.info('loading requirements from %s', file_obj.project_path)
parent_project = file_obj.project
for line in file_obj.lines:
text = line.content.strip()
if not text or text.startswith('#'):
continue
try:
# FIXME(dhellmann): Use pbr's requirements parser.
dist_name = pkg_resources.Requirement.parse(text).project_name
except ValueError:
LOG.warn('could not parse dist name from %r',
line.content)
continue
for dist_name, line in read_requirements_file(file_obj):
LOG.debug('requirement: %s', dist_name)
new_r = models.Requirement(
name=dist_name,