Skip to content

Commit

Permalink
#10 - improve config and Python style
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lsloan committed Apr 24, 2023
1 parent 2a5913f commit 0b81702
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
35 changes: 23 additions & 12 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0b81702

Please sign in to comment.