Skip to content

Commit

Permalink
0.6.1 (#75)
Browse files Browse the repository at this point in the history
* fix: gh issue #74
* version: 0.6.1
  • Loading branch information
simonkowallik authored Feb 18, 2023
1 parent ae35b89 commit b680402
Show file tree
Hide file tree
Showing 12 changed files with 1,609 additions and 716 deletions.
2 changes: 1 addition & 1 deletion as3ninja/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__author__ = """Simon Kowallik"""
__email__ = "[email protected]"
__version__ = "0.6.0" # pyproject.toml
__version__ = "0.6.1" # pyproject.toml
__projectname__ = "AS3 Ninja"
# pylint: disable=line-too-long
__description__ = "AS3 Ninja is a templating and validation engine for your AS3 declarations providing a CLI and Swagger REST API."
45 changes: 38 additions & 7 deletions as3ninja/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from . import __version__
from .declaration import AS3Declaration
from .exceptions import AS3ValidationError
from .gitget import Gitget
from .schema import AS3Schema
from .templateconfiguration import AS3TemplateConfiguration
Expand Down Expand Up @@ -217,7 +218,22 @@ def git_transform( # pylint: disable=R0913 # Too many arguments
)
if validate:
as3s = AS3Schema()
as3s.validate(declaration=as3declaration.dict())
try:
as3s.validate(declaration=as3declaration.dict())
except AS3ValidationError as exc:
LOG_STDERR.error(
"Validation failed for AS3 Schema version: {}",
as3s.version,
feature="f-strings",
)
if exc.context:
for subexc in exc.context:
LOG_STDERR.info(
"\n{}\n",
subexc,
feature="f-strings",
)
raise exc

_output_declaration(as3declaration, output_file=output_file, pretty=pretty)

Expand Down Expand Up @@ -248,12 +264,27 @@ def validate(
If no version is specified, the latest available version is used."""
as3s = AS3Schema(version=version)
_declaration = deserialize(declaration.name)
as3s.validate(declaration=_declaration)
LOG_STDOUT.info(
"Validation passed for AS3 Schema version: {}",
as3s.version,
feature="f-strings",
)
try:
as3s.validate(declaration=_declaration)
LOG_STDOUT.info(
"Validation passed for AS3 Schema version: {}",
as3s.version,
feature="f-strings",
)
except AS3ValidationError as exc:
LOG_STDERR.error(
"Validation failed for AS3 Schema version: {}",
as3s.version,
feature="f-strings",
)
if exc.context:
for subexc in exc.context:
LOG_STDERR.info(
"\n{}\n",
subexc,
feature="f-strings",
)
raise exc


@cli.group(context_settings=dict(help_option_names=["-h", "--help"]))
Expand Down
32 changes: 28 additions & 4 deletions as3ninja/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,19 @@ class AS3SchemaError(SchemaError):
"""Raised when AS3 Schema is erroneous, eg. does not adhere to jsonschema standards."""

def __init__(self, message: str = "", original_exception=None):
super(AS3SchemaError, self).__init__(f"{message}: {str(original_exception)}")
# super(AS3SchemaError, self).__init__(f"{message}: {str(original_exception)}")
super().__init__(
message=message + original_exception.message,
validator=original_exception.validator,
path=original_exception.path,
cause=original_exception.cause,
context=original_exception.context,
validator_value=original_exception.validator_value,
instance=original_exception.instance,
schema=original_exception.schema,
schema_path=original_exception.schema_path,
parent=original_exception.parent,
)


class AS3SchemaVersionError(ValueError):
Expand All @@ -152,6 +164,18 @@ class AS3ValidationError(ValidationError):
"""Validation of AS3 declaration against AS3 Schema produced an error."""

def __init__(self, message: str = "", original_exception=None):
super(AS3ValidationError, self).__init__(
f"{message}: {str(original_exception)}"
)
if original_exception:
super().__init__(
message=message + original_exception.message,
validator=original_exception.validator,
path=original_exception.path,
cause=original_exception.cause,
context=original_exception.context,
validator_value=original_exception.validator_value,
instance=original_exception.instance,
schema=original_exception.schema,
schema_path=original_exception.schema_path,
parent=original_exception.parent,
)
else:
super().__init__(message=message)
6 changes: 3 additions & 3 deletions as3ninja/schema/as3schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _build_ref_url(self, version: str) -> str:
raise ValueError(
f"Expected to find a single AS3 Schema file, found: {len(url)}, urls:{url}"
)
return "file://" + str(url[0])
return url[0].as_uri()

def _schema_ref_update(self, version: str) -> dict:
"""Private Method: _schema_ref_update returns the AS3 Schema for specified version with updated references.
Expand Down Expand Up @@ -322,6 +322,6 @@ def validate(
validator = self._validator(version)
validator.validate(declaration)
except ValidationError as exc:
raise AS3ValidationError("AS3 Validation Error", exc)
except (SchemaError, RefResolutionError) as exc:
raise AS3ValidationError("AS3 Validation Error: ", exc) from exc
except (SchemaError) as exc:
raise AS3SchemaError("JSON Schema Error", exc)
2 changes: 2 additions & 0 deletions as3ninja/schema/formatcheckers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def _regex_match(regex: str, value: str) -> bool:
:param regex: The regular expression, for example: ``r'^[ -~]+$'``
:param value: Value to apply the regular expression to
"""
if not isinstance(value, str):
return False
reg_ex = re.compile(regex)
if reg_ex.match(value) is None:
return False
Expand Down
51 changes: 26 additions & 25 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,47 +1,48 @@
alabaster==0.7.12 ; python_version >= "3.8" and python_version < "4.0"
alabaster==0.7.13 ; python_version >= "3.8" and python_version < "4.0"
anyio==3.6.2 ; python_version >= "3.8" and python_version < "4.0"
attrs==22.1.0 ; python_version >= "3.8" and python_version < "4.0"
attrs==22.2.0 ; python_version >= "3.8" and python_version < "4.0"
babel==2.11.0 ; python_version >= "3.8" and python_version < "4.0"
certifi==2022.9.24 ; python_version >= "3.8" and python_version < "4"
charset-normalizer==2.1.1 ; python_version >= "3.8" and python_version < "4"
certifi==2022.12.7 ; python_version >= "3.8" and python_version < "4"
charset-normalizer==3.0.1 ; python_version >= "3.8" and python_version < "4"
click==8.1.3 ; python_version >= "3.8" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.8" and python_version < "4.0" and sys_platform == "win32" or python_version >= "3.8" and python_version < "4.0" and platform_system == "Windows"
docutils==0.17.1 ; python_version >= "3.8" and python_version < "4.0"
fastapi==0.87.0 ; python_version >= "3.8" and python_version < "4.0"
docutils==0.18.1 ; python_version >= "3.8" and python_version < "4.0"
fastapi==0.92.0 ; python_version >= "3.8" and python_version < "4.0"
h11==0.14.0 ; python_version >= "3.8" and python_version < "4.0"
hvac==0.11.2 ; python_version >= "3.8" and python_version < "4.0"
idna==3.4 ; python_version >= "3.8" and python_version < "4"
imagesize==1.4.1 ; python_version >= "3.8" and python_version < "4.0"
importlib-metadata==5.0.0 ; python_version >= "3.8" and python_version < "3.10"
importlib-resources==5.10.0 ; python_version >= "3.8" and python_version < "3.9"
importlib-metadata==6.0.0 ; python_version >= "3.8" and python_version < "3.10"
importlib-resources==5.12.0 ; python_version >= "3.8" and python_version < "3.9"
jinja2==3.1.2 ; python_version >= "3.8" and python_version < "4.0"
jsonschema==4.17.0 ; python_version >= "3.8" and python_version < "4.0"
jsonschema==4.17.3 ; python_version >= "3.8" and python_version < "4.0"
loguru==0.6.0 ; python_version >= "3.8" and python_version < "4.0"
markupsafe==2.1.1 ; python_version >= "3.8" and python_version < "4.0"
packaging==21.3 ; python_version >= "3.8" and python_version < "4.0"
markupsafe==2.1.2 ; python_version >= "3.8" and python_version < "4.0"
packaging==23.0 ; python_version >= "3.8" and python_version < "4.0"
pkgutil-resolve-name==1.3.10 ; python_version >= "3.8" and python_version < "3.9"
pydantic==1.10.2 ; python_version >= "3.8" and python_version < "4.0"
pygments==2.13.0 ; python_version >= "3.8" and python_version < "4.0"
pyparsing==3.0.9 ; python_version >= "3.8" and python_version < "4.0"
pyrsistent==0.19.2 ; python_version >= "3.8" and python_version < "4.0"
pytz==2022.6 ; python_version >= "3.8" and python_version < "4.0"
pydantic==1.10.5 ; python_version >= "3.8" and python_version < "4.0"
pygments==2.14.0 ; python_version >= "3.8" and python_version < "4.0"
pyrsistent==0.19.3 ; python_version >= "3.8" and python_version < "4.0"
pytz==2022.7.1 ; python_version >= "3.8" and python_version < "4.0"
pyyaml==6.0 ; python_version >= "3.8" and python_version < "4.0"
requests==2.28.1 ; python_version >= "3.8" and python_version < "4"
requests==2.28.2 ; python_version >= "3.8" and python_version < "4"
setuptools==67.3.2 ; python_version >= "3.8" and python_version < "4.0"
six==1.16.0 ; python_version >= "3.8" and python_version < "4.0"
sniffio==1.3.0 ; python_version >= "3.8" and python_version < "4.0"
snowballstemmer==2.2.0 ; python_version >= "3.8" and python_version < "4.0"
sphinx-autodoc-typehints==1.19.5 ; python_version >= "3.8" and python_version < "4.0"
sphinx-rtd-theme==1.1.1 ; python_version >= "3.8" and python_version < "4.0"
sphinx-autodoc-typehints==1.22 ; python_version >= "3.8" and python_version < "4.0"
sphinx-rtd-theme==1.2.0 ; python_version >= "3.8" and python_version < "4.0"
sphinx==5.3.0 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-applehelp==1.0.2 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-applehelp==1.0.4 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-devhelp==1.0.2 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-htmlhelp==2.0.0 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-htmlhelp==2.0.1 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-jquery==2.0.0 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-jsmath==1.0.1 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-qthelp==1.0.3 ; python_version >= "3.8" and python_version < "4.0"
sphinxcontrib-serializinghtml==1.1.5 ; python_version >= "3.8" and python_version < "4.0"
starlette==0.21.0 ; python_version >= "3.8" and python_version < "4.0"
typing-extensions==4.4.0 ; python_version >= "3.8" and python_version < "4.0"
urllib3==1.26.12 ; python_version >= "3.8" and python_version < "4"
starlette==0.25.0 ; python_version >= "3.8" and python_version < "4.0"
typing-extensions==4.5.0 ; python_version >= "3.8" and python_version < "4.0"
urllib3==1.26.14 ; python_version >= "3.8" and python_version < "4"
uvicorn==0.18.3 ; python_version >= "3.8" and python_version < "4.0"
win32-setctime==1.1.0 ; python_version >= "3.8" and python_version < "4.0" and sys_platform == "win32"
zipp==3.10.0 ; python_version >= "3.8" and python_version < "3.10"
zipp==3.14.0 ; python_version >= "3.8" and python_version < "3.10"
Loading

0 comments on commit b680402

Please sign in to comment.