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

[ADD] reqgen: add exclude_path parameter

parent 2ae9e7e7
Pipeline #103373 failed with stage
in 31 seconds
......@@ -88,7 +88,7 @@ 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
......@@ -97,18 +97,20 @@ def merge_requirements(merge_to, merge_from):
"""
res = copy.deepcopy(merge_to)
for name, req in iteritems(merge_from):
if name in exclude_libs:
continue
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 +125,14 @@ def save_requirements(requirementstxt, filename):
reqs = load_deps(requirementstxt)
if not reqs:
return
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')
req_file.write(req.line + '\n')
def search_reqs_files(folder_name, recursive=False):
......@@ -158,6 +163,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