-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
validation through entry point + reorg of the arg space #68
base: main
Are you sure you want to change the base?
Changes from 1 commit
c0f9e08
0d8af34
50c7d94
dc30f81
de339f3
58ded58
26168bc
bcd745a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#!/usr/bin/python3 | ||
|
||
import argparse | ||
import re | ||
import os | ||
from pcchecks import Regex | ||
import sys | ||
from pcutil import get_exist, get_not_exist | ||
from pcprvalidator import get_no_prefix_files, get_all_modules, get_all_assemblies, get_undetermined_files | ||
from pcvalidator import validation | ||
from pcmsg import print_message, print_report_message | ||
|
||
parser = argparse.ArgumentParser() | ||
|
||
|
||
def get_nonexisting_entry_points(entry_point_list): | ||
nonexistent_files = get_not_exist(entry_point_list) | ||
|
||
if nonexistent_files: | ||
print_message(nonexistent_files, 'entry point', 'does not exist in your repository') | ||
sys.exit(2) | ||
|
||
|
||
def get_includes(entry_points): | ||
path_to_includes = [] | ||
|
||
for entry in entry_points: | ||
path_to_entry_point = os.path.dirname(os.path.abspath(entry)) | ||
|
||
with open(entry, 'r') as file: | ||
original = file.read() | ||
stripped = Regex.MULTI_LINE_COMMENT.sub('', original) | ||
stripped = Regex.SINGLE_LINE_COMMENT.sub('', stripped) | ||
|
||
included_files = re.findall(Regex.INCLUDED_CONTENT, stripped) | ||
|
||
if included_files: | ||
|
||
for include in included_files[:]: | ||
if include.startswith('_'): | ||
included_files.remove(include) | ||
|
||
for i in included_files: | ||
path_to_includes.append(os.path.join(path_to_entry_point, i)) | ||
|
||
return path_to_includes | ||
|
||
|
||
def get_level_one_includes(files): | ||
path_to_level_one_includes = get_includes(files) | ||
|
||
return path_to_level_one_includes | ||
|
||
|
||
def get_level_two_includes(files): | ||
path_to_level_two_includes = get_includes(files) | ||
|
||
return path_to_level_two_includes | ||
|
||
|
||
def get_level_three_includes(files): | ||
path_to_level_three_includes = get_includes(files) | ||
|
||
return path_to_level_three_includes | ||
|
||
|
||
def get_level_four_includes(files): | ||
path_to_level_four_includes = get_includes(files) | ||
|
||
return path_to_level_four_includes | ||
|
||
|
||
def get_concatenated_includes(entry_point_list): | ||
existing_entry_points = get_exist(entry_point_list) | ||
level_one_includes = get_level_one_includes(existing_entry_points) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These functions are acting as wrappers for a single command today. If you'd like to keep this format, perhaps this chain can be simplified to something similar to the following -
|
||
level_two_includes = get_level_two_includes(level_one_includes) | ||
level_three_includes = get_level_three_includes(level_two_includes) | ||
level_four_includes = get_level_four_includes(level_three_includes) | ||
no_prefix_level_four_includes = get_no_prefix_files(level_four_includes) | ||
level_four_modules = get_all_modules(level_four_includes, no_prefix_level_four_includes) | ||
level_four_assemblies = get_all_assemblies(level_four_includes, no_prefix_level_four_includes) | ||
|
||
all_includes = level_one_includes + level_two_includes + level_three_includes + level_four_modules | ||
|
||
return all_includes, level_four_assemblies | ||
|
||
|
||
def get_level_four_assemblies(entry_point_list): | ||
all_includes, level_four_assemblies = get_concatenated_includes(entry_point_list) | ||
|
||
return level_four_assemblies | ||
|
||
|
||
def get_all_includes(entry_point_list): | ||
all_includes, level_four_assemblies = get_concatenated_includes(entry_point_list) | ||
|
||
for entry in entry_point_list: | ||
if not entry.endswith('master.adoc'): | ||
all_includes = all_includes + entry_point_list | ||
|
||
for include in all_includes: | ||
if os.path.basename(include).startswith('_'): | ||
all_includes.remove(include) | ||
|
||
return all_includes | ||
|
||
|
||
def validate_entry_point_files(entry_point_list): | ||
# exit if entry point doesn't exist | ||
get_nonexisting_entry_points(entry_point_list) | ||
existing_entry_points = get_exist(entry_point_list) | ||
includes = get_all_includes(entry_point_list) | ||
no_prefix_files = get_no_prefix_files(includes) | ||
modules_found = get_all_modules(includes, no_prefix_files) | ||
assemblies_found = get_all_assemblies(includes, no_prefix_files) | ||
undetermined_file_type = get_undetermined_files(no_prefix_files) | ||
level_four_assemblies = get_level_four_assemblies(existing_entry_points) | ||
|
||
if level_four_assemblies: | ||
print_message(level_four_assemblies, 'entry point', 'contains unsupported level of nesting for the following files') | ||
|
||
if undetermined_file_type: | ||
print_message(undetermined_file_type, 'entry point', 'contains the following files that can not be classified as modules or assemblies') | ||
|
||
validate = validation(includes, modules_found, assemblies_found) | ||
print_report_message(validate, 'entry point') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
|
||
|
||
class Report(): | ||
"""Create and print report. thank u J.""" | ||
|
||
def __init__(self): | ||
"""Create placeholder for problem description.""" | ||
self.report = {} | ||
self.count = 0 | ||
|
||
def create_report(self, category, file_path): | ||
"""Generate report.""" | ||
self.count += 1 | ||
if not category in self.report: | ||
self.report[category] = [] | ||
self.report[category].append(file_path) | ||
|
||
def print_report(self): | ||
|
||
"""Print report.""" | ||
separator = "\n\t" | ||
|
||
for category, files in self.report.items(): | ||
print("\nERROR: {} found in the following files:".format(category)) | ||
print('\t' + separator.join(files)) | ||
|
||
|
||
def print_message(variable, specification, msg): | ||
print(f'\nYour {specification} {msg}:\n') | ||
for var in variable: | ||
print('\t', var) | ||
print("\nTotal: ", str(len(variable))) | ||
|
||
|
||
def print_report_message(variable, specification): | ||
if variable.count != 0: | ||
print(f"\nYour {specification} contains the following files that did not pass validation:\n") | ||
variable.print_report() | ||
sys.exit(2) | ||
else: | ||
print("All files passed validation.") | ||
sys.exit(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might run into a similar problem I encountered with the coalescing function here.
Namely, some users use attributes in their includes - and nested ones at that. As such, unless you go through and resolve the entire attribute tree, attempting to convert an include into an actual path sometimes fails.
How would you feel about a pared down version of the coalescing loop to still work with attributes and iterate through levels of content?