From 0b817021b4a219ca054a13553acf6f19f85a54ed Mon Sep 17 00:00:00 2001 From: "Mr. Lance E Sloan (lsloan)" Date: Mon, 24 Apr 2023 13:39:38 -0400 Subject: [PATCH] #10 - improve config and Python style N816 actually highlighted a problem, not to be ignored. Rather than have config export variable that's not a constant, move that variable into a function for checking the rest of the config. --- config.py | 35 +++++++++++++++++++++++------------ setup.cfg | 4 ++-- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/config.py b/config.py index 2a30d4d..f9a8eba 100644 --- a/config.py +++ b/config.py @@ -9,21 +9,32 @@ CANVAS_BASE_URL: str = os.getenv('CANVAS_BASE_URL') CANVAS_API_TOKEN: str = os.getenv('CANVAS_API_TOKEN') COURSE_IDS_CSV: str = os.getenv('COURSE_IDS_CSV') +COURSE_IDS: List[str] = [ + c.strip() for c in COURSE_IDS_CSV.split(',') if c +] if COURSE_IDS_CSV else None -envErrors = [] -if CANVAS_BASE_URL is None: - envErrors.append('CANVAS_BASE_URL') +def checkConfig(): + envErrors = [] -if CANVAS_API_TOKEN is None: - envErrors.append('CANVAS_API_TOKEN') + if CANVAS_BASE_URL is None: + envErrors.append('CANVAS_BASE_URL') -if COURSE_IDS_CSV is None: - envErrors.append('COURSE_IDS_CSV') + if CANVAS_API_TOKEN is None: + envErrors.append('CANVAS_API_TOKEN') -if len(envErrors) > 0: - LOGGER.critical('The following environment variable(s) are not set: ' - f'{", ".join(envErrors)}') - sys.exit() + if COURSE_IDS_CSV is None: + envErrors.append('COURSE_IDS_CSV') -COURSE_IDS: List[str] = [c.strip() for c in COURSE_IDS_CSV.split(',')] + if len(envErrors) > 0: + LOGGER.critical('The following environment variable(s) are not set: ' + f'{", ".join(envErrors)}') + sys.exit() + + if COURSE_IDS is None: + LOGGER.critical('COURSE_IDS could not be set. ' + '(Problem parsing COURSE_IDS_CSV?)') + sys.exit() + + +checkConfig() diff --git a/setup.cfg b/setup.cfg index 0d52425..397cdb1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [flake8] +# Vive la résistance! Vive la mixedCase! # N802 function name '…' should be lowercase # N803 argument name '…' should be lowercase # N806 variable '…' in function should be lowercase -# N816 variable '…' in global scope should not be mixedCase -extend-ignore = N802,N803,N806,N816 +extend-ignore = N802,N803,N806