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

Adds black and pre-commit hooks #239

Merged
merged 35 commits into from Aug 20, 2021
Merged

Adds black and pre-commit hooks #239

merged 35 commits into from Aug 20, 2021

Conversation

sverhoeven
Copy link
Member

@sverhoeven sverhoeven commented Aug 10, 2021

Also formats files to be compliant.

Fixes #111
Fixes #241

Tried to add flake8, but it complains a lot and all complaints have to manually fixed.

Do we want to be flake8 compliant and drop prospector? Yep we do warnings first and once fixed fatal errors.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@sverhoeven sverhoeven marked this pull request as ready for review August 11, 2021 07:47
@Peter9192
Copy link
Collaborator

Can you try to set the max line length for flake8 to 88 (black's default)? I should have some time to fix the remaining line length issues if that's ok with you

@sverhoeven
Copy link
Member Author

Max length is now 88 and some checks are ignored.
From the 400+ warnings only 81 are line too long errors.

Sure you can help to fix any of them

I configured pre-commit to print the flake8 warnings, but treat is as passed.
So we can slowly fix all warnings and once done we can enforce it.

Copy link
Collaborator

@Peter9192 Peter9192 left a comment

Choose a reason for hiding this comment

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

Very nice @sverhoeven , I think this really helps to improve the package! I fixed all line lengths issues except for in the notebooks. I did have a few minor comments, could you look at those please?

additional_dependencies: [isort==5.9.3]
- id: nbqa-mypy
additional_dependencies: [mypy==0.910]
# TODO renable when erros are fixed/ignored
Copy link
Collaborator

Choose a reason for hiding this comment

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

old?

Copy link
Member Author

Choose a reason for hiding this comment

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

nope, https://pypi.org/project/isort/5.9.3/ and https://pypi.org/project/mypy/0.910/ are latest versions on PyPI

Versions are there to make sure the .py and .ipynb are using same versions of linters/formatters.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant the #TODO which was above a block that was not disabled, but I guess we'll get to it once we addressed the remaining issues.

# rev: "v2.9.6"
# hooks:
# - id: pylint
# TODO renable when erros are fixed/ignored
Copy link
Collaborator

Choose a reason for hiding this comment

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

old?

Copy link
Member Author

Choose a reason for hiding this comment

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

Same isort,mypi or do you mean something else then version?

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this file supposed to be formatted?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is a text file according to http://wiki.gis.com/wiki/index.php/Shapefile#Shapefile_projection_format_.28.prj.29

and can still read it with

In [1]: from cartopy.io import shapereader

In [2]: shape = shapereader.Reader('docs/examples/data/Rhine')

In [5]: list(shape.records())
Out[5]: [<Record: <shapely.geometry.polygon.Polygon object at 0x7fdfa3388a60>, {'HYBAS_ID': 2040023010, 'NEXT_DOWN': 0, 'NEXT_SINK': 2040023010, 'MAIN_BAS': 2040023010, 'DIST_SINK': 0.0, 'DIST_MAIN': 0.0, 'SUB_AREA': 163122.5, 'UP_AREA': 163122.5, 'PFAF_ID': 2326, 'SIDE': 'M', 'LAKE': 0, 'ENDO': 0, 'COAST': 0, 'ORDER': 1, 'SORT': 64, '_Slope_mea': 2.675870994597621, '_Slope_med': 1.3819899559021, '_Slope_std': 3.960913895155292, '_Slope_min': 0.0, '_Slope_max': 42.11079788208008, '_Slope_ran': 42.11079788208008, '_Slope_var': 0, '_Slope_v_1': 15.688838884834267, '_Urban_cou': 2617913.0, '_Urban_sum': 220178.0, '_Urban_mea': 0.084104399191264, '_Altitudem': -185.0, '_Altitud_1': 3944.0, '_Altituder': 4129.0, 'Urban_Perc': 8.41, '_variety': 0}, <fields>>]

for _ in (
"1.5, 2.5",
[1.5, 2.5],
[1.5, 2.5],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same test twice?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like it, can we fix that in a separate issue?

.pre-commit-config.yaml Outdated Show resolved Hide resolved
setup.cfg Show resolved Hide resolved
- id: nbqa-mypy
additional_dependencies: [mypy==0.910]
# TODO renable when erros are fixed/ignored
- id: nbqa-flake8
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could it be that the notebooks (in docs) are not picked up by these checks?

This check passes on pre-commit run --all-files for me, but if I do pip install nbqa and then nbqa flake8 docs/*.ipynb I get a list of issues.

Choose a reason for hiding this comment

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

I think the issue is

        args: *fa

, I'm not sure what it's meant to do here, but if you remove it then pre-commit run nbqa-flake8 --all-files will fail too

Copy link
Member Author

Choose a reason for hiding this comment

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

The flake8 hook is verbose by default while nbqa-flake8 was not, I forced it to be verbose so now warnings show up.

The *fa is a YAML alias of YAML anchor defined in flake8 hook with @fa so I do not have to repeat the list of flake8 plugins.

Choose a reason for hiding this comment

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

I didn't know you could do that, thanks! This'll be useful in other projects

@sonarcloud
Copy link

sonarcloud bot commented Aug 17, 2021

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 9 Code Smells

71.5% 71.5% Coverage
1.1% 1.1% Duplication

@sverhoeven sverhoeven merged commit c794ef7 into main Aug 20, 2021
@sverhoeven
Copy link
Member Author

Thanks for reviewing

@sverhoeven sverhoeven deleted the 111-black branch August 20, 2021 07:07
@MarcoGorelli
Copy link

Just FYI, black now has a Jupyter hook, I'd advise using that instead of nbqa-black

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.

nrMeasurements in grdc metadata is always NA Consistent formatting
3 participants