Skip to content
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

jupiter prep #69

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
56473e2
replaced pv2.yml generation scripts with build.yml generator
Levi-Leah Feb 17, 2022
24466ce
s/pantheon2.yml/build.yml/g
Levi-Leah Feb 17, 2022
13bbde5
updated schema to validate build.yml
Levi-Leah Feb 17, 2022
16f7b73
added check for a defined nspb attribute within the attributes file
Levi-Leah Feb 17, 2022
0179d20
mods how attribute file is sourced from the build.yml
Levi-Leah Feb 17, 2022
00d48b5
collecting files
Levi-Leah Feb 24, 2022
d4ea04d
mods how files are sourced
Levi-Leah Feb 24, 2022
301f133
removing excludes from content list
Levi-Leah Feb 24, 2022
1ea9481
removes excludes from includes
Levi-Leah Feb 24, 2022
fafcc62
new way to get unique file list from build.yml + reorg
Levi-Leah Mar 1, 2022
d1e7544
changes md5sum to realpath
Levi-Leah Mar 1, 2022
3ba8111
hooked up validation routine for files with no prefix
Levi-Leah Mar 1, 2022
67b9ecb
adds validation for files with prefix + catches and validates files w…
Levi-Leah Mar 1, 2022
a232aad
fixes false positives in -- code blokes
Levi-Leah Mar 1, 2022
a2df642
fixes the imports
Levi-Leah Mar 1, 2022
48072cb
split function into two to avoid printing output multiple times
Levi-Leah Mar 1, 2022
f024446
msg change
Levi-Leah Mar 1, 2022
051c18a
removes outdated checks
Levi-Leah Mar 2, 2022
c5b6668
weird way to deal with optional exclude key
Levi-Leah Mar 2, 2022
36496f2
fix
Levi-Leah Mar 2, 2022
bf63dc2
removes attribute files from file pull
Levi-Leah Mar 2, 2022
5678681
implemented Jaromir's feedback on build.yml generation script
Levi-Leah Mar 3, 2022
2dd92c1
adds docstring; removes some functions; simplifies validation routine
Levi-Leah Mar 3, 2022
52ac8ab
fixes typos
Levi-Leah Mar 3, 2022
c945743
main validation routine now expects user input
Levi-Leah Mar 3, 2022
1079908
raname; new parser; validation throug build/dir/single file
Levi-Leah Mar 4, 2022
bbd504d
adds attribute check to adoc files validation
Levi-Leah Mar 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions PantheonCMD/buildyml-generator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

ROOT_REPO=$(git rev-parse --show-toplevel)
SCRIPT_DIR=$(realpath $(dirname "$0"))
REPO_NAME=$(basename $ROOT_REPO)

if [[ -f "$ROOT_REPO/build.yml" ]]; then
read -p "build.yml already exists. Do you want to overwrite it? [y/N] " -n 1
echo
if [[ ! "$REPLY" =~ ^[yY]$ ]]; then
exit
fi
fi

