From f72956a26e3d5e26741470050038e70d9e39af84 Mon Sep 17 00:00:00 2001 From: nobbi1991 <48419518+nobbi1991@users.noreply.github.com> Date: Mon, 12 Dec 2022 23:10:04 +0100 Subject: [PATCH] Removed tests from py-pkg | no open files after parsing (#113) * exclude tests folder from python package * don't leave open files * bump version * updated release notes --- CHANGELOG.md | 7 +++++++ ldfparser/parser.py | 9 ++++++--- setup.cfg | 2 +- setup.py | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7af7a..d0e33be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.18.0] - 2022-12-13 + +### Changed + +- Remove `tests` folder from python package +- Close all files which are opened by the ldfparser + ## [0.17.0] - 2022-10-17 ### Added diff --git a/ldfparser/parser.py b/ldfparser/parser.py index 0131fad..9b78431 100644 --- a/ldfparser/parser.py +++ b/ldfparser/parser.py @@ -24,12 +24,15 @@ def parse_ldf_to_dict(path: str, capture_comments: bool = False, encoding: str = :type encoding: str """ comments = [] - lark = os.path.abspath(os.path.join(os.path.dirname(__file__), 'grammars', 'ldf.lark')) - parser = Lark(grammar=open(lark), parser='lalr', lexer_callbacks={ + lark_file = os.path.abspath(os.path.join(os.path.dirname(__file__), 'grammars', 'ldf.lark')) + with open(lark_file, "r", encoding=encoding) as lark_file: + grammar = lark_file.read() + parser = Lark(grammar=grammar, parser='lalr', lexer_callbacks={ 'C_COMMENT': comments.append, 'CPP_COMMENT': comments.append }, propagate_positions=True) - ldf_file = open(path, "r", encoding=encoding).read() + with open(path, "r", encoding=encoding) as input_file: + ldf_file = input_file.read() tree = parser.parse(ldf_file) json = LdfTransformer().transform(tree) diff --git a/setup.cfg b/setup.cfg index 1fb6010..0def4c5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,2 @@ [metadata] -version = 0.17.0 +version = 0.18.0 diff --git a/setup.py b/setup.py index 102ff66..f584453 100644 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/c4deszes/ldfparser", - packages=find_packages(), + packages=find_packages(exclude=["tests"]), package_data={'': ['*.lark']}, license='MIT', keywords=['LIN', 'LDF'],