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

Release v0.2.0 #93

Merged
merged 18 commits into from
Jan 25, 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
3 changes: 1 addition & 2 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.2
current_version = 0.2.0
commit = True
tag = True

Expand All @@ -18,4 +18,3 @@ replace = version = release = "{new_version}"
[bumpversion:file:src/omi/__init__.py]
search = __version__ = "{current_version}"
replace = __version__ = "{new_version}"

1 change: 1 addition & 0 deletions .github/workflows/test-pypi-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- test-release
- 'release/*'
- 'release-*'

jobs:
build-n-publish:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ venv*/
pyvenv*/
/0_env
/1_env
env*/

# Installer logs
pip-log.txt
Expand Down Expand Up @@ -76,3 +77,7 @@ docs/_build

# Mypy Cache
.mypy_cache/


# manual testing scripts
/local_test
7 changes: 6 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
Changelog
=========

current (2022-XX-XX)
current (2024-XX-XX)
--------------------
*

0.2.0 (2024-01-25)
--------------------
* Introduce OMIT_NONE_FIELDS in JSONCompiler class to ease removing / keeping none values in the metadata. By default None values are kept. (#72)[https://github.com/OpenEnergyPlatform/omi/pull/72]

0.1.2 (2023-01-27)
--------------------
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Overview
:alt: PyPI Package latest release
:target: https://pypi.org/project/omi

.. |commits-since| image:: https://img.shields.io/github/commits-since/OpenEnergyPlatform/omi/v0.0.2.svg
.. |commits-since| image:: https://img.shields.io/github/commits-since/OpenEnergyPlatform/omi/v0.2.0.svg
:alt: Commits since latest release
:target: https://github.com/OpenEnergyPlatform/omi/compare/v0.0.2...master
:target: https://github.com/OpenEnergyPlatform/omi/compare/v0.2.0...master

.. |wheel| image:: https://img.shields.io/pypi/wheel/omi.svg
:alt: PyPI Wheel
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
year = "2019"
author = "Martin Glauer"
copyright = "{0}, {1}".format(year, author)
version = release = "0.0.2"
version = release = "0.2.0"

pygments_style = "trac"
templates_path = ["."]
Expand Down
1 change: 1 addition & 0 deletions docs/oep_metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ new metadata format by using the respective dialect
.. doctest::

>>> dialect1_4 = OEP_V_1_4_Dialect()
>>> dialect1_4._compiler.OMIT_NONE_FIELDS = True
>>> dialect1_4.compile(parsed)
{'id': 'unique_id', 'metaMetadata': {'metadataVersion': 'OEP-1.4.0', 'metadataLicense': {'name': 'CC0-1.0', 'title': 'Creative Commons Zero v1.0 Universal', 'path': 'https://creativecommons.org/publicdomain/zero/1.0/'}}}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def read(*names, **kwargs):

setup(
name="omi",
version="0.1.2",
version="0.2.0",
license="AGPL-3.0",
description="A library to process and translate open energy metadata.",
long_description="%s\n%s"
Expand Down
2 changes: 1 addition & 1 deletion src/omi/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.2"
__version__ = "0.2.0"
4 changes: 3 additions & 1 deletion src/omi/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ def grp():
@click.option("-f", help="Dialect identifier of the input")
@click.option("-t", default="oep-v1.5", help="Dialect identifier to translate to")
@click.option("-o", default=None, help="Output file")
@click.option("-omit_nones", default=True, help="Use to either keep or omit all null / none values from the json.")
@click.argument("file_path")
def translate(f, t, o, file_path):
def translate(f, t, o, omit_nones, file_path):
with open(file_path, "r", encoding="utf-8") as infile:
from_dialect = get_dialect(f)()
obj = from_dialect.parse(infile.read())
to_dialect = get_dialect(t)()
to_dialect._compiler.OMIT_NONE_FIELDS = omit_nones
s = to_dialect.compile_and_render(obj)
if o:
with open(o, "w", encoding="utf-8") as outfile:
Expand Down
4 changes: 3 additions & 1 deletion src/omi/dialects/oep/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ def compile_date_or_none(x, format=None):

class JSONCompiler(Compiler):
__METADATA_VERSION = "OEP-1.4.0"
OMIT_NONE_FIELDS = False

def _construct_dict(self, *args, omit_none=True, **kwargs):
def _construct_dict(self, *args, omit_none=None, **kwargs):
"""
Accepts a list of arguments of shape (name: str, field: Compileable) and returns a dictionary that maps
name -> self.visit(field). If `omit_none` is true, fields that are `None` are ignored.
Expand All @@ -32,6 +33,7 @@ def _construct_dict(self, *args, omit_none=True, **kwargs):
-------

"""
omit_none = self.OMIT_NONE_FIELDS
d = {
field_name: self.visit(field)
for field_name, field in args
Expand Down
11 changes: 8 additions & 3 deletions tests/test_cli/test_cli_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@
from omi.cli import translate
import json


def test_cli_translation():
@click.command()
@click.argument('name')
@click.argument("name")
def hello(name):
click.echo('Hello %s!' % name)
click.echo("Hello %s!" % name)

runner = CliRunner()
result = runner.invoke(translate, ["-f", "oep-v1.3", "-t", "oep-v1.4", "tests/data/metadata_v13.json"])
result = runner.invoke(
translate,
["-f", "oep-v1.3", "-t", "oep-v1.4", "-omit_nones", "True", "tests/data/metadata_v13.json"],
)
with open("tests/data/metadata_v13_converted.json") as expected_file:
expected = json.loads(expected_file.read())
print(result)
assert result.exit_code == 0
assert json.loads(result.output) == expected
4 changes: 4 additions & 0 deletions tests/test_dialects/test_oep/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

def test_compiler_v1_5():
compiler = JSONCompilerOEM15()
# omit none values as expected result also does not include None´s
compiler.OMIT_NONE_FIELDS = True
with open("tests/data/metadata_v15.json", "r", encoding="utf-8") as _input_file:
expected_result = json.load(_input_file)
result = compiler.visit(metadata_v_1_5)
Expand All @@ -15,6 +17,8 @@ def test_compiler_v1_5():

def test_compiler_v1_4():
compiler = JSONCompiler()
# omit none values as expected result also does not include None´s
compiler.OMIT_NONE_FIELDS = True
with open("tests/data/metadata_v14.json", "r", encoding="utf-8") as _input_file:
expected_result = json.load(_input_file)
result = compiler.visit(metadata_v_1_4)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dialects/test_oep/test_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
def test_translation_1_3_to_1_4():
parser = JSONParser_1_3()
compiler = JSONCompiler()
# omit none values as expected result also does not include None´s
compiler.OMIT_NONE_FIELDS = True
with open("tests/data/metadata_v13_minimal.json", "r") as _input_file:
input_string = _input_file.read()
# Step 1: Parse JSON to internal structure
Expand Down
Loading