Commit 267528e0 authored by Jonathan Osorio Alcalá's avatar Jonathan Osorio Alcalá
Browse files

[ADD] reqgen: add exclude_path parameter

parent 2ae9e7e7
Pipeline #103435 passed with stage
in 39 seconds
......@@ -17,7 +17,7 @@ lint:
stage: test
- pip
- test
- python
- tox -e py27
......@@ -25,7 +25,7 @@ testpy27:
stage: test
- pip
- test
- python
image: python:3.4-alpine
......@@ -34,7 +34,7 @@ testpy34:
stage: test
- pip
- test
- python
image: python:3.5-alpine
......@@ -88,27 +88,30 @@ def will_install(package_line):
return compare(res_groups[0], python_version(), res_groups[1])
def merge_requirements(merge_to, merge_from):
def merge_requirements(merge_to, merge_from, exclude_libs=False):
Takes a dict of requirements objects and merge
:param merge_to: The first dict where you want to merge from
:param merge_from: The second element where we want to merge from
:return: A dict with the merged elements
exclude_libs = exclude_libs or []
res = copy.deepcopy(merge_to)
for name, req in iteritems(merge_from):
if name in exclude_libs:
if name not in res or gt(req, res.get(name)):
res.update({name: req})
return res
def generate_merged_file(dest_file, path, recursive=False):
def generate_merged_file(dest_file, path, recursive=False, exclude=False):
file_list = search_reqs_files(path, recursive)
for files in file_list:
save_requirements(files, dest_file)
save_requirements(files, dest_file, exclude)
def save_requirements(requirementstxt, filename):
def save_requirements(requirementstxt, filename, exclude_path=False):
Take the requirements in the first file and save them to the second if they are
newer or they're no present in the file
......@@ -123,11 +126,14 @@ def save_requirements(requirementstxt, filename):
reqs = load_deps(requirementstxt)
if not reqs:
fullreqs = merge_requirements(fullreqs, reqs)
exclude_libs = []
if exclude_path:
exclude_libs = load_deps(exclude_path).keys()
fullreqs = merge_requirements(fullreqs, reqs, exclude_libs)
with open(filename, 'w') as req_file:
for req in fullreqs.values():
if req is not None:
req_file.write(req.line + '\n')
def search_reqs_files(folder_name, recursive=False):
......@@ -158,6 +164,8 @@ def search_reqs_files(folder_name, recursive=False):
help="If true, reqgen will retrieve all the requirements in a"
" path and all it's subdirectories, else, it will stop after"
" the first requirements.txt found in a path")
def main(dest_file, path, recursive):
generate_merged_file(dest_file, path, recursive)
@click.option('--exclude_path', default="",
help='Path where store the requirements_exclude.txt')
def main(dest_file, path, recursive, exclude_path):
generate_merged_file(dest_file, path, recursive, exclude_path)
return 0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment