Skip to content

Commit

Permalink
Merge pull request #56 from urbanopt/develop
Browse files Browse the repository at this point in the history
Merge to main for release
  • Loading branch information
nllong authored Mar 30, 2023
2 parents 6de129b + 13d7ad9 commit a3f9c2c
Show file tree
Hide file tree
Showing 23 changed files with 301 additions and 273 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: 3.7
python-version: 3.8
- name: Set up package
run: |
pip install -U pip setuptools
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exclude: |
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand Down Expand Up @@ -41,14 +41,14 @@ repos:
"--remove-all-unused-imports",
"--remove-unused-variable",
]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
args:
["--ignore=F401,E402,E501,E731,W503,W504", "--max-line-length=100"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.6.2
rev: v3.0.0-alpha.4
hooks:
- id: prettier
# for now ignoring html, javascript
Expand Down
25 changes: 15 additions & 10 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,37 @@
Changelog
=========

Version 0.2.3
=============
* Update precommit and ci by @nllong in https://github.com/urbanopt/modelica-builder/pull/54
* Update overwrite_component_redeclaration to handle the redeclare of args by @nllong in https://github.com/urbanopt/modelica-builder/pull/53

Version 0.2.2
=============

- Add component argument/parameter deletion, remove_component_argument
- Add test for deleting a "constant Ingeger x=5" component
- Update testing dependencies
- Add component redeclare package argument replacement
* Add component argument/parameter deletion, remove_component_argument
* Add test for deleting a "constant Ingeger x=5" component
* Update testing dependencies
* Add component redeclare package argument replacement

Version 0.2.1
=============

- Fix import issue when installing package for a poetry-managed projects
* Fix import issue when installing package for a poetry-managed projects

Version 0.2.0
=============

- Fix compatibility with files containing '\r\n', which is typically used on Windows
* Fix compatibility with files containing '\r\n', which is typically used on Windows

Version 0.1.1
=============

- Add ability to rename a component's argument name
- Convert to use GitHub actions instead of Travis
- Update README with more practical example
* Add ability to rename a component's argument name
* Convert to use GitHub actions instead of Travis
* Update README with more practical example

Version 0.1.0
=============

- Initial release
* Initial release
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
Copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.

BSD 3-Clause License
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Release Instructions
--------------------

* Bump version to <NEW_VERSION> in setup.cfg (use semantic versioning as much as possible).
* Run `autopep8` to nicely format the code (or run `pre-commit --all-files`).
* Run `pre-commit --all-files`
* Create a PR against develop into main.
* Run `git tag <NEW_VERSION>`. (Note that `python setup.py --version` pulls from the latest tag`.)
* After main branch passes, then merge and checkout the main branch. Build the distribution using the following code:
Expand Down
2 changes: 1 addition & 1 deletion modelica_builder/builder.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down
2 changes: 1 addition & 1 deletion modelica_builder/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down
2 changes: 1 addition & 1 deletion modelica_builder/edit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down
20 changes: 15 additions & 5 deletions modelica_builder/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down Expand Up @@ -181,18 +181,28 @@ def rename_component_argument(self, type_, identifier, old_argument_name, new_ar

self.add(SimpleTransformation(selector, Edit.make_replace(f'{new_argument_name}')))

def overwrite_component_redeclaration(self, type_, identifier, new_declaration):
def overwrite_component_redeclaration(self, type_, identifier, new_redeclaration, existing_redeclaration=None):
"""
Overwrite the component redeclaration with a new string
:param type_: string, type of the component
:param identifier: string, component identifier
:param new_declaration: string, new component redeclaration string. It is the entire string, i.e., argument=value
:param new_redeclaration: string, new component redeclaration string. It is the entire string, i.e., redeclare argument=value
:param existing_redeclaration: string, existing argument redeclaration string. Defaults to None.
"""
# In the case of `redeclare a.b.c update`, the existing declaration query is
# actually a combination of two objects that get concatenated. So remove
# the spaces in the existing_declaration if it is passed int.
prepend_redeclare = False
if existing_redeclaration:
existing_redeclaration = existing_redeclaration.replace(' ', '')
prepend_redeclare = True
selector = (ComponentDeclarationSelector(type_, identifier)
.chain(ComponentRedeclarationSelector()))
.chain(ComponentRedeclarationSelector(existing_redeclaration)))

self.add(SimpleTransformation(selector, Edit.make_replace(f'{new_declaration}')))
if prepend_redeclare:
new_redeclaration = f'redeclare {new_redeclaration}'
self.add(SimpleTransformation(selector, Edit.make_replace(f'{new_redeclaration}')))

def remove_component(self, type_=None, identifier=None):
"""remove_component removes a component declaration.
Expand Down
2 changes: 1 addition & 1 deletion modelica_builder/modelica_parser/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down
35 changes: 28 additions & 7 deletions modelica_builder/selector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down Expand Up @@ -392,17 +392,38 @@ class ComponentRedeclarationSelector(Selector):
"""
BASE_PATH = 'stored_definition/class_definition/class_specifier/long_class_specifier/composition/element_list/element/component_clause/component_list/component_declaration'

def __init__(self):
def __init__(self, argument_name):
"""
:param modification_name: str, mane of the modification to select
:param modification_value: None | str, if not None, it only selects modifications with this value
:param argument_name: str, name of the argument to select, if None, then it will look for `redeclare package`
"""

self._argument_name = argument_name
super().__init__()

def _select(self, base, parser):
# select the element_reclaration's short_class_specifier
xpath = 'component_declaration/declaration/modification/class_modification/argument_list/argument/element_redeclaration/short_class_definition/short_class_specifier'
xpath = 'component_declaration/declaration/modification/class_modification/argument_list'

# select the element_reclaration's short_class_specifier for component redeclarations
filtered_modifications = []
redeclare_package_xpath = xpath + '/argument/element_redeclaration/short_class_definition/short_class_specifier'
element_modifications = XPath.XPath.findAll(base, redeclare_package_xpath, parser)
if len(element_modifications) == 1:
filtered_modifications.append(element_modifications[0])

# now look for other redeclases in the argument list -- first get all the arguments
element_modifications = XPath.XPath.findAll(base, xpath, parser)

return element_modifications
# setup the sub xpath to get the argument name and value
arg_xpath = '/argument/element_redeclaration/component_clause1'

# iterate over the arguments
for element_modification in element_modifications:
# filter modifications (ie arguments) to those that match our name
for index, child in enumerate(element_modification.children):
argument_name_texts = XPath.XPath.findAll(child, arg_xpath, parser)
# should only be one, if there isn't one, then skip, otherwise error
if len(argument_name_texts) == 1:
if argument_name_texts[0].getText() == self._argument_name:
filtered_modifications.append(child)

return filtered_modifications
2 changes: 1 addition & 1 deletion modelica_builder/transformation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down
2 changes: 1 addition & 1 deletion modelica_builder/transformer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

[metadata]
name = modelica-builder
description = Modelica builder enables parsing and modification of Modelica files
version = 0.2.2
description = Modelica builder enables programmatic parsing and modification of Modelica files
version = 0.2.3
author = Nicholas Long
author_email = nicholas.long@nrel.gov
license = BSD-3 Clause
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PYTHON_REGEX = re.compile(r'^""".\*{100}.*:copyright.*\*{100}."""$', re.MULTILINE | re.DOTALL)
PYTHON_LICENSE = '''"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""'''
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
****************************************************************************************************
:copyright (c) 2020-2022, Alliance for Sustainable Energy, LLC.
:copyright (c) 2020-2023, Alliance for Sustainable Energy, LLC.
All rights reserved.
****************************************************************************************************
"""
Expand Down
Loading

0 comments on commit a3f9c2c

Please sign in to comment.