Skip to content

Commit

Permalink
Python 3.6 support (#50)
Browse files Browse the repository at this point in the history
* Removed dataclass and __future__ imports as they are not available in Python 3.6. Lowered the version of pylint to work with python 3.6

* Updated the workload to add a test for python 3.6. Updated the changelog with the latest changes. Updated setup.py build to 0.2.2

* Updated the setup.py to include python 3.6. Changed the ubuntu version in the python version matrix job to allow 3.6 in the pipeline

* Updated setup.py to include a 3.6 classifier
  • Loading branch information
ryan95f authored Jan 18, 2023
1 parent 05b22fc commit 2bc3d58
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
pylint tests/
validate-python-versions:
needs: static-analysis
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
max-parallel: 2
fail-fast: true
steps:
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@

* Improved the Yamlator grammar to allow rule names to accept options including symbols, unicode, spaces and dashes. Any YAML key that contains spaces, must be enclosed in double quotes
* Upgraded the Ubuntu version on the publish workflow

## v0.2.2 (18th January 2023)

* Added support for Python 3.6+ by removing the `__future__` and `dataclass` imports from the codebase
* Downgraded pylint in the developer dependencies to allow for Python 3.6 to run locally
Binary file modified requirements-dev.txt
Binary file not shown.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import setuptools

VERSION = '0.2.1'
VERSION = '0.2.2'
PACKAGE_NAME = 'yamlator'
DESCRIPTION = 'Yamlator is a CLI tool that allows a YAML file to be validated using a lightweight schema language' # nopep8

Expand Down Expand Up @@ -51,12 +51,13 @@ def create_long_description():
'lark==1.0.0',
'PyYAML==6.0'
],
python_requires='>=3.7',
python_requires='>=3.6',
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
Expand Down
5 changes: 2 additions & 3 deletions tests/violations/test_violation_json_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from typing import Any
from collections import deque
from parameterized import parameterized
from dataclasses import dataclass

from yamlator.violations import BuiltInTypeViolation
from yamlator.violations import RegexTypeViolation
Expand All @@ -26,9 +25,9 @@
from yamlator.violations import StrictEntryPointViolation


@dataclass
class FakeViolation:
msg: str
def __init__(self, msg: str) -> None:
self.msg = msg


class TestViolationJSONEncoder(unittest.TestCase):
Expand Down
40 changes: 19 additions & 21 deletions yamlator/parser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""Maintains the parser transformers"""


from __future__ import annotations

import re
import os

Expand Down Expand Up @@ -81,31 +78,31 @@ class SchemaTransformer(Transformer):
# determine the type of the rule if a enum or ruleset is used
seen_constructs = {}

def rule_name(self, tokens: list[Token]) -> Token:
def rule_name(self, tokens: 'list[Token]') -> Token:
"""Processes the rule name by removing any quotes"""
token = tokens[0]
name = token.value.strip()
name = _QUOTES_REGEX.sub('', name)
return Token(value=name, type_=token.type)

def required_rule(self, tokens: list[Token]) -> Rule:
def required_rule(self, tokens: 'list[Token]') -> Rule:
"""Transforms the required rule tokens in a Rule object"""
(name, rtype) = tokens[0:2]
return Rule(name.value, rtype, True)

def optional_rule(self, tokens: list[Token]) -> Rule:
def optional_rule(self, tokens: 'list[Token]') -> Rule:
"""Transforms the optional rule tokens in a Rule object"""
(name, rtype) = tokens[0:2]
return Rule(name.value, rtype, False)

def ruleset(self, tokens: list[Token]) -> YamlatorRuleset:
def ruleset(self, tokens: 'list[Token]') -> YamlatorRuleset:
"""Transforms the ruleset tokens into a YamlatorRuleset object"""
name = tokens[0].value
rules = tokens[1:]
self.seen_constructs[name] = SchemaTypes.RULESET
return YamlatorRuleset(name, rules)

def strict_ruleset(self, tokens: list[Token]) -> YamlatorRuleset:
def strict_ruleset(self, tokens: 'list[Token]') -> YamlatorRuleset:
"""Transforms the ruleset tokens into a YamlatorRuleset object
and marks the ruleset as being in strict mode
"""
Expand Down Expand Up @@ -137,40 +134,40 @@ def start(self, instructions: Iterator[YamlatorType]) -> dict:
'enums': enums
}

def str_type(self, _: list[Token]) -> RuleType:
def str_type(self, _: 'list[Token]') -> RuleType:
"""Transforms a string type token into a RuleType object"""
return RuleType(schema_type=SchemaTypes.STR)

def int_type(self, _: list[Token]) -> RuleType:
def int_type(self, _: 'list[Token]') -> RuleType:
"""Transforms a int type token into a RuleType object"""
return RuleType(schema_type=SchemaTypes.INT)

def float_type(self, _: list[Token]) -> RuleType:
def float_type(self, _: 'list[Token]') -> RuleType:
"""Transforms a float type token into a RuleType object"""
return RuleType(schema_type=SchemaTypes.FLOAT)

def list_type(self, tokens: list[Token]) -> RuleType:
def list_type(self, tokens: 'list[Token]') -> RuleType:
"""Transforms a list type token into a RuleType object"""
return RuleType(schema_type=SchemaTypes.LIST, sub_type=tokens[0])

def map_type(self, tokens: list[Token]) -> RuleType:
def map_type(self, tokens: 'list[Token]') -> RuleType:
"""Transforms a map type token into a RuleType object"""
return RuleType(schema_type=SchemaTypes.MAP, sub_type=tokens[0])

def any_type(self, _: list[Token]) -> RuleType:
def any_type(self, _: 'list[Token]') -> RuleType:
"""Transforms the any type token into a RuleType object"""
return RuleType(schema_type=SchemaTypes.ANY)

def bool_type(self, _: list[Token]) -> RuleType:
def bool_type(self, _: 'list[Token]') -> RuleType:
"""Transforms a bool type token into a RuleType object"""
return RuleType(schema_type=SchemaTypes.BOOL)

def enum_item(self, tokens: list[Token]) -> EnumItem:
def enum_item(self, tokens: 'list[Token]') -> EnumItem:
"""Transforms a enum item token into a EnumItem object"""
name, value = tokens
return EnumItem(name=name, value=value)

def enum(self, tokens: list[Token]) -> YamlatorEnum:
def enum(self, tokens: 'list[Token]') -> YamlatorEnum:
"""Transforms a enum token into a YamlatorEnum object"""
enums = {}

Expand All @@ -182,7 +179,7 @@ def enum(self, tokens: list[Token]) -> YamlatorEnum:
self.seen_constructs[name] = SchemaTypes.ENUM
return YamlatorEnum(name.value, enums)

def container_type(self, token: list[Token]) -> RuleType:
def container_type(self, token: 'list[Token]') -> RuleType:
"""Transforms a container type token into a RuleType object
Raises:
Expand All @@ -195,12 +192,12 @@ def container_type(self, token: list[Token]) -> RuleType:
raise ConstructNotFoundError(name)
return RuleType(schema_type=schema_type, lookup=name)

def regex_type(self, tokens: list[Token]) -> RuleType:
def regex_type(self, tokens: 'list[Token]') -> RuleType:
"""Transforms a regex type token into a RuleType object"""
(regex, ) = tokens
return RuleType(schema_type=SchemaTypes.REGEX, regex=regex)

def type(self, tokens: list[Token]) -> Any:
def type(self, tokens: 'list[Token]') -> Any:
"""Extracts the type tokens and passes them through onto
the next stage in the transformer
"""
Expand Down Expand Up @@ -242,7 +239,8 @@ class _InstructionHandler:
_next_handler = None

def set_next_handler(self,
handler: _InstructionHandler) -> _InstructionHandler:
handler: '_InstructionHandler'
) -> '_InstructionHandler':
"""Set the next handler in the chain
Args:
Expand Down
4 changes: 1 addition & 3 deletions yamlator/types.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Yamlator Types"""


from __future__ import annotations
import re

from enum import Enum
Expand Down Expand Up @@ -37,7 +35,7 @@ class RuleType:
regex = None

def __init__(self, schema_type: SchemaTypes, lookup: str = None,
sub_type: RuleType = None, regex: str = None) -> None:
sub_type: 'RuleType' = None, regex: str = None) -> None:
"""RuleType init
Args:
Expand Down
3 changes: 1 addition & 2 deletions yamlator/validators/base_validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Base Yamlator validator"""

from __future__ import annotations
from collections import deque

from yamlator.types import Data
Expand All @@ -22,7 +21,7 @@ def __init__(self, violations: deque) -> None:
"""
self._violations = violations

def set_next_validator(self, validator: Validator) -> Validator:
def set_next_validator(self, validator: 'Validator') -> 'Validator':
"""Set the next validator in the chain
Args:
Expand Down
1 change: 0 additions & 1 deletion yamlator/violations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Contains classes related to handling different violations"""


from __future__ import annotations
import json

from collections import deque
Expand Down

0 comments on commit 2bc3d58

Please sign in to comment.