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

Task/update GitHub #9

Merged
merged 7 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt
pylint src --errors-only
pylint src tests --errors-only
- name: Build package
run: pytest --junitxml output/report.xml
run: |
pip install -e .
pytest --junitxml output/report.xml
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ output/
venv/
build/
dist/
.pypirc
.env
dmtgen.egg-info/
8 changes: 8 additions & 0 deletions .pypirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[distutils]
index-servers =
gitlab

[gitlab]
repository = https://gitlab.sintef.no/api/v4/projects/${env.CI_PROJECT_ID}/packages/pypi
username = gitlab-ci-token
password = ${env.CI_JOB_TOKEN}
2 changes: 1 addition & 1 deletion publish.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set -e

python setup.py clean --all sdist bdist_wheel
python -m build --wheel --sdist

if $PUBLISH_LIB; then
python -m twine upload dist/* --config-file .pypirc
Expand Down
5 changes: 2 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
setuptools==65.5.1
wheel==0.38.1
twine==3.2.0
build
twine
pytest
pylint
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='dmtgen',
version='0.5.0.dev1',
version='0.5.0',
author="SINTEF Ocean",
description="Python generator utilities for DMT",
long_description=long_description,
Expand Down
10 changes: 5 additions & 5 deletions src/dmtgen/base_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, root_dir: Path, package_name: str,
self.source_only = False
self.root_package = root_package

# pylint: disable=unused-argument, no-self-use
# pylint: disable=unused-argument
def get_template_generator(self, template: Path, config: Dict) -> TemplateBasedGenerator:
""" Override in subclasses to control which template generator to use"""
return BasicTemplateGenerator()
Expand Down Expand Up @@ -72,10 +72,10 @@ def __find_templates_and_generate(self, output_dir: Path, config: Dict):
@staticmethod
def __read_template(templatefile: Path):
loader = jinja2.FileSystemLoader(templatefile.parents[0])
env_parameters = dict(
loader=loader,
undefined=jinja2.StrictUndefined
)
env_parameters = {
"loader": loader,
"undefined":jinja2.StrictUndefined
}
environment = jinja2.Environment(**env_parameters)
environment.filters["escape_string"] = escape_string
return environment.get_template(templatefile.name)
Expand Down
47 changes: 29 additions & 18 deletions src/dmtgen/common/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,23 @@
class Blueprint:
""" " A basic SIMOS Blueprint"""

def __init__(self, bp_dict: Dict, parent: Package) -> None:
# pylint: disable=too-many-instance-attributes
def __init__(self, content: Dict, parent: Package) -> None:
self.parent = parent
self.blueprint = bp_dict
self.name = self.blueprint["name"]
self.description = bp_dict.get("description","")
self.__abstract = bp_dict.get("abstract",False)
self.content = content
self.name: str = self.content["name"]
self.description: str = content.get("description",None)
attributes = {}
for a_dict in bp_dict.get("attributes",[]):
for a_dict in content.get("attributes",[]):
attribute = BlueprintAttribute(a_dict, self)
attributes[attribute.name]=attribute
self.__abstract = content.get("abstract",False)
self.__attributes = attributes
extends = bp_dict.get("extends",[])
self.__extends = extends
self.__extends = content.get("extends",[])
# We will resolve this later
self.__extensions = None


@property
def abstract(self) -> bool:
"""If the blueprint represent an abstract type"""
return self.__abstract

@property
def attributes(self) -> Sequence[BlueprintAttribute]:
"""Attributes"""
Expand All @@ -53,17 +48,33 @@ def extensions(self) -> Sequence[Blueprint]:
if self.__extensions is not None:
return self.__extensions

self.__extensions = [self.__resolve(extension) for extension in self.__extends]
self.__extensions = [self.__resolve_extension(extension) for extension in self.__extends]
return self.__extensions

def __resolve(self,extension: str):
def resolve(self):
""" Resolve all attributes"""
for attribute in self.__attributes.values():
attribute.resolve()


def __resolve_extension(self,extension: str):
package: Package = self.parent
return package.get_blueprint(extension)
resolved = package.resolve_type(extension)
return package.get_blueprint(resolved)

def is_abstract(self) -> bool:
"""If the blueprint represent an abstract type.
In object oriented terms, this would be an interface or abstract class."""
return self.__abstract

def get_path(self):
""" Get full path to blueprint """
""" Get full path to blueprint"""
parent = self.parent
if parent:
return parent.get_path() + "/" + self.name
# Then we are at root
return "/" + self.name
return self.name

def get_attribute(self, name:str) -> BlueprintAttribute:
""" Return the attribute if it exists, otherwise None"""
return self.all_attributes.get(name,None)
89 changes: 68 additions & 21 deletions src/dmtgen/common/blueprint_attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
class BlueprintAttribute:
""" " A basic SIMOS Attribute"""

def __init__(self, content: Dict, parent_blueprint: Blueprint) -> None:
# pylint: disable=too-many-instance-attributes
def __init__(self, content: Dict, parent: Blueprint) -> None:
self.content = content
name = content["name"]
if len(name)==0:
Expand All @@ -24,48 +25,94 @@ def __init__(self, content: Dict, parent_blueprint: Blueprint) -> None:
self.dimensions = []

atype = content["attributeType"]
self.parent = parent_blueprint
package = parent_blueprint.parent
self.type = package.resolve_type(atype)
self.is_primitive = atype in ['boolean', 'number', 'string', 'integer']
self.is_enum = self.content.get("enumType",None) is not None
self.is_blueprint = not (self.is_primitive or self.is_enum)
self.is_optional = self.content.get("optional",True)
self.is_array = len(self.dimensions)>0
self.is_contained = content.get("contained",True)
self.__parent = parent
self.__type = atype
self.__optional = self.content.get("optional",True)
self.__is_primitive = atype in ['boolean', 'number', 'string', 'integer']
self.enum_type = self.content.get("enumType",None)
self.__is_enum = self.enum_type is not None
self.__is_blueprint = not (self.__is_primitive or self.__is_enum)
self.__is_array = len(self.dimensions)>0
self.__is_string = self.type == "string"
self.__is_boolean = self.type == "boolean"
self.__is_integer = self.type == "integer"
self.__is_number = self.type == "number"
self.__is_contained = content.get("contained",True)

def resolve(self):
""" Resolve to correct type"""
package = self.parent.parent
self.__type = package.resolve_type(self.__type)
if self.enum_type:
self.enum_type = package.resolve_type(self.enum_type)

@property
def parent(self) -> Blueprint:
"""The parent blueprint"""
return self.__parent

@property
def type(self) -> str:
"""The type of the attribute"""
return self.__type

@property
def optional(self) -> bool:
"""Is this an optional attribute"""
return self.__optional

@property
def contained(self) -> bool:
"""Is this a contained attribute"""
return self.__is_contained

def is_primitive(self) -> bool:
"""Is this a primitive type"""
return self.__is_primitive

def is_enum(self) -> bool:
"""Is this an enum type"""
return self.__is_enum

def is_blueprint(self) -> bool:
"""Is this a blueprint type"""
return self.__is_blueprint

def is_string(self) -> bool:
"""Is this a string"""
return self.type == "string"
return self.__is_string

@property
def is_boolean(self) -> bool:
"""Is this a boolean"""
return self.type == "boolean"
return self.__is_boolean

@property
def is_integer(self) -> bool:
"""Is this an integer"""
return self.type == "integer"
return self.__is_integer

@property
def is_number(self) -> bool:
"""Is this a number"""
return self.type == "number"
return self.__is_number

def is_optional(self) -> bool:
"""Is an optional relation"""
return self.__optional

@property
def is_required(self) -> bool:
"""Is a required relation"""
return not self.is_optional
return not self.__optional

def is_array(self) -> bool:
"""Is this an array"""
return self.__is_array

def is_fixed_array(self) -> bool:
"""Is this a fixed array"""
return self.is_array and "*" not in self.dimensions
return self.__is_array and "*" not in self.dimensions

def is_variable_array(self) -> bool:
"""Is this a variable array"""
return self.is_array and "*" in self.dimensions
return self.__is_array and "*" in self.dimensions

def get(self, key, default=None):
"""Return the content value or an optional default"""
Expand Down
Loading