cat >$ROOT_REPO/build.yml << EOF
# Your repository name goes here
repository: $REPO_NAME
variants:
# Your variant name goes here
- name: PLACEHOLDER
# Path to your attributes file goes here
attributes:
- PATH/TO/_attributes.adoc
nav: PATH/TO/nav.yml
build: true
files:
# Path to your assemblies, modules, and images go here
included:
- PATH/TO/ASSEMBLIES/*.adoc
- PATH/TO/MODULES/**/*.adoc
- PATH/TO/images/*.png

EOF

echo "build.yml successfully generated"
31 changes: 31 additions & 0 deletions PantheonCMD/enki.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/python3

import argparse
from pathlib import Path
import os
from enki_yaml_valiadtor import yaml_validation
from enki_files_valiadtor import multi_file_validation, single_file_validation

parser = argparse.ArgumentParser()
parser.add_argument("path", type=Path)

p = parser.parse_args()


user_input = p.path

if user_input.is_file():
file_name = os.path.basename(user_input)
file_path = os.path.dirname(user_input)
if file_name == 'build.yml':
file_name = os.path.basename(user_input)
yaml_validation(user_input, file_path)
else:
str = str(user_input)
list = str.split()
single_file_validation(list)

elif user_input.is_dir():
multi_file_validation(user_input)
else:
print("ERROR: Provided path doesn't exist.")
41 changes: 16 additions & 25 deletions PantheonCMD/pcchecks.py → PantheonCMD/enki_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Tags:
ABSTRACT = '[role="_abstract"]'
ADD_RES = '[role="_additional-resources"]'
EXPERIMENTAL = ':experimental:'
NBSP_ATT = ':nbsp: &nbsp'
NBSP_VAR = '{nbsp}'
LVLOFFSET = ':leveloffset:'
ICONS = ':icons:'
TOC = ':toc:'
Expand All @@ -18,7 +20,8 @@ class Regex:
"""Define regular expresiions for the checks."""

INCLUDE = re.compile(r'include::.*\]\n')
MODULE_TYPE = re.compile(r':_module-type: (PROCEDURE|CONCEPT|REFERENCE)')
MODULE_TYPE = re.compile(r':_content-type: (PROCEDURE|CONCEPT|REFERENCE)')
ASSEMBLY_TYPE = re.compile(r':_content-type: ASSEMBLY')
PREFIX_ASSEMBLIES = re.compile(r'.*\/assembly.*\.adoc')
PREFIX_MODULES = re.compile(r'.*\/con.*\.adoc|.*\/proc.*\.adoc|.*\/ref.*\.adoc')
# should exclude pseudo vanilla like <<some content>>
Expand All @@ -36,6 +39,7 @@ class Regex:
INTERNAL_IFDEF = re.compile(r'(ifdef::internal\[\])(.*\n)*?(endif::\[\])')
CODE_BLOCK_DASHES = re.compile(r'(-{4,})(.*\n)*?(-{4,})')
CODE_BLOCK_DOTS = re.compile(r'(\.{4,})(.*\n)*?(\.{4,})')
CODE_BLOCK_TWO_DASHES = re.compile(r'(-{2,})(.*\n)*?(-{2,})')
HUMAN_READABLE_LABEL_XREF = re.compile(r'xref:.*\[]')
HUMAN_READABLE_LABEL_LINK = re.compile(r'\b(?:https?|file|ftp|irc):\/\/[^\s\[\]<]*\[\]')
NESTED_ASSEMBLY = re.compile(r'include.*assembly([a-z|0-9|A-Z|\-|_]+)\.adoc(\[.*\])')
Expand All @@ -62,6 +66,13 @@ def toc_check(report, stripped_file, file_path):
report.create_report('toc attribute', file_path)


def nbsp_check(report, stripped_file, file_path):
if re.findall(Tags.NBSP_ATT, stripped_file):
return
elif re.findall(Tags.NBSP_VAR, stripped_file):
report.create_report('`{nsbp}` attribute is used but not defined. `:nbsp: &nbsp` attribute is not', file_path)


def vanilla_xref_check(stripped_file):
"""Check if the file contains vanilla xrefs."""
if re.findall(Regex.VANILLA_XREF, stripped_file):
Expand All @@ -74,12 +85,6 @@ def inline_anchor_check(stripped_file):
return True


def var_in_title_check(stripped_file):
"""Check if the file contains a variable in the level 1 heading."""
if re.findall(Regex.VAR_IN_TITLE, stripped_file):
return True


def experimental_tag_check(stripped_file):
"""Check if the experimental tag is set."""
if stripped_file.count(Tags.EXPERIMENTAL) > 0:
Expand Down Expand Up @@ -121,14 +126,6 @@ def add_res_section_module_check(report, stripped_file, file_path):
if not re.findall(Regex.ADD_RES_MODULE, stripped_file):
report.create_report("Additional resources section for modules should be `.Additional resources`. Wrong section name was", file_path)


# Standalone check on assemblies_found
def nesting_in_assemblies_check(report, stripped_file, file_path):
"""Check if file contains nested assemblies."""
if re.findall(Regex.NESTED_ASSEMBLY, stripped_file):
return report.create_report('nesting in assemblies. nesting', file_path)


# Standalone check on assemblies_found
def add_res_section_assembly_check(report, stripped_file, file_path):
if re.findall(Regex.ADDITIONAL_RES, stripped_file):
Expand All @@ -142,9 +139,9 @@ def lvloffset_check(stripped_file):
return True


def abstarct_tag_none_or_multiple_check(stripped_file):
def abstarct_tag_multiple_check(stripped_file):
"""Checks if the abstract tag is not set or set more than once."""
if stripped_file.count(Tags.ABSTRACT) != 1:
if stripped_file.count(Tags.ABSTRACT) > 1:
return True


Expand Down Expand Up @@ -224,9 +221,6 @@ def checks(report, stripped_file, original_file, file_path):
if inline_anchor_check(stripped_file):
report.create_report('in-line anchors', file_path)

if var_in_title_check(stripped_file):
report.create_report('variable in the level 1 heading', file_path)

if experimental_tag_check(stripped_file):
report.create_report('files contain UI macros but the :experimental: tag not', file_path)

Expand All @@ -242,11 +236,8 @@ def checks(report, stripped_file, original_file, file_path):
if lvloffset_check(stripped_file):
report.create_report('unsupported use of :leveloffset:. unsupported includes', file_path)

if abstarct_tag_none_or_multiple_check(stripped_file):
if stripped_file.count(Tags.ABSTRACT) == 0:
report.create_report('abstract tag not', file_path)
else:
report.create_report('multiple abstract tags', file_path)
if abstarct_tag_multiple_check(stripped_file):
report.create_report('multiple abstract tags', file_path)

if abstract_tag_check(original_file):
if re.findall(Regex.FIRST_PARA, original_file):
Expand Down
130 changes: 130 additions & 0 deletions PantheonCMD/enki_files_valiadtor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/python3
import os
import sys
from enki_checks import Regex, icons_check, toc_check, nbsp_check, checks, nesting_in_modules_check, add_res_section_module_check, add_res_section_assembly_check
import re
import subprocess
from enki_yaml_valiadtor import Report, printing_build_yml_error


def get_files_bash(file_path):
"""Expand filepaths."""
command = "find " + str(file_path) + " -type f -name \*adoc 2>/dev/null"
process = subprocess.run(command, stdout=subprocess.PIPE, shell=True).stdout
files = process.strip().decode('utf-8').split('\n')

return files


def sort_prefix_files(files):
"""Get a list of assemblies, modulesa, and unidentifiyed files."""
prefix_assembly = []
prefix_modules = []
undefined_content = []
attribute_file = []

for item in files:
file_name = os.path.basename(item)
file_path = os.path.basename(item)

if file_path.startswith("_"):
attribute_file.append(item)
elif "/_" in file_path:
attribute_file.append(item)

if file_name.startswith('assembly'):
prefix_assembly.append(item)
elif file_name.startswith(("proc_", "con_", "ref_", "proc-", "con-", "ref-")):
prefix_modules.append(item)
elif file_name.startswith("_"):
attribute_file.append(item)
elif file_name.startswith(("snip_", "snip-")):
continue
elif file_name == 'master.adoc':
continue
else:
undefined_content.append(item)

return attribute_file, prefix_assembly, prefix_modules, undefined_content


def file_validation(files):
"""Validate all files."""
attribute_file, prefix_assembly, prefix_modules, undefined_content = sort_prefix_files(files)

all_files = attribute_file + prefix_assembly + prefix_modules + undefined_content

undetermined_file_type = []
confused_files = []

report = Report()

for path in all_files:
with open(path, 'r') as file:
original = file.read()
stripped = Regex.MULTI_LINE_COMMENT.sub('', original)
stripped = Regex.SINGLE_LINE_COMMENT.sub('', stripped)
stripped = Regex.CODE_BLOCK_DASHES.sub('', stripped)
stripped = Regex.CODE_BLOCK_TWO_DASHES.sub('', stripped)
stripped = Regex.CODE_BLOCK_DOTS.sub('', stripped)
stripped = Regex.INTERNAL_IFDEF.sub('', stripped)

icons_check(report, stripped, path)
toc_check(report, stripped, path)

if path in attribute_file:
nbsp_check(report, stripped, path)
else:
checks(report, stripped, original, path)

if path in undefined_content:
if re.findall(Regex.MODULE_TYPE, stripped):
nesting_in_modules_check(report, stripped, path)
add_res_section_module_check(report, stripped, path)

elif re.findall(Regex.ASSEMBLY_TYPE, stripped):
add_res_section_assembly_check(report, stripped, path)

else:
undetermined_file_type.append(path)

if path in prefix_assembly:
if re.findall(Regex.MODULE_TYPE, stripped):
confused_files.append(path)
nesting_in_modules_check(report, stripped, path)
add_res_section_module_check(report, stripped, path)
else:
add_res_section_assembly_check(report, stripped, path)

if path in prefix_modules:
if re.findall(Regex.ASSEMBLY_TYPE, stripped):
confused_files.append(path)
add_res_section_assembly_check(report, stripped, path)
else:
nesting_in_modules_check(report, stripped, path)
add_res_section_module_check(report, stripped, path)

if confused_files:
printing_build_yml_error("files that have mismatched name prefix and content type tag. Content type tag takes precedence. The files were checked according to the tag", confused_files)

if undetermined_file_type:
printing_build_yml_error('files that can not be classified as modules or assemblies', undetermined_file_type)

return report


def multi_file_validation(file_path):
files = get_files_bash(file_path)
validation = file_validation(files)

if validation.count != 0:
validation.print_report()
sys.exit(2)


def single_file_validation(files):
validation = file_validation(files)

if validation.count != 0:
validation.print_report()
sys.exit(2)
Loading