Skip to content

Commit 45dbaa7

Browse files
authored
Merge pull request #193 from pnnl/test-workflows
Add automated linting as a github action.
2 parents 84a99be + d0060d5 commit 45dbaa7

File tree

19 files changed

+2654
-26
lines changed

19 files changed

+2654
-26
lines changed

.github/workflows/lint.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Lint and test
5+
6+
on:
7+
push:
8+
branches: [ "main", "develop", "test-workflows"]
9+
pull_request:
10+
branches: [ "main", "develop", "test-workflows"]
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
python-version: ["3.11", "3.12", "3.13"]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up Python ${{ matrix.python-version }}
24+
uses: actions/setup-python@v4
25+
with:
26+
python-version: ${{ matrix.python-version }}
27+
28+
- name: Install dependencies
29+
run: |
30+
pip install -e ./src/tesp_support
31+
pip install ruff pytest mypy
32+
33+
- name: Lint with ruff
34+
run: |
35+
# Test code with ruff. This will check for syntax and runtime errors.
36+
# The values after --ignore prefixes that match all error codes starting with those characters.
37+
# F codes found at https://flake8.pycqa.org/en/latest/user/error-codes.html
38+
# F841 unused-variable
39+
# E9xx: Runtime (https://pycodestyle.pycqa.org/en/latest/intro.html#error-codes)
40+
# E731 lambda-assignment
41+
ruff check ./src --ignore=F841,E731
42+
# exit-zero treats all errors as warnings.
43+
# ruff check ./src --exit-zero --statistics
44+
45+
- name: Check types with mypy
46+
run: |
47+
# Stop the build if there are Python syntax errors and runtime errors.
48+
# The values after --disable-error-code ignores match codes starting with those characters.
49+
mypy ./src/tesp_support/tesp_support/api --disable-error-code import-untyped --disable-error-code union-attr --disable-error-code attr-defined --disable-error-code import-not-found
50+
51+
- name: Test with pytest
52+
run: |
53+
source ./tesp.env
54+
pytest ./src/tesp_support/test/api # only api tests for now

.github/workflows/pypi-publish.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Deploy PYPI Project CI
2+
3+
on:
4+
push:
5+
branches: [ "main"]
6+
tags:
7+
- 'v*' # Triggers on version tags
8+
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: '3.10'
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install setuptools wheel twine build
26+
27+
- name: Build package
28+
run: |
29+
cd src/tesp_support
30+
python -m build .
31+
32+
- name: Publish to PyPI
33+
env:
34+
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} # Use your PyPI username
35+
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} # Store your token in GitHub secrets
36+
# TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD_TEST }} # Store your token in GitHub secrets
37+
run: |
38+
printf "Deploying PYPI project"
39+
twine upload src/tesp_support/dist/*
40+
# twine upload --repository testpypi src/tesp_support/dist/*

examples/analysis/consensus/code/post_processing/TMG_plots.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2815,7 +2815,7 @@ def customer_comparative_analysis(case_data, comp_data, case_path, comp_path, ds
28152815
# x = customer_diff_df.loc(axis=0)[:, ['kw-hr']]
28162816

28172817
customer_diff_df.to_csv(path_or_buf=case_path + '\\customer_diff_data_DSO'+dso_num+'.csv')
2818-
participating = customer_diff_df.loc[customer_diff_df[('metadata','participating')] == True]
2818+
participating = customer_diff_df.loc[customer_diff_df[('metadata','participating')]]
28192819

28202820
plt.figure()
28212821
plt.scatter(participating[('metadata','slider_setting')], -100*participating[(month,'kw-hr')])

examples/analysis/dsot/code/run_annual_postprocessing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def run_annual_postprocessing(case_list: list, base_case_path: str, demand_case_
186186
logger.info("Run base: %s", run_base)
187187

188188
# Process the base case first
189-
if run_base == True:
189+
if run_base:
190190
case_list.insert(0, str(base_case_path))
191191
logger.info("Added base case to processing list")
192192
else:

examples/analysis/glm_dsot/code/run_annual_postprocessing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run_annual_postprocessing(case_list: list, base_case_path: str, demand_case_
8282
"""
8383

8484
# Process the base case first
85-
if run_base == True:
85+
if run_base:
8686
case_list.insert(0, str(base_case_path))
8787
else:
8888
pass

examples/capabilities/ercot/bulk_system/loopERCOT.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def make_dictionary(ppc, rootname):
282282
# run OPF to establish the prices and economic dispatch
283283
if ts >= tnext_opf:
284284
ropf = pp.runopf(ppc, ppopt_market)
285-
if ropf['success'] == False:
285+
if not ropf['success']:
286286
conv_accum = False
287287
opf_bus = deepcopy(ropf['bus'])
288288
opf_gen = deepcopy(ropf['gen'])
@@ -321,7 +321,7 @@ def make_dictionary(ppc, rootname):
321321
ppc['bus'][:, 13] = opf_bus[:, 13] # set the lmp
322322
ppc['gen'][:, 1] = opf_gen[:, 1] # set the economic dispatch
323323
rpf = pp.runpf(ppc, ppopt_regular)
324-
if rpf[0]['success'] == False:
324+
if not rpf[0]['success']:
325325
conv_accum = False
326326
print('rpf did not converge at', ts)
327327
# pp.printpf (100.0,

examples/capabilities/ercot/case8/tso_most.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ def tso_most_loop_f(bTestDAM=False, test_bids=None):
910910
write_most_base_case(ppc, 'rtmcase_{:d}.m'.format(ts))
911911
# rBus, rBranch, rGen, rGenCost = solve_most_rtm_case(ppc['MostCommand'], 'solvertmcase.m')
912912
ropf = pp.runopf(ppc, ppopt_market)
913-
if ropf['success'] == False:
913+
if not ropf['success']:
914914
ropf['bus'][:, 13] = ppc['lmp_cap']
915915
conv_accum = False
916916
opf_bus = deepcopy(ropf['bus'])

examples/capabilities/ercot/case8/tso_psst_f.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,7 @@ def update_cost_and_load():
13141314

13151315
# tso.print_mod_load(ppc['bus'], ppc['DSO'], gld_load, 'OPF', ts)
13161316
ropf = pp.runopf(ppc, ppopt_market)
1317-
if ropf['success'] == False:
1317+
if not ropf['success']:
13181318
conv_accum = False
13191319
opf_bus = deepcopy(ropf['bus'])
13201320
opf_gen = deepcopy(ropf['gen'])

models/lbnl/dockers/Estimation/develop/w_energyplus/workflow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def param_estimation(model_param, ADD_UNIT_EP_TZONE):
132132
emulation.collect_measurements(estimation_start_time, estimation_stop_time)
133133

134134
# Add units to EnergyPlus output variables
135-
if ((ADD_UNIT_EP_TZONE == True) and obs_var == 'Tzone'):
135+
if ((ADD_UNIT_EP_TZONE) and obs_var == 'Tzone'):
136136
print("==========WARNING: When using E+FMU, if the output of E+ is the "
137137
"zone temperature, then the next lines will add the unit degC to the "
138138
"output results. This is only valid for E+ and an output which is Tzone.")

models/pitt/Reduced_Order_Model/tesp_support/feederGenerator.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,7 @@ def write_houses(basenode, op, vnom):
13151315
else:
13161316
vstart = format(-0.5 * vnom, '.2f') + '+' + format(0.866025 * vnom, '.2f') + 'j'
13171317

1318-
if forERCOT == True:
1318+
if forERCOT:
13191319
phs = phs + 'S'
13201320
tpxname = gld_strict_name(basenode + '_tpx')
13211321
mtrname = gld_strict_name(basenode + '_mtr')
@@ -1328,7 +1328,7 @@ def write_houses(basenode, op, vnom):
13281328
print(' voltage_2 ' + vstart + ';', file=op)
13291329
print('}', file=op)
13301330
for i in range(nhouse):
1331-
if forERCOT == False:
1331+
if not forERCOT:
13321332
tpxname = gld_strict_name(basenode + '_tpx_' + str(i + 1))
13331333
mtrname = gld_strict_name(basenode + '_mtr_' + str(i + 1))
13341334
print('object triplex_line {', file=op)
@@ -1700,7 +1700,7 @@ def write_substation(op, name, phs, vnom, vll):
17001700
if len(fncs_case) > 0:
17011701
print('#ifdef USE_FNCS', file=op)
17021702
print('object fncs_msg {', file=op)
1703-
if forERCOT == True:
1703+
if forERCOT:
17041704
print(' name gridlabd' + fncs_case + ';', file=op)
17051705
else:
17061706
print(' name gridlabdSimulator1;', file=op)
@@ -1760,7 +1760,7 @@ def write_voltage_class(model, h, t, op, vprim, vll, secmtrnode):
17601760
bHaveS = True
17611761
else:
17621762
bHaveS = False
1763-
if bHaveS == True and bHadS == False:
1763+
if bHaveS and not bHadS:
17641764
prefix = 'triplex_'
17651765
print('object ' + prefix + t + ' {', file=op)
17661766
if len(parent) > 0:
@@ -1776,17 +1776,17 @@ def write_voltage_class(model, h, t, op, vprim, vll, secmtrnode):
17761776
if 'load_class' in model[t][o]:
17771777
print(' load_class ' + model[t][o]['load_class'] + ';', file=op)
17781778
if 'constant_power_A' in model[t][o]:
1779-
if bHaveS == True:
1779+
if bHaveS:
17801780
print(' power_1 ' + model[t][o]['constant_power_A'] + ';', file=op)
17811781
else:
17821782
print(' constant_power_A ' + model[t][o]['constant_power_A'] + ';', file=op)
17831783
if 'constant_power_B' in model[t][o]:
1784-
if bHaveS == True:
1784+
if bHaveS:
17851785
print(' power_1 ' + model[t][o]['constant_power_B'] + ';', file=op)
17861786
else:
17871787
print(' constant_power_B ' + model[t][o]['constant_power_B'] + ';', file=op)
17881788
if 'constant_power_C' in model[t][o]:
1789-
if bHaveS == True:
1789+
if bHaveS:
17901790
print(' power_1 ' + model[t][o]['constant_power_C'] + ';', file=op)
17911791
else:
17921792
print(' constant_power_C ' + model[t][o]['constant_power_C'] + ';', file=op)
@@ -1800,19 +1800,19 @@ def write_voltage_class(model, h, t, op, vprim, vll, secmtrnode):
18001800
vstartb = format(-0.5 * vnom, '.2f') + format(-0.866025 * vnom, '.2f') + 'j'
18011801
vstartc = format(-0.5 * vnom, '.2f') + '+' + format(0.866025 * vnom, '.2f') + 'j'
18021802
if 'voltage_A' in model[t][o]:
1803-
if bHaveS == True:
1803+
if bHaveS:
18041804
print(' voltage_1 ' + vstarta + ';', file=op)
18051805
print(' voltage_2 ' + vstarta + ';', file=op)
18061806
else:
18071807
print(' voltage_A ' + vstarta + ';', file=op)
18081808
if 'voltage_B' in model[t][o]:
1809-
if bHaveS == True:
1809+
if bHaveS:
18101810
print(' voltage_1 ' + vstartb + ';', file=op)
18111811
print(' voltage_2 ' + vstartb + ';', file=op)
18121812
else:
18131813
print(' voltage_B ' + vstartb + ';', file=op)
18141814
if 'voltage_C' in model[t][o]:
1815-
if bHaveS == True:
1815+
if bHaveS:
18161816
print(' voltage_1 ' + vstartc + ';', file=op)
18171817
print(' voltage_2 ' + vstartc + ';', file=op)
18181818
else:
@@ -2120,7 +2120,7 @@ def ProcessTaxonomyFeeder(outname, rootname, vll, vln, avghouse, avgcommercial):
21202120
if metrics_interval > 0:
21212121
print('object metrics_collector_writer {', file=op)
21222122
print(' interval', str(metrics_interval) + ';', file=op)
2123-
if forERCOT == True:
2123+
if forERCOT:
21242124
print(' // filename ${METRICS_FILE};', file=op)
21252125
print(' filename ' + outname + '_metrics.json;', file=op)
21262126
else:
@@ -2268,7 +2268,7 @@ def ProcessTaxonomyFeeder(outname, rootname, vll, vln, avghouse, avgcommercial):
22682268
write_link_class(model, h, 'transformer', seg_loads, op)
22692269
write_link_class(model, h, 'capacitor', seg_loads, op)
22702270

2271-
if forERCOT == True:
2271+
if forERCOT:
22722272
identify_ercot_houses(model, h, 'load', 0.001 * avghouse, rgn)
22732273
connect_ercot_houses(model, h, op, vln, 120.0)
22742274
for key in house_nodes:
@@ -2287,7 +2287,7 @@ def ProcessTaxonomyFeeder(outname, rootname, vll, vln, avghouse, avgcommercial):
22872287

22882288
write_voltage_class(model, h, 'node', op, vln, vll, secnode)
22892289
write_voltage_class(model, h, 'meter', op, vln, vll, secnode)
2290-
if forERCOT == False:
2290+
if not forERCOT:
22912291
write_voltage_class(model, h, 'load', op, vln, vll, secnode)
22922292
if len(Eplus_Bus) > 0 and Eplus_Volts > 0.0 and Eplus_kVA > 0.0:
22932293
print('////////// EnergyPlus large-building load ///////////////', file=op)

0 commit comments

Comments
 (0)