Skip to content

Commit

Permalink
Enable flake8
Browse files Browse the repository at this point in the history
Enables checking the code using flake8
  • Loading branch information
JPEWdev committed Feb 22, 2024
1 parent 1895f4e commit ae64069
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- uses: psf/black@stable
- uses: py-actions/flake8@v2
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dev = [
"pytest >= 7.4",
"pytest-server-fixtures >= 1.7",
"pytest-cov >= 4.1",
"flake8 >= 7.0.0",
]

[project.urls]
Expand Down
6 changes: 3 additions & 3 deletions src/shacl2code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .model import Model, ContextMap
from .main import main
from .version import VERSION
from .model import Model, ContextMap # noqa: F401
from .main import main # noqa: F401
from .version import VERSION # noqa: F401
8 changes: 4 additions & 4 deletions src/shacl2code/lang/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
#
# SPDX-License-Identifier: MIT

from .lang import LANGUAGES
from .lang import LANGUAGES # noqa: F401

# All renderers must be imported here to be registered
from .jinja import JinjaRender
from .python import PythonRender
from .jsonschema import JsonSchemaRender
from .jinja import JinjaRender # noqa: F401
from .python import PythonRender # noqa: F401
from .jsonschema import JsonSchemaRender # noqa: F401
5 changes: 2 additions & 3 deletions src/shacl2code/lang/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
import sys
import os
from contextlib import contextmanager
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, TemplateRuntimeError

from .lang import TEMPLATE_DIR


class OutputFile(object):
def __init__(self, path):
Expand Down Expand Up @@ -88,3 +85,5 @@ def get(self, _id):

with self.__output.open() as f:
f.write(render)
if not render[-1] == "\n":
f.write("\n")
2 changes: 1 addition & 1 deletion src/shacl2code/lang/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path

from .common import BasicJinjaRender
from .lang import language, TEMPLATE_DIR
from .lang import language


@language("jinja")
Expand Down
9 changes: 5 additions & 4 deletions src/shacl2code/lang/templates/python.j2
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class StringProp(Property):
def set(self, value):
return str(value)

def set(self, value):
def get(self, value):
return str(value)

def validate(self, value):
Expand Down Expand Up @@ -538,7 +538,7 @@ class SHACLObject(object):
@classmethod
def deserialize(cls, data, *, object_ids=None, context=None):
for t in ("@type", compact("@type")):
if not t in data:
if t not in data:
continue

typ = data[t]
Expand Down Expand Up @@ -743,7 +743,7 @@ def read_jsonld(f):
"""
data = json.load(f)
object_ids = {}
if not "@graph" in data:
if "@graph" not in data:
objects = [SHACLObject.deserialize(data, object_ids)]
else:
objects = [SHACLObject.deserialize(o, object_ids) for o in data["@graph"]]
Expand Down Expand Up @@ -825,6 +825,7 @@ CONTEXT = {
{%- endfor %}
}
# ENUMERATIONS
{%- for enum in enums %}
{%- if enum.comment %}
Expand All @@ -849,7 +850,6 @@ class {{ enum.clsname }}(EnumProp):
{%- endfor %}
{% endfor %}
# CLASSES
{%- for class in classes %}
{%- if class.comment %}
Expand Down Expand Up @@ -903,6 +903,7 @@ class {{ class.clsname }}(
{%- endfor %}
self._set_init_props(**kwargs)
SHACLObject.DESERIALIZERS["{{ class._id }}"] = {{ class.clsname }}
{% endfor %}
Expand Down
6 changes: 2 additions & 4 deletions src/shacl2code/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import keyword
import re
import typing
from pathlib import Path
from dataclasses import dataclass, field
from dataclasses import dataclass

from pyld import jsonld

Expand Down Expand Up @@ -42,7 +41,7 @@ def __expand(self, _id):
if not ctx:
return _id

if not ":" in _id:
if ":" not in _id:
if _id in ctx:
if isinstance(ctx[_id], dict):
return self.__expand(ctx[_id]["@id"])
Expand Down Expand Up @@ -278,7 +277,6 @@ def __init__(self, model_data, context=None):

tmp_classes = self.classes
done_ids = set()
seen_ids = set()
self.classes = []

while tmp_classes:
Expand Down
2 changes: 1 addition & 1 deletion tests/expect/jsonschema/spdx3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2580,4 +2580,4 @@
"type": "string"
}
}
}
}
Loading

0 comments on commit ae64069

Please sign in to comment.