Skip to content

Commit 0a32f0f

Browse files
authored
Add lint workflow (#23)
* Remove __main__ files * Remove gravity migration webservice * Remove Kurt's stuff from DT * Lint everything * Add linting workflow
1 parent c6f2a2b commit 0a32f0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+767
-6861
lines changed

.github/workflows/lint.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Lint
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.py'
7+
8+
pull_request:
9+
paths:
10+
- '**.py'
11+
12+
jobs:
13+
run-linters:
14+
name: Run linters
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out Git repository
18+
uses: actions/checkout@v4
19+
- name: Set up Python
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: 3.9
23+
- name: Install Python dependencies
24+
run: |
25+
python -m pip install .[lint]
26+
- name: Lint
27+
run: |
28+
flake8 --ignore=E501,E261,W503 --exclude=.dtk_tools emod_api

emod_api/__main__.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

emod_api/campaign.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import json
77

8+
from emod_api import schema_to_class as s2c
9+
810
schema_path = None
911
_schema_json = None
1012
campaign_dict = {"Events": [], "Use_Defaults": 1}
@@ -21,20 +23,18 @@
2123

2224

2325
def reset():
24-
del (campaign_dict["Events"][:])
25-
global pubsub_signals_subbing
26-
global pubsub_signals_pubbing
27-
global adhocs
28-
global event_map
29-
del (pubsub_signals_subbing[:])
30-
del (pubsub_signals_pubbing[:])
31-
del (adhocs[:])
32-
del (custom_coordinator_events[:])
33-
del (custom_node_events[:])
34-
event_map = {}
35-
from emod_api import schema_to_class as s2c
26+
campaign_dict["Events"].clear()
27+
28+
pubsub_signals_subbing.clear()
29+
pubsub_signals_pubbing.clear()
30+
adhocs.clear()
31+
custom_coordinator_events.clear()
32+
custom_node_events.clear()
33+
implicits.clear()
34+
35+
event_map.clear()
36+
3637
s2c.clear_schema_cache()
37-
del (implicits[:])
3838

3939

4040
def set_schema(schema_path_in):
@@ -62,16 +62,15 @@ def get_schema():
6262

6363
def add(event, name=None, first=False):
6464
"""
65-
Add a complete campaign event to the campaign builder. The new event is assumed to be a Python dict, and a
66-
valid event. The new event is not validated here.
65+
Add a complete campaign event to the campaign builder. The new event is assumed to be a Python dict, and a
66+
valid event. The new event is not validated here.
6767
Set the first flag to True if this is the first event in a campaign because it functions as an
6868
accumulator and in some situations like sweeps it might have been used recently.
6969
"""
7070
event.finalize()
7171
if first:
7272
print("Use of 'first' flag is deprecated. Use set_schema to start build a new, empty campaign.")
73-
global campaign_dict
74-
campaign_dict["Events"] = []
73+
campaign_dict["Events"].clear()
7574
if "Event_Name" not in event and name is not None:
7675
event["Event_Name"] = name
7776
if "Listening" in event:
@@ -91,7 +90,7 @@ def get_trigger_list():
9190
try:
9291
trigger_list = get_schema()["idmTypes"]["idmAbstractType:EventCoordinator"]["BroadcastCoordinatorEvent"][
9392
"Broadcast_Event"]["enum"]
94-
except Exception as ex:
93+
except Exception:
9594
trigger_list = get_schema()["idmTypes"]["idmType:IncidenceCounter"]["Trigger_Condition_List"]["Built-in"]
9695
return trigger_list
9796

emod_api/channelreports/__main__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

emod_api/channelreports/channels.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
"""Module for reading InsetChart.json channels."""
44

5-
from csv import writer as CsvWriter
65
from datetime import datetime
76
import json
87
from pathlib import Path
98
from typing import Dict, List, Union
10-
import warnings
11-
129
import pandas as pd
1310

1411
_CHANNELS = "Channels"
@@ -410,7 +407,7 @@ def validate_channel(_channel, _title, _header) -> None:
410407

411408
return
412409

413-
def to_csv(self, filename: Union[str, Path], channel_names: List[str]=None, transpose: bool=False) -> None:
410+
def to_csv(self, filename: Union[str, Path], channel_names: List[str] = None, transpose: bool = False) -> None:
414411

415412
"""
416413
Write each channel from the report to a row, CSV style, in the given file.

emod_api/channelreports/icj_to_csv.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
import json
33
import pandas as pd
44

5-
def _get_sim_years( output_path ):
65

7-
if not os.path.exists( "config.json" ):
6+
def _get_sim_years(output_path):
7+
8+
if not os.path.exists("config.json"):
89
return None
9-
with open( "config.json" ) as config_fp:
10-
config = json.load( config_fp )
10+
with open("config.json") as config_fp:
11+
config = json.load(config_fp)
1112
if "Base_Year" not in config["parameters"]:
1213
return None
1314

1415
base_year = config["parameters"]["Base_Year"]
15-
step = config["parameters"]["Simulation_Timestep"]/365
16-
steps = round(config["parameters"]["Simulation_Duration"]/step)
17-
18-
sim_year = [ base_year + step * x for x in range(steps) ]
16+
step = config["parameters"]["Simulation_Timestep"] / 365
17+
steps = round(config["parameters"]["Simulation_Duration"] / step)
18+
19+
sim_year = [base_year + step * x for x in range(steps)]
1920
return sim_year
2021

21-
def inset_chart_json_to_csv_dataframe_pd( output_path: str ):
22+
23+
def inset_chart_json_to_csv_dataframe_pd(output_path: str):
2224
"""
2325
Convert InsetChart.json file in 'output_path' to InsetChart.csv.
2426
Adding Simulation_Year column if Base_Year exists in config.json.
@@ -34,15 +36,15 @@ def inset_chart_json_to_csv_dataframe_pd( output_path: str ):
3436
ValueError: if InsetChart.csv can't be written.
3537
"""
3638

37-
icj_path = os.path.join( output_path, "InsetChart.json" )
38-
if not os.path.exists( icj_path ):
39-
raise ValueError( f"InsetChart.json not found at {output_path}." )
39+
icj_path = os.path.join(output_path, "InsetChart.json")
40+
if not os.path.exists(icj_path):
41+
raise ValueError(f"InsetChart.json not found at {output_path}.")
4042

4143
# Load JSON data from file
42-
with open( icj_path ) as fp:
43-
icj = json.load( fp )
44+
with open(icj_path) as fp:
45+
icj = json.load(fp)
4446

45-
optional_years_channel = _get_sim_years( output_path )
47+
optional_years_channel = _get_sim_years(output_path)
4648
if optional_years_channel:
4749
icj["Channels"]["Simulation_Year"]["Data"] = optional_years_channel
4850

@@ -56,8 +58,8 @@ def inset_chart_json_to_csv_dataframe_pd( output_path: str ):
5658

5759
try:
5860
# Convert DataFrame to CSV
59-
csv_path = os.path.join( output_path, "InsetChart.csv" )
61+
csv_path = os.path.join(output_path, "InsetChart.csv")
6062
df.to_csv(csv_path, index=False)
6163
except Exception as ex:
62-
print( f"ERROR: Exception {ex} while writing csv dataframe of InsetChart.json to disk." )
63-
raise ValueError( ex )
64+
print(f"ERROR: Exception {ex} while writing csv dataframe of InsetChart.json to disk.")
65+
raise ValueError(ex)

0 commit comments

Comments
 (0)