Skip to content
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

API server code health improvements #1041

Merged
merged 6 commits into from
Dec 2, 2022
Merged

API server code health improvements #1041

merged 6 commits into from
Dec 2, 2022

Conversation

rzats
Copy link
Contributor

@rzats rzats commented Dec 2, 2022

Addresses #998.

Prerequisites:

  • Unless it is a documentation hotfix it should be merged against the dev branch
  • Branch is up-to-date with the branch to be merged with, i.e. dev
  • Build is successful
  • Code is cleaned up and formatted

Summary

General linting pass for the API & acquisition code: removes unused imports, fixes some whitespace issues, fixing exception try/except blocks etc

@rzats rzats requested a review from melange396 December 2, 2022 13:15
Copy link
Collaborator

@melange396 melange396 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof, some of the code here was really gnarly (especially the first file, src/acquisition/afhsb/afhsb_csv.py)! i looooove seeing all the unused imports and variables getting removed! the whitespace fixes also soothe my ocd. this is fabulous!!!

what programs/packages/commands/parameters did you use to do this? its probably something that should be incorporated into #962...

you should change "Closes #998" to "Addresses #998" and we can get this PR merged by itself. itll be good to separate this set of problematic code changes that a linter found automatically (syntactic points) from the other semantic or logical changes that youll make later in further pursuit of issue #998.

Comment on lines 45 to 48
def handle_failed(_, filename, source, logger):
logger.info(event='leaving failed file alone', dest=source, file=filename)

def handle_successful(path_src, filename, source, logger):
def handle_successful(path_src, filename, _, logger):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we should leave these as-is because they are intended to have the same function signature.

Comment on lines -207 to -211
region = NIDSS.LOCATION_TO_REGION[location]
imported_b64 = base64.b64encode(fields[6].encode('utf-8'))
imported = imported_b64 == b'5piv'
sex = fields[5]
age = fields[7]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just comment out the region, sex, and age lines and note that theyre currently unused? leaving them in could help someone debug later (at least in terms of parsing the input file), and they might even be data points we will add in the future...

src/server/endpoints/covidcast_utils/model.py Outdated Show resolved Hide resolved
rzats and others added 2 commits December 2, 2022 16:41
Co-authored-by: melange396 <george.haff@gmail.com>
Copy link
Collaborator

@melange396 melange396 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great to me!

@rzats
Copy link
Contributor Author

rzats commented Dec 2, 2022

@melange396 I applied the changes you've requested!

what programs/packages/commands/parameters did you use to do this? its probably something that should be incorporated into #962...

This PR fixes issues detected by Prospector, which uses pylint internally.

There are tools that can autoformat Python repos, which we can use now that we have a working editable package. black is one that comes to mind: it can be incorporated as a CI step (yells at you if your code isn't formatted), post-commit hook (formats your code automatically), etc.

Caveat: these tools are non-configurable and "uncompromising" by design, so on an initial run, they will reformat the majority of the codebase to the indentation style they like, affecting most lines of code. This will

so we need to think carefully about when to apply them.

@rzats rzats changed the title [WIP] API server code health improvements API server code health improvements Dec 2, 2022
@rzats rzats merged commit 3d37c59 into dev Dec 2, 2022
@rzats rzats deleted the rzatserkovnyi/code-health branch December 2, 2022 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants