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

Poetry #297

Merged
merged 28 commits into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d5628b6
poetry config file
vtnate Jan 29, 2021
e646831
temporary rename of requirements & setup files
vtnate Jan 29, 2021
4f84004
update tox to work with python
vtnate Jan 29, 2021
b253c3c
reference github repo properly
vtnate Jan 29, 2021
099bd8e
include poetry.lock file
vtnate Jan 29, 2021
fb2a995
remove outdated comment
vtnate Feb 3, 2021
32bee83
update poetry & tox configs
vtnate Feb 3, 2021
fb377ab
more tox changes
vtnate Feb 3, 2021
12eb364
Merge branch 'develop' into poetry
vtnate Feb 3, 2021
23fc084
set precommit hook to work with poetry
vtnate Feb 3, 2021
d324f28
update format_modelica_files to be a click command
vtnate Feb 3, 2021
fbe0d5d
clean up tox file yet more
vtnate Feb 3, 2021
1bbd5d3
poetry config file to work with precommit hooks
vtnate Feb 3, 2021
d1a5e5b
Use poetry in CI
vtnate Feb 3, 2021
10a5400
fix typo in ci.yml
vtnate Feb 3, 2021
f8eca40
add cd as dependency in docs tox env
vtnate Feb 3, 2021
45ffe33
use changedir instead of cd for docs test
vtnate Feb 4, 2021
c3d3629
whitelist_externals is deprecated, use allowlist_externals instead
vtnate Feb 4, 2021
aec1a06
update scripts to work with poetry
vtnate Feb 4, 2021
1a69f66
ap & pc
vtnate Feb 4, 2021
7b8c443
remove commented lines
vtnate Feb 4, 2021
6c67908
Merge branch 'develop' into poetry
vtnate Feb 4, 2021
11c82d3
remove commented lines
vtnate Feb 4, 2021
89d755d
Merge branch 'poetry' of https://github.com/urbanopt/geojson-modelica…
vtnate Feb 4, 2021
b7063a3
Merge remote-tracking branch 'origin/develop' into poetry
nllong Feb 5, 2021
a2d8158
cleanup readme and fix update_schemas
nllong Feb 5, 2021
3b03261
change readme to suggest running tox instead of py.test
vtnate Feb 5, 2021
dfc9c51
remove outdate setup files
vtnate Feb 5, 2021
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
58 changes: 20 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# 3.8, 3.9 do not work at the moment.
# 3.9 does not work as of 2020-02-01
nllong marked this conversation as resolved.
Show resolved Hide resolved
python-version: [3.7]
test_env: [python, precommit, docs]
steps:
- uses: actions/checkout@v2
-
Expand All @@ -24,23 +25,35 @@ jobs:
python -c "import sys; print(sys.version)"
docker --version
docker-compose --version
-
vtnate marked this conversation as resolved.
Show resolved Hide resolved
name: Set up Poetry
run: |
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
# NOTE: Poetry won't be in PATH until following steps
echo "$HOME/.poetry/bin" >> $GITHUB_PATH
$HOME/.poetry/bin/poetry install
-
name: Print Environment
run: poetry --version
-
name: Install dependencies
env:
MODELICAPATH: /home/runner/work/modelica-buildings
run: |
# Install modelicafmt (hard code the version for now)
curl -SLO https://github.com/urbanopt/modelica-fmt/releases/download/v0.1-pr.3/modelica-fmt_0.1-pr.3_Linux_x86_64.tar.gz
vtnate marked this conversation as resolved.
Show resolved Hide resolved
tar xzf modelica-fmt_0.1-pr.3_Linux_x86_64.tar.gz
chmod +x modelicafmt
sudo mv modelicafmt /usr/local/bin/
# Install MBL
git clone --single-branch --branch issue2204_gmt_mbl https://github.com/lbl-srg/modelica-buildings.git $MODELICAPATH
cd $MODELICAPATH
echo "Git branch is $(git branch)"
pip install --upgrade pip
pip install tox==3.13.2
-
name: Run unittests (using tox)
name: Tox ${{ matrix.test_env }}
env:
MODELICAPATH: /home/runner/work/modelica-buildings
run: |
echo $(pwd)
tox -e python
run: poetry run tox -e ${{ matrix.test_env }}
-
name: Job Failed
if: ${{ failure() }}
Expand All @@ -60,34 +73,3 @@ jobs:
with:
name: test-output
path: tests/model_connectors/output
formatting:
runs-on: ubuntu-latest
strategy:
matrix:
tox_env: [flake8, docs]
steps:
-
uses: actions/checkout@v2
-
uses: actions/setup-python@v2
with:
python-version: '3.7'
-
name: Install deps
run: |
# Install modelicafmt (hard code the version for now)
curl -SLO https://github.com/urbanopt/modelica-fmt/releases/download/v0.1-pr.3/modelica-fmt_0.1-pr.3_Linux_x86_64.tar.gz
tar xzf modelica-fmt_0.1-pr.3_Linux_x86_64.tar.gz
chmod +x modelicafmt
sudo mv modelicafmt /usr/local/bin/
pip install --upgrade pip
pip install tox==3.13.2
pip install requests
-
name: Run pre-commit
run: |
pip install pre-commit
pre-commit run --show-diff-on-failure --color=always --all-files
-
name: Run tox
run: tox -e ${{ matrix.tox_env }}
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ repos:
name: Modelica Formatter
types: [file]
files: \.(mo|mot)$
entry: python setup.py format_modelica_files
entry: poetry run format_modelica_files
language: system
pass_filenames: false
35 changes: 13 additions & 22 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ GeoJSON Modelica Translator (GMT)
Description
-----------

The GeoJSON Modelica Translator (GMT) is a one-way trip from GeoJSON in combination with a well-defined instance of the system parameters schema to a Modelica project with multiple buildings loads, energy transfer stations, district system, and distribution network. The project will eventually allow multiple paths to build up different district heating and cooling system topolologies; however, the initial implementation is limited to 1GDH and 4GDC.
The GeoJSON Modelica Translator (GMT) is a one-way trip from GeoJSON in combination with a well-defined instance of the system parameters schema to a Modelica package with multiple buildings loads, energy transfer stations, distribution networks, and central plants. The project will eventually allow multiple paths to build up different district heating and cooling system topologies; however, the initial implementation is limited to 1GDH and 4GDHC.

Getting Started
---------------

The GeoJSON Modelica Translator is in alpha-phase development and the functionality is limited. Currently, the proposed approach for getting started is outlined in this readme. Currently you need Python 3 and Pip 3 to install/build the packages. Python 2 is at end of life and should be avoided; however, Python 2 may still be needed to run the models with JModelica (this is actively being evaluated). Note that the best approach is to use Docker to run the Modelica models as this approach does not require Python 2.
The GeoJSON Modelica Translator is in alpha-phase development and the functionality is limited. Currently, the proposed approach for getting started is outlined in this readme. You need Python 3, pip 3, and Poetry to install/build the packages. Note that the best approach is to use Docker to run the Modelica models as this approach does not require Python 2.

* Clone this repo into a working directory
* (optional/as-needed) Add Python 3 to the environment variables
* Install Poetry (:code:`pip install poetry`). More information on Poetry can be found `here <https://python-poetry.org/docs/>`_.
* Install `Docker <https://docs.docker.com/get-docker/>`_ for your platform
* Configure Docker on your local desktop to have at least 4 GB Ram and 2 Cores. This is configured under the Docker Preferences.
* Configure Docker on your local desktop to have at least 4 GB Ram and 2 cores. This is configured under the Docker Preferences.
* Install the Modelica Buildings Library from GitHub
* Clone https://github.com/lbl-srg/modelica-buildings/ into a working directory outside of the GMT directory
* Change to the directory inside the modelica-buildings repo you just checked out. (:code:`cd modelica-buildings`)
Expand All @@ -30,31 +31,22 @@ The GeoJSON Modelica Translator is in alpha-phase development and the functional
* Ubuntu: :code:`sudo apt install git-lfs; git lfs install`
* Pull the correct staging branch for this project with: :code:`git checkout issue2204_gmt_mbl`
* Add the Modelica Buildings Library path to your MODELICAPATH environment variable (e.g., export MODELICAPATH=${MODELICAPATH}:$HOME/path/to/modelica-buildings).
* Return to the GMT directory and run :code:`pip install -r requirements.txt`
* Test if everything is installed correctly by running :code:`py.test`
* Return to the GMT root directory and run :code:`poetry install`
* Test if everything is installed correctly by running :code:`poetry run tox`
* This should run all unit tests, pre-commit, and build the docs.

The py.test tests should all pass assuming the libraries are installed correctly on your computer. Also, there will be a set of Modelica models that are created and persisted into the :code:`tests/output` folder and the :code:`tests/model_connectors/output` folder.
The tests should all pass assuming the libraries are installed correctly on your computer. Also, there will be a set of Modelica models that are created and persisted into the :code:`tests/output` folder and the :code:`tests/model_connectors/output` folder. These files can be inspected in your favorite Modelica editor.

Developers
**********

This project uses several dependencies that are under active development (e.g., modelica-builder, TEASER, etc.). Since
these are included as dependent project using git there may be a need to force an update from the dependent git repos.
The best way to accomplish this is run the following command:

.. code-block::bash

pip install -U --upgrade-strategy eager -r requirements.txt

This project used `pre-commit <https://pre-commit.com/>`_ to ensure code consistency. To enable pre-commit, run the following from the command line.

.. code-block:: bash

pip install pre-commit
pre-commit install

Make sure to install `modelica-fmt <https://github.com/urbanopt/modelica-fmt/releases>`_ in order for pre-commit to run code cleanup on Modelica files. The latest prerelease or release is recommended. Once you download the package, place the modelicafmt binary into a folder that is in your path.

To run pre-commit against the files without calling git commit, then run the following. This is useful when cleaning up the repo before committing.

.. code-block:: bash
Expand Down Expand Up @@ -145,7 +137,7 @@ There is managed task to automatically pull updated GeoJSON schemas from the :co

.. code-block:: bash

./setup.py update_schemas
poetry run update_schemas

The developer should run the test suite after updating the schemas to ensure that nothing appears to have broken. Note that the tests do not cover all of the properties and should not be used as proof that everything works with the updated schemas.

Expand All @@ -157,7 +149,7 @@ To apply the copyright/license to all the files, run the following managed task

.. code-block:: bash

./setup.py update_licenses
poetry run update_licenses


Templating Diagram
Expand All @@ -176,23 +168,22 @@ Release Instructions

# Remove old dist packages
rm -rf dist/*
python setup.py sdist
poetry build

* Run `git tag <NEW_VERSION>`. (Note that `python setup.py --version` pulls from the latest tag.)
* Verify that the files in the dist/* folder have the correct version (no dirty, no sha)
* Run the following to release

.. code-block:: bash

pip install twine
twine upload dist/*
poetry publish

* Build and release the documentation

.. code-block:: bash

# Build and verify with the following
python setup.py build_sphinx
poetry run make html

# release using
./docs/publish_docs.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUR

EMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
vtnate marked this conversation as resolved.
Show resolved Hide resolved
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
"""
****************************************************************************************************
:copyright (c) 2019-2021 URBANopt, Alliance for Sustainable Energy, LLC, and other contributors.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the
distribution.

Neither the name of the copyright holder nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
Expand Down
53 changes: 19 additions & 34 deletions management/format_modelica_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,51 +28,36 @@
****************************************************************************************************
"""

import distutils.cmd
import distutils.log
import os
import re
import subprocess
from pathlib import Path
from tempfile import mkstemp

SKIP_FILES = ['DistrictEnergySystem.mot']
import click

SKIP_FILES = ['DistrictEnergySystem.mot']
TEMPLATE_FILES = Path('geojson_modelica_translator/model_connectors').glob('**/templates/*')


class FormatModelicaFiles(distutils.cmd.Command):
"""Custom comand for applying modelicafmt to modelica files. Note that modelicafmt executable must be available in
your $PATH."""

description = "Formats modelica files"

user_options = [
('file=', 'f', 'Specific file to format')
]
@click.command()
@click.argument('mofile', required=False)
def fmt_modelica_files(mofile):
if mofile is not None:
files = [mofile]
else:
files = TEMPLATE_FILES

def initialize_options(self):
self.file = None

def finalize_options(self):
pass

def run(self):
if self.file is not None:
files = [self.file]
else:
files = TEMPLATE_FILES

for filepath in files:
if os.path.basename(filepath) in SKIP_FILES:
continue
try:
if filepath.suffix == ".mot":
preprocess_and_format(str(filepath))
elif filepath.suffix == ".mo":
apply_formatter(str(filepath))
except FormattingException as e:
self.announce(f'Error processing file {filepath}:\n {e}', level=distutils.log.ERROR)
for filepath in files:
if os.path.basename(filepath) in SKIP_FILES:
continue
try:
if filepath.suffix == ".mot":
preprocess_and_format(str(filepath))
elif filepath.suffix == ".mo":
apply_formatter(str(filepath))
except FormattingException as e:
click.echo(f'Error processing file {filepath}:\n {e}', err=True)


class FormattingException(Exception):
Expand Down
31 changes: 31 additions & 0 deletions management/uo_des.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
"""
****************************************************************************************************
:copyright (c) 2019-2021 URBANopt, Alliance for Sustainable Energy, LLC, and other contributors.

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions
and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions
and the following disclaimer in the documentation and/or other materials provided with the
distribution.

Neither the name of the copyright holder nor the names of its contributors may be used to endorse
or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
****************************************************************************************************
"""


from pathlib import Path

import click
Expand Down
Loading