Skip to content

Commit

Permalink
Merge pull request #303 from ioannis-vm/FIX_preview_rules
Browse files Browse the repository at this point in the history
Ruff: Disallow unsafe fixes and revert changes.
  • Loading branch information
fmckenna authored Aug 15, 2024
2 parents 15a21a1 + 1dadbab commit 125b166
Show file tree
Hide file tree
Showing 320 changed files with 3,221 additions and 3,080 deletions.
2 changes: 1 addition & 1 deletion build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python # noqa: EXE001, D100, CPY001
#!/usr/bin/env python # noqa: EXE001, D100

from bincrafters import build_template_default

Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os # noqa: D100, CPY001
import os # noqa: D100

from conans import CMake, ConanFile

Expand Down
6 changes: 3 additions & 3 deletions modules/Workflow/AggregateResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def main(threads=1): # noqa: C901, D103
if use_dask:
log_msg(f'{threads} threads requested. Using DASK.')

import math # noqa: PLC0415
import math

from dask import delayed # noqa: PLC0415
from dask.distributed import Client, LocalCluster # noqa: PLC0415
from dask import delayed
from dask.distributed import Client, LocalCluster

@delayed
def read_csv_files(file_list, header):
Expand Down
34 changes: 17 additions & 17 deletions modules/Workflow/CreateWorkflowJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def generate_workflow_tasks( # noqa: C901, D103
jobId = os.getenv('SLURM_JOB_ID') # We might need this later # noqa: N806, F841

# get the type of outputs requested
with open(f'{rWHALE_dir}/{config_file}') as f: # noqa: PLW1514, PTH123
with open(f'{rWHALE_dir}/{config_file}') as f: # noqa: PTH123
settings = json.load(f)
output_types = [
out_type
Expand All @@ -75,13 +75,13 @@ def generate_workflow_tasks( # noqa: C901, D103
)

# get the list of buildings requested to run
if bldg_filter == '': # noqa: PLC1901
if bldg_filter == '':
# we pull the bldg_filter from the config file
bldg_filter = settings['Applications']['Building']['ApplicationData'].get(
'filter', ''
)

if bldg_filter == '': # noqa: PLC1901
if bldg_filter == '':
raise ValueError( # noqa: TRY003
'Running a regional simulation on DesignSafe requires either ' # noqa: EM101
"the 'buildingFilter' parameter to be set for the workflow "
Expand Down Expand Up @@ -137,7 +137,7 @@ def generate_workflow_tasks( # noqa: C901, D103
filter = filter[1:] # to remove the initial comma # noqa: A001

if (i % 500) == 0:
subfolder = subfolder + 1 # noqa: PLR6104
subfolder = subfolder + 1

run_dir = (
f'/tmp/{rWHALE_dir}' # noqa: S108
Expand Down Expand Up @@ -167,7 +167,7 @@ def generate_workflow_tasks( # noqa: C901, D103
for out_type in output_types:
res_type = None

if out_type in ['BIM', 'EDP', 'DM', 'DV']: # noqa: PLR6201
if out_type in ['BIM', 'EDP', 'DM', 'DV']:
res_type = out_type
file_name = f'{res_type}*.csv'
elif out_type == 'every_realization':
Expand All @@ -188,7 +188,7 @@ def generate_workflow_tasks( # noqa: C901, D103
task_list += f'rm -rf {run_dir} \n'

# write the tasks to the output file
with open('WorkflowJobs.txt', 'a+') as tasksFile: # noqa: N806, PLW1514, PTH123
with open('WorkflowJobs.txt', 'a+') as tasksFile: # noqa: PTH123, N806
tasksFile.write(task_list)


Expand All @@ -202,7 +202,7 @@ def generate_workflow_tasks_siteresponse( # noqa: D103
jobId = os.getenv('SLURM_JOB_ID') # We might need this later # noqa: N806, F841

# get the type of outputs requested
with open(f'{rWHALE_dir}/{config_file}') as f: # noqa: PLW1514, PTH123
with open(f'{rWHALE_dir}/{config_file}') as f: # noqa: PTH123
settings = json.load(f)
output_types = [ # noqa: F841
out_type
Expand All @@ -211,13 +211,13 @@ def generate_workflow_tasks_siteresponse( # noqa: D103
]

# get the list of buildings requested to run
if bldg_filter == '': # noqa: PLC1901
if bldg_filter == '':
# we pull the bldg_filter from the config file
bldg_filter = settings['Applications']['Building']['ApplicationData'].get(
'filter', ''
)

if bldg_filter == '': # noqa: PLC1901
if bldg_filter == '':
raise ValueError( # noqa: TRY003
'Running a regional simulation on DesignSafe requires either ' # noqa: EM101
"the 'buildingFilter' parameter to be set for the workflow "
Expand Down Expand Up @@ -277,7 +277,7 @@ def generate_workflow_tasks_siteresponse( # noqa: D103
filter = filter[1:] # to remove the initial comma # noqa: A001

if (i % 500) == 0:
subfolder = subfolder + 1 # noqa: PLR6104
subfolder = subfolder + 1

run_dir = (
f'/tmp/{rWHALE_dir}' # noqa: S108
Expand Down Expand Up @@ -315,7 +315,7 @@ def generate_workflow_tasks_siteresponse( # noqa: D103
task_list += "echo 'cmd generated. Currend dir: '$PWD \n"

# write the tasks to the output file
with open('WorkflowJobs_siteResponse.txt', 'a+') as tasksFile: # noqa: N806, PLW1514, PTH123
with open('WorkflowJobs_siteResponse.txt', 'a+') as tasksFile: # noqa: PTH123, N806
tasksFile.write(task_list)


Expand All @@ -332,7 +332,7 @@ def generate_workflow_tasks_regionalsiteresponse( # noqa: C901, D103
output_valid = ['IM']

# get the type of outputs requested
with open(f'{rWHALE_dir}/{config_file}') as f: # noqa: PLW1514, PTH123
with open(f'{rWHALE_dir}/{config_file}') as f: # noqa: PTH123
settings = json.load(f)
output_types = [
out_type
Expand All @@ -341,13 +341,13 @@ def generate_workflow_tasks_regionalsiteresponse( # noqa: C901, D103
]

# get the list of sites requested to run
if site_filter == '': # noqa: PLC1901
if site_filter == '':
# we pull the site_filter from the config file
site_filter = settings['Applications']['RegionalEvent'][
'ApplicationData'
].get('filter', '')

if site_filter == '': # noqa: PLC1901
if site_filter == '':
raise ValueError( # noqa: TRY003
'Running a regional simulation on DesignSafe requires either ' # noqa: EM101
"the 'buildingFilter' parameter to be set for the workflow "
Expand Down Expand Up @@ -403,7 +403,7 @@ def generate_workflow_tasks_regionalsiteresponse( # noqa: C901, D103
filter = filter[1:] # to remove the initial comma # noqa: A001

if (i % 500) == 0:
subfolder = subfolder + 1 # noqa: PLR6104
subfolder = subfolder + 1

run_dir = (
f'/tmp/{rWHALE_dir}' # noqa: S108
Expand Down Expand Up @@ -434,7 +434,7 @@ def generate_workflow_tasks_regionalsiteresponse( # noqa: C901, D103
for out_type in output_types:
res_type = None

if out_type in ['IM', 'BIM', 'EDP', 'DM', 'DV']: # noqa: PLR6201
if out_type in ['IM', 'BIM', 'EDP', 'DM', 'DV']:
res_type = out_type
file_name = f'{res_type}*.csv'
elif out_type == 'every_realization':
Expand All @@ -455,7 +455,7 @@ def generate_workflow_tasks_regionalsiteresponse( # noqa: C901, D103
task_list += f'rm -rf {run_dir} \n'

# write the tasks to the output file
with open('WorkflowJobs_SiteResponse.txt', 'a+') as tasksFile: # noqa: N806, PLW1514, PTH123
with open('WorkflowJobs_SiteResponse.txt', 'a+') as tasksFile: # noqa: PTH123, N806
tasksFile.write(task_list)


Expand Down
4 changes: 2 additions & 2 deletions modules/Workflow/EE-UQ workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@

def main(run_type, input_file, app_registry): # noqa: D103
# initialize the log file
with open(input_file) as f: # noqa: PLW1514, PTH123
with open(input_file) as f: # noqa: PTH123
inputs = json.load(f)
runDir = inputs['runDir'] # noqa: N806

whale.log_file = runDir + '/log.txt'
with open(whale.log_file, 'w') as f: # noqa: FURB103, PLW1514, PTH123
with open(whale.log_file, 'w') as f: # noqa: PTH123
f.write('EE-UQ workflow\n')

# echo the inputs
Expand Down
22 changes: 11 additions & 11 deletions modules/Workflow/EE-UQ.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# written: fmk, adamzs # noqa: CPY001, D100, EXE002, INP001
# written: fmk, adamzs # noqa: EXE002, INP001, D100

# import functions for Python 2.X support
import sys
Expand All @@ -20,13 +20,13 @@
from WorkflowUtils import * # noqa: E402, F403


def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803, PLR0912, PLR0914, PLR0915
def main(run_type, inputFile, applicationsRegistry): # noqa: C901, N803, D103, PLR0912, PLR0915
# the whole workflow is wrapped within a 'try' block.
# a number of exceptions (files missing, explicit application failures, etc.) are
# handled explicitly to aid the user.
# But unhandled exceptions case the workflow to stop with an error, handled in the
# exception block way at the bottom of this main() function
try: # noqa: PLR1702
try:
workflow_log(divider) # noqa: F405
workflow_log('Start of run') # noqa: F405
workflow_log(divider) # noqa: F405
Expand All @@ -39,7 +39,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
# first we parse the applications registry to load all possible applications
# - for each application type we place in a dictionary key being name, value containing path to executable
#
with open(applicationsRegistry) as data_file: # noqa: PLW1514, PTH123
with open(applicationsRegistry) as data_file: # noqa: PTH123
registryData = json.load(data_file) # noqa: N806
# convert all relative paths to full paths

Expand All @@ -64,7 +64,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
# open input file, and parse json into data
#

with open(inputFile) as data_file: # noqa: PLW1514, PTH123
with open(inputFile) as data_file: # noqa: PTH123
data = json.load(data_file)
# convert all relative paths to full paths
# relative2fullpath(data)
Expand Down Expand Up @@ -300,7 +300,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
driverFile = 'driver' # noqa: N806

# open driver file & write building app (minus the --getRV) to it
driverFILE = open(driverFile, 'w') # noqa: N806, PLW1514, PTH123, SIM115
driverFILE = open(driverFile, 'w') # noqa: SIM115, PTH123, N806

# get RV for event
eventAppDataList = [ # noqa: N806
Expand Down Expand Up @@ -346,7 +346,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
modelAppDataList.insert(0, 'python')

for key in modelingAppData.keys(): # noqa: SIM118
modelAppDataList.append('--' + key) # noqa: FURB113
modelAppDataList.append('--' + key)
modelAppDataList.append('' + modelingAppData.get(key))

for item in modelAppDataList:
Expand Down Expand Up @@ -380,7 +380,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
edpAppDataList.insert(0, 'python')

for key in edpAppData.keys(): # noqa: SIM118
edpAppDataList.append('--' + key) # noqa: FURB113
edpAppDataList.append('--' + key)
edpAppDataList.append('' + edpAppData.get(key))

for item in edpAppDataList:
Expand Down Expand Up @@ -415,7 +415,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
simAppDataList.insert(0, 'python')

for key in simAppData.keys(): # noqa: SIM118
simAppDataList.append('--' + key) # noqa: FURB113
simAppDataList.append('--' + key)
simAppDataList.append('' + simAppData.get(key))

for item in simAppDataList:
Expand Down Expand Up @@ -454,7 +454,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
uqAppDataList.insert(0, 'python')
uqAppDataList[1] = uqAppExeLocal

uqAppDataList.append('--runType') # noqa: FURB113
uqAppDataList.append('--runType')
uqAppDataList.append(run_type)

for key in uqAppData.keys(): # noqa: SIM118
Expand Down Expand Up @@ -506,7 +506,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
workflow_log_file = 'workflow-log-%s.txt' % ( # noqa: UP031
strftime('%Y-%m-%d-%H-%M-%S-utc', gmtime())
)
log_filehandle = open(workflow_log_file, 'w') # noqa: PLW1514, PTH123, SIM115
log_filehandle = open(workflow_log_file, 'w') # noqa: SIM115, PTH123

print(type(log_filehandle)) # noqa: T201
print(divider, file=log_filehandle)
Expand Down
20 changes: 10 additions & 10 deletions modules/Workflow/GMT.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# written: fmk, adamzs # noqa: CPY001, D100, EXE002, INP001
# written: fmk, adamzs # noqa: EXE002, INP001, D100

# import functions for Python 2.X support
import sys
Expand All @@ -20,13 +20,13 @@
from WorkflowUtils import * # noqa: E402, F403


def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803, PLR0912, PLR0914, PLR0915
def main(run_type, inputFile, applicationsRegistry): # noqa: C901, N803, D103, PLR0912, PLR0915
# the whole workflow is wrapped within a 'try' block.
# a number of exceptions (files missing, explicit application failures, etc.) are
# handled explicitly to aid the user.
# But unhandled exceptions case the workflow to stop with an error, handled in the
# exception block way at the bottom of this main() function
try: # noqa: PLR1702
try:
workflow_log(divider) # noqa: F405
workflow_log('Start of run') # noqa: F405
workflow_log(divider) # noqa: F405
Expand All @@ -39,7 +39,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
# first we parse the applications registry to load all possible applications
# - for each application type we place in a dictionary key being name, value containing path to executable
#
with open(applicationsRegistry) as data_file: # noqa: PLW1514, PTH123
with open(applicationsRegistry) as data_file: # noqa: PTH123
registryData = json.load(data_file) # noqa: N806
# convert all relative paths to full paths

Expand All @@ -64,7 +64,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
# open input file, and parse json into data
#

with open(inputFile) as data_file: # noqa: PLW1514, PTH123
with open(inputFile) as data_file: # noqa: PTH123
data = json.load(data_file)
# convert all relative paths to full paths
# relative2fullpath(data)
Expand Down Expand Up @@ -253,7 +253,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
driverFile = 'driver' # noqa: N806

# open driver file & write building app (minus the --getRV) to it
driverFILE = open(driverFile, 'w') # noqa: N806, PLW1514, PTH123, SIM115
driverFILE = open(driverFile, 'w') # noqa: SIM115, PTH123, N806

# get RV for event
eventAppDataList = [ # noqa: N806
Expand Down Expand Up @@ -300,7 +300,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
edpAppDataList.insert(0, 'python')

for key in edpAppData.keys(): # noqa: SIM118
edpAppDataList.append('--' + key) # noqa: FURB113
edpAppDataList.append('--' + key)
edpAppDataList.append('' + edpAppData.get(key))

for item in edpAppDataList:
Expand Down Expand Up @@ -335,7 +335,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
simAppDataList.insert(0, 'python')

for key in simAppData.keys(): # noqa: SIM118
simAppDataList.append('--' + key) # noqa: FURB113
simAppDataList.append('--' + key)
simAppDataList.append('' + simAppData.get(key))

for item in simAppDataList:
Expand Down Expand Up @@ -379,7 +379,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
uqAppDataList.insert(0, 'python')
uqAppDataList[1] = uqAppExeLocal

uqAppDataList.append('--runType') # noqa: FURB113
uqAppDataList.append('--runType')
uqAppDataList.append(run_type)

print(uqAppDataList) # noqa: T201
Expand Down Expand Up @@ -433,7 +433,7 @@ def main(run_type, inputFile, applicationsRegistry): # noqa: C901, D103, N803,
workflow_log_file = 'workflow-log-%s.txt' % ( # noqa: UP031
strftime('%Y-%m-%d-%H-%M-%S-utc', gmtime())
)
log_filehandle = open(workflow_log_file, 'w') # noqa: PLW1514, PTH123, SIM115
log_filehandle = open(workflow_log_file, 'w') # noqa: SIM115, PTH123

print(type(log_filehandle)) # noqa: T201
print(divider, file=log_filehandle)
Expand Down
Loading

0 comments on commit 125b166

Please sign in to comment.