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

1043 enforce default formatting #1060

Merged
merged 4 commits into from
Sep 13, 2024
Merged

Conversation

dbirman
Copy link
Member

@dbirman dbirman commented Sep 12, 2024

@saskiad requested that I get this working, and as long as I limit it to checking for default= and not required fields that are missing Field(...) it seems to work well.

This PR installs a [dev] package aind-flake8-extensions published on pypi as a flake8 extension. The extension generates warnings like these:

src/aind_data_schema/components/devices.py:530:5: PF001 Field 'coupling_efficiency' should use 'default=None' for optional fields
src/aind_data_schema/components/stimulus.py:42:5: PF001 Field 'pulse_train_interval' should use 'default=None' for optional fields
src/aind_data_schema/core/instrument.py:40:5: PF001 Field 'instrument_id' should use 'default=None' for optional fields
src/aind_data_schema/core/instrument.py:60:5: PF001 Field 'calibration_date' should use 'default=None' for optional fields
src/aind_data_schema/core/instrument.py:65:5: PF001 Field 'calibration_data' should use 'default=None' for optional fields
src/aind_data_schema/core/procedures.py:243:5: PF001 Field 'procedure_name' should use 'default=None' for optional fields
src/aind_data_schema/core/subject.py:100:5: PF001 Field 'genotype' should use 'default=None' for optional fields
src/aind_data_schema/core/subject.py:114:5: PF001 Field 'rrid' should use 'default=None' for optional fields
src/aind_data_schema/core/subject.py:119:5: PF001 Field 'restrictions' should use 'default=None' for optional fields

When it sees code like this (from devices.py:530):

    coupling_efficiency: Optional[Decimal] = Field(
        None,
        title="Coupling efficiency (percent)",
        ge=0,
        le=100,
    )

It also auto-highlights this issue in your editor as you code, if you have a flake8 extension in your IDE.

The extension doesn't fix the issue for you (I've gone through and fixed all of the above).

@dbirman dbirman linked an issue Sep 12, 2024 that may be closed by this pull request
Copy link
Collaborator

@bruno-f-cruz bruno-f-cruz left a comment

Choose a reason for hiding this comment

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

Great tool/idea! I don't have experience with these custom linters so I am not comfortable evaluating the PR.
I would just ask if running flake8 via CI/CD will raise an exception if any of these are missing, just to make sure we can use this to enforce the keyword on PRs. Otherwise lgtm thanks for the PR :)

@dbirman
Copy link
Member Author

dbirman commented Sep 13, 2024

Great tool/idea! I don't have experience with these custom linters so I am not comfortable evaluating the PR. I would just ask if running flake8 via CI/CD will raise an exception if any of these are missing, just to make sure we can use this to enforce the keyword on PRs. Otherwise lgtm thanks for the PR :)

It should raise an exception yes!

@dbirman dbirman added this pull request to the merge queue Sep 13, 2024
Merged via the queue into dev with commit ebd9319 Sep 13, 2024
5 checks passed
@dbirman dbirman deleted the 1043-enforce-default-formatting branch September 13, 2024 01:21
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.

Enforce default formatting
3 participants