-
Notifications
You must be signed in to change notification settings - Fork 4
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
Validator #2
base: milestone0.3
Are you sure you want to change the base?
Validator #2
Conversation
apluslms_roman/cli.py
Outdated
from os.path import abspath, expanduser, expandvars | ||
from sys import exit | ||
from sys import exit, stderr, modules |
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.
imports are not used
apluslms_roman/cli.py
Outdated
@@ -1,23 +1,37 @@ | |||
import argparse | |||
from os import getcwd | |||
from os import getcwd, path |
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.
path
is not used
apluslms_roman/cli.py
Outdated
|
||
def main(): | ||
|
||
|
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.
unneeded newlines
apluslms_roman/validator.py
Outdated
|
||
#mystinen lista schema directoryja - course.yamlissa jossain kentässä, joka sijaitsee käyttäjän paketin juuressa | ||
def get_folders(config): | ||
folders = config.__config__.get("custom_schema_locations", []) |
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.
Key schema_paths
should be semantically better. In addition, it should be validated that it's a list.
if not isinstance(folders, list):
raise ValueError("Invalid type for 'schema_path' in config. Expected a llist.")
apluslms_roman/validator.py
Outdated
schema_path = os.path.join(ext[0], schema_fullname) | ||
logger.info(" Starting validation of %s with %s", filename, schema_fullname) | ||
result = self.assert_valid(schema_path, filename) | ||
logger.info(" Validation done", filename) |
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.
could probably contain the result
apluslms_roman/validator.py
Outdated
for ff in os.listdir(folder): | ||
logger.debug(" File-------------%s", ff) | ||
if prog.match(ff) is not None: | ||
found = prog.match(ff).groups() |
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.
match = prog.match(ff)
if match is not None:
major, minor, ext = match.groups()
...
better?
apluslms_roman/validator.py
Outdated
logger.debug(" File-------------%s", ff) | ||
if prog.match(ff) is not None: | ||
found = prog.match(ff).groups() | ||
schema_index.setdefault(schema, {}) |
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.
foo = schema_index.setdefault(...)
store result in var and use it below in place of schema_index[schema]
.
apluslms_roman/validator.py
Outdated
|
||
|
||
#idea = { schema_name: {(major, minor): location}} | ||
schema_index = {} |
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.
global
apluslms_roman/validator.py
Outdated
logger.info(" Locating all valid schemas...") | ||
self.find_all_matches(schema) | ||
logger.info(" Locating matching version v%d...", major) | ||
serial, ext = self.find_newest(schema, major, minor) |
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.
this is required only when minor is not known version: '3'
. If minor is known, then test (major, minor) in schema_index[schema]
is sufficient.
apluslms_roman/validator.py
Outdated
logger.debug(" Index-------------%s", schema_index) | ||
current = schema_index[schema].setdefault((int(found[0]), int(found[1])), None) | ||
if current is None: | ||
schema_index[schema][int(found[0]), int(found[1])] = (folder, found[2]) |
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 can store os.path.join(folder, ff)
and then the filename doesn't need to be reconstructed later.
apluslms_roman/validator.py
Outdated
return None | ||
|
||
#filter(_ <= major.minor) and reduce(max(_,_)) | ||
i = {k:v for k, v in schemas.items() if k[0]<major or k[0]==major and k[1]<=minor} |
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.
Finding newest with major should be simple as:
ver = max((v for v in schems if v[0] == major), default=None)
file_ = schemas[ver]
Files In addition, version could use do |
Created validator.py and some schemas for testing purposes.