-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor setup.py #115
Refactor setup.py #115
Conversation
Kudos, SonarCloud Quality Gate passed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR title is kinda misleading:
it does certainly contain refactorings (keeping the observable behavior of the software),
but also includes functional changes (league filtering) and loggin changes.
Also I thoroughly reviewed the diffs and commented things aspects to reconsider/improve.
Overall looks good to me though. Yet my top priority now would be to fix the association scraping (e.g. via #77)
try: | ||
if League.is_youth(abbreviation, name) and not options['youth']: | ||
logger.debug('SKIPPING League (youth league): %s %s %s', bhv_id, abbreviation, name) | ||
return | ||
except YouthUndecidableError: | ||
logger.info(3*'\t' + 'Youth undecidable for league: %s %s %s', bhv_id, abbreviation, name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which benefit do you see over the current exception handling?
With logger.exception(str)
the same log output would be produced, including the current exception message and stacktrace.
try: | ||
abbreviation = Association.get_association_abbreviation(name) | ||
except KeyError: | ||
LOGGER.warning("No abbreviation for association '%s'", name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with restructuring this exception handling to a None-check.
I think the warning should still be logged though.
|
||
# Filter and return all striped association URLs | ||
#return [item if item.startswith('http') else root_url + item for item in items] | ||
return [root_url + item.lstrip('/') for item in items if not item.startswith('https')] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this improve URL parsing?
can you add a test for this, which would fail without this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There have been some duplicate entries (abbreviations) in this list. I tried to filter out those before making the HTTP-Request.
'file': { | ||
'level': 'INFO', | ||
'class': 'logging.FileHandler', | ||
'filename': ROOT_DIR / 'hbscorez_INFO.log', | ||
'formatter': 'verbose', | ||
'encoding': 'UTF-8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have to check if the production settings extends or overwrite the logging configuration.
Also I'm not sure wether this should really be the default config, or if it's just personal preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea was to split the logging into different files, which retrospecively spoken, does not improve anything. However the encoding could be added due to some german "Umlaute" appearing in the association, district and / or team names. New PR is in the pipeline :)
@@ -5,10 +5,11 @@ | |||
/.vscode/ | |||
/htmlcov/ | |||
/logs | |||
/mails/ | |||
mails/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove the leading slash?
this would cause any directory named mails
in the whole project to be ignored.
including any module with that name. when actually we only need to ignore the root mail directory.
/media/ | ||
/reports/ | ||
/static/ | ||
venv/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be necessary when using pipenv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not know pipenv beforehand so to get the project up and running I just used the (for me well known) python module 'venv'.
@@ -17,4 +18,5 @@ db.sqlite3 | |||
docker-stack*.yml | |||
geckodriver.log | |||
hbscorez.log | |||
src/hbscorez/settings_docker_stack*.py | |||
hbscorez*.log | |||
src/hbscorez/settings_docker_stack*.py |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove the trailing space?
from teams.models import Team | ||
|
||
LOGGER = logging.getLogger('hbscorez') | ||
|
||
logger = logging.getLogger('hbscorez') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't lowercase this module level constant, see pylint-dev/pylint#2166
also if this was to be renamed, all the other logger variables in the project should also be renamed
'Inklusion', 'Special Olympics'] | ||
adult_match_strong = any(n in name for n in adult_name_indicators) | ||
'Inklusion', 'Special Olympics', | ||
'-F-', '-M-' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a test for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do in the new PR :)
'Inklusion', 'Special Olympics', | ||
'-F-', '-M-' | ||
] | ||
adult_match_strong = any(n in name for n in adult_name_indicators) and "M-Runde" not in name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change means: don't strongly match leagues as adult, whose name contains M-Runde
it (probably unnecessarily) adds a new condition branch - and thus complexity - complexity to this evaluation statement.
couldn't we instead just solve this by adding M-Runde
to youth_name_indicators_direct
?
also this should be backed by a test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be backed by a test - There was a corner case where M-Runde
appeared (at least with the old root URL) in the youth league and is also declared as adult league due to the M
in its name
.
Thanks you for the PR though! 😉 I really appreciate your work to improve the project, especially this biggest and most complex module. |
c49c030
to
013af77
Compare
Hi, yes, might be too much changes to be declared as a PR. |
Change Types
Description
Checklist