Skip to content
Open
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
21 changes: 0 additions & 21 deletions .github/workflows/flake8.yml

This file was deleted.

18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint

on: [push]

jobs:
lint:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Check precommit hooks
uses: pre-commit/action@v3.0.0
Comment on lines +1 to +18
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the "flake8" workflow with this one that will run the precommit hook on all files, and as such do flake8, black, isort and mypy

12 changes: 7 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: PyPIRelease

on:
push:
branches: [ main ]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release workflow builds the wheel for main too

tags:
- '*'

Expand All @@ -10,23 +11,24 @@ jobs:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v2
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Pip Dependencies
shell: bash
run: pip install -r requirements.txt
run: pip install --upgrade build

- name: Build the Wheel
shell: bash
run: rm -rf dist/ build/ && python3 setup.py bdist_wheel sdist
run: rm -rf dist/ build/ && python3 -m build

- name: Deploy on Test PyPi
uses: pypa/gh-action-pypi-publish@37f50c210e3d2f9450da2cd423303d6a14a6e29f # v1.5.1
if: contains(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
Comment on lines 29 to +31
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But only upload to pypi when it's a tag

with:
user: __token__
password: ${{ secrets.PYPIPW }}
16 changes: 13 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,34 @@ jobs:
wget: 'C:\msys64\usr\bin\wget.exe' # -q GitHub actions can't find wget at this location
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v2

- uses: actions/checkout@v4

- name: Set up Python 3.8
uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Python Dependencies
run: pip install pysparklines
run: pip install -e .

- name: Download EnergyPlus
run: ${{ matrix.wget }} "https://github.com/NREL/EnergyPlus/releases/download/v22.2.0/${{ matrix.file_base_name }}${{ matrix.file_extension }}" -O "energyplus${{ matrix.file_extension }}"

- name: Extract EnergyPlus
run: ${{ matrix.extract_command }} "energyplus${{ matrix.file_extension }}"

- name: Run Example Script 01
run: python ./energyplus_api_helpers/demos/01_simple_library_call.py "./${{ matrix.file_base_name }}"

# - name: Run Example Script 02
# run: python ./energyplus_api_helpers/demos/02_threaded.py "./${{ matrix.file_base_name }}"
#
- name: Run Example Script 03
run: python ./energyplus_api_helpers/demos/03_multiprocessed.py "./${{ matrix.file_base_name }}"

- name: Run Example Script 04
run: python ./energyplus_api_helpers/demos/04_dynamic_terminal_output_progress.py "./${{ matrix.file_base_name }}"

- name: Run Example Script 05
run: python ./energyplus_api_helpers/demos/05_dynamic_terminal_output.py "./${{ matrix.file_base_name }}"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,3 @@ cython_debug/

.vscode
*.code-workspace

23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
hooks:
- id: mypy
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-pyproject]
Comment on lines +1 to +23
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a pre-commit hook for linting / checking

38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# EnergyPlus API Helper Scripts

[![pypi](https://img.shields.io/pypi/v/energyplus-api-helpers.svg)](https://pypi.org/project/energyplus-api-helpers/)
[![python](https://img.shields.io/pypi/pyversions/energyplus-api-helpers.svg)](https://pypi.org/project/energyplus-api-helpers/)
[![Build Status](https://github.com/Myoldmopar/EnergyPlusAPIHelper/actions/workflows/test.yml/badge.svg)](https://github.com/Myoldmopar/EnergyPlusAPIHelper/actions/workflows/test.yml)

This project is a small library of helper functionality and, more importantly, demo scripts, for interacting with the EnergyPlus API.
The EnergyPlus Python API is not on PyPi (as of now), it simply comes with the EnergyPlus installation.
This library makes that process a bit easier, and also offers a set of demos in the `energyplus_api_helpers/demos` folder.

## Usage

A super minimal example using the helper class here:

```python
Expand All @@ -20,16 +26,40 @@ In this example, the helper class is constructed simply by pointing it to a vali
The helper class is then used to get an EnergyPlus API instance, which is in turn used to create a new EnergyPlus "state".
Finally, EnergyPlus is executed with some basic command line arguments passed into the `run_energyplus` function of the main EnergyPlus API.

### Inferring EnergyPlus path

It is possible to call `helper = EnergyPlusHelper()` (without a path argument), in which case the helper tries to locate your E+ installation directory.

It does so checking, in order of preference:

* Any `energyplus` executable in your `PATH`
* By trying to locate the most recent EnergyPlus version installed in a default location

## Code Quality

[![Flake8](https://github.com/Myoldmopar/EnergyPlusAPIDemos/actions/workflows/flake8.yml/badge.svg)](https://github.com/Myoldmopar/EnergyPlusAPIDemos/actions/workflows/flake8.yml)
[![Lint](https://github.com/Myoldmopar/EnergyPlusAPIHelper/actions/workflows/lint.yml/badge.svg)](https://github.com/Myoldmopar/EnergyPlusAPIHelper/actions/workflows/lint.yml)

Code is checked for style using GitHub Actions (flake8, black, isort, mypy).

## Contributing

You should install this project along with development dependencies via:

```
pip install -e .[dev]
```

There is a pre-commit configuration you should install if you plan on contributing:

```
pre-commit install
```

Code is checked for style using GitHub Actions.

## Releases

[![PyPIRelease](https://github.com/Myoldmopar/EnergyPlusAPIDemos/actions/workflows/release.yml/badge.svg)](https://github.com/Myoldmopar/EnergyPlusAPIDemos/actions/workflows/release.yml)
[![PyPIRelease](https://github.com/Myoldmopar/EnergyPlusAPIHelper/actions/workflows/release.yml/badge.svg)](https://github.com/Myoldmopar/EnergyPlusAPIDemos/actions/workflows/release.yml)

When a release is tagged, a GitHub Action workflow will create a Python wheel and upload it to the PyPi server.

To install into an existing Python environment, execute `pip install energyplus_api_helpers`
To install into an existing Python environment, execute `pip install energyplus-api-helpers`
19 changes: 3 additions & 16 deletions energyplus_api_helpers/demos/01_simple_library_call.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
from pathlib import Path
from sys import argv
from energyplus_api_helpers.demos.helper import get_eplus_path_from_argv1
from energyplus_api_helpers.import_helper import EPlusAPIHelper


eplus_path = '/eplus/installs/EnergyPlus-22-2-0'
if len(argv) > 1:
eplus_path = argv[1]

e = EPlusAPIHelper(Path(eplus_path))
e = EPlusAPIHelper(get_eplus_path_from_argv1())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example usage of the helper in one of the demo files

api = e.get_api_instance()
state = api.state_manager.new_state()
return_value = api.runtime.run_energyplus(
state, [
'-d',
e.get_temp_run_dir(),
'-a',
'-w',
e.weather_file_path(),
e.path_to_test_file('5ZoneAirCooled.idf')
]
state, ["-d", e.get_temp_run_dir(), "-a", "-w", e.weather_file_path(), e.path_to_test_file("5ZoneAirCooled.idf")]
)
20 changes: 4 additions & 16 deletions energyplus_api_helpers/demos/02_threaded.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
from pathlib import Path
from sys import argv
from threading import Thread
from energyplus_api_helpers.import_helper import EPlusAPIHelper


eplus_path = '/eplus/installs/EnergyPlus-22-2-0'
if len(argv) > 1:
eplus_path = argv[1]
from energyplus_api_helpers.demos.helper import get_eplus_path_from_argv1
from energyplus_api_helpers.import_helper import EPlusAPIHelper


def thread_function(_working_dir: str):
print(f"Thread: Running at working dir: {_working_dir}")
state = api.state_manager.new_state()
api.runtime.run_energyplus(
state, [
'-d',
_working_dir,
'-a',
'-w',
e.weather_file_path(),
e.path_to_test_file('5ZoneAirCooled.idf')
]
state, ["-d", _working_dir, "-a", "-w", e.weather_file_path(), e.path_to_test_file("5ZoneAirCooled.idf")]
)


e = EPlusAPIHelper(Path(eplus_path))
e = EPlusAPIHelper(get_eplus_path_from_argv1())
api = e.get_api_instance()
for index in range(3):
working_dir = e.get_temp_run_dir()
Expand Down
19 changes: 4 additions & 15 deletions energyplus_api_helpers/demos/03_multiprocessed.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
from pathlib import Path
import multiprocessing as mp
from sys import argv
from energyplus_api_helpers.import_helper import EPlusAPIHelper

eplus_path = '/eplus/installs/EnergyPlus-22-2-0'
if len(argv) > 1:
eplus_path = argv[1]
from energyplus_api_helpers.demos.helper import get_eplus_path_from_argv1
from energyplus_api_helpers.import_helper import EPlusAPIHelper


def subprocess_function():
e = EPlusAPIHelper(Path(eplus_path))
e = EPlusAPIHelper(get_eplus_path_from_argv1())
api = e.get_api_instance()
working_dir = e.get_temp_run_dir()
print(f"Thread: Running at working dir: {working_dir}")
state = api.state_manager.new_state()
api.runtime.run_energyplus(
state, [
'-d',
working_dir,
'-a',
'-w',
e.weather_file_path(),
e.path_to_test_file('1ZoneUncontrolled.idf')
]
state, ["-d", working_dir, "-a", "-w", e.weather_file_path(), e.path_to_test_file("1ZoneUncontrolled.idf")]
)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
from pathlib import Path
from sys import argv
from energyplus_api_helpers.demos.helper import get_eplus_path_from_argv1
from energyplus_api_helpers.import_helper import EPlusAPIHelper

eplus_path = '/eplus/installs/EnergyPlus-22-2-0'
if len(argv) > 1:
eplus_path = argv[1]


def progress_update(percent):
filled_length = int(80 * (percent / 100.0))
bar = "*" * filled_length + '-' * (80 - filled_length)
print(f'\rProgress: |{bar}| {percent}%', end="\r")
bar = "*" * filled_length + "-" * (80 - filled_length)
print(f"\rProgress: |{bar}| {percent}%", end="\r")


e = EPlusAPIHelper(Path(eplus_path))
e = EPlusAPIHelper(get_eplus_path_from_argv1())
api = e.get_api_instance()
state = api.state_manager.new_state()
api.runtime.set_console_output_status(state, False)
api.runtime.callback_progress(state, progress_update)
result = api.runtime.run_energyplus(
state,
[
'-d',
e.get_temp_run_dir(),
'-w',
e.weather_file_path(),
"-a",
e.path_to_test_file('5ZoneAirCooled.idf')
]
state, ["-d", e.get_temp_run_dir(), "-w", e.weather_file_path(), "-a", e.path_to_test_file("5ZoneAirCooled.idf")]
)
if result == 0:
print("Success, finished")
Expand Down
Loading