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

Pull Request: TypeHinting and Readability #3

Merged
merged 9 commits into from
Apr 29, 2023
Merged

Pull Request: TypeHinting and Readability #3

merged 9 commits into from
Apr 29, 2023

Conversation

xaviernogueira
Copy link
Member

Hello xpublish-opendap devs / @abkfenris.

First off, great job making a very useful adaptor. I look forward to developing with it and sharing our work with the wider Xpublished community in the near future.

TLDR: I made no functional changes to the repo code at all! Behavior was not modified in any way. I hope you consider reviewing and pulling in these edits, as I'd argue they improve the readability and understandability of the code, which only encourages more use and contributions.

Readability edits:
As I began working with the repo, I noticed readability could be improved to match the standards set by the Google Python StyleGuide as well as PEP8 (i.e., column limits, #-out-able imports/function-arguments, relative "." imports, spacing between functions, etc.).

TypeHinting Edits:
TypeHinting was somewhat inconsistent (missing for a few functions) and personally I am a big fan of "idiot-proofing" repositories via very explicit TypeHinting (including in-line hinting for variables returned by functions).

An example of this to illustrate my thinking where I attempt to make clear the underlying type shared by all opendap_protocol datatypes:

# BEFORE
dtype_dap = {np.dtype(k): v for k, v in dtype_dap.items()}

# AFTER:
dtype_dap: Dict[np.dtype, dap.DAPAtom] = {
    np.dtype(k): v for k, v in dtype_dap.items()
}

All my edits are incredibly minor, but since I hope more people use this code going forward, adding that final but of polish seems worth it.

Thank you for your consideration!

@abkfenris
Copy link
Member

Hi @xaviernogueira, thanks for this work! Did you use any tools to help with type hinting or formatting? It would be nice to be able to add those to the pre-commit config so that others can build on your work, or at least not unintentionally revert it.

It looks like I left the tests and pre-commit config broken, so I just made a new PR to attempt to fix them #4, so you may want to merge or rebase onto it (once I have that not-broken).

@xaviernogueira
Copy link
Member Author

@abkfenris I just did the edits manually. That said, I have autopep8 format my code by default in my IDE which would be great for a pre-commit. That said, it doesn't do all that much, mostly clears out trailing spaces and extra empty lines.

How about you ping me when you fix the tests and I can merge to that?

@abkfenris
Copy link
Member

Ah ok. I've got Black running as part of the pre-commit hooks which covers formatting. Mypy and Ruff are also both part of the pre-commit hooks too to help with typing and linting, along with a handful of other checks.

I've landed my PR with updated tests and pre-commit config, so you can try merging that/main in.

@xaviernogueira
Copy link
Member Author

Okay I did it! Seems like everything is aligned. Now the tests need to run?

@abkfenris
Copy link
Member

I just triggered the tests.

Copy link
Member

@abkfenris abkfenris left a comment

Choose a reason for hiding this comment

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

It looks like that merge didn't quite do everything cleanly which is causing pytest to fail.

It also looks like your autopep8 config is conflicting with black's auto formatting, which is causing the pre-commit action to fail. Are you able to disable auto-format on save, and let pre-commit run before pushing? (you may need to manually run pre-commit run --all-files to bring things back into sync)?

xpublish_opendap/dap_xarray.py Outdated Show resolved Hide resolved
xpublish_opendap/dap_xarray.py Outdated Show resolved Hide resolved
xpublish_opendap/dap_xarray.py Show resolved Hide resolved
@xaviernogueira
Copy link
Member Author

xaviernogueira commented Apr 29, 2023

All tests passed (manually ran). Some reformatting was done automatically, and I turned off autopep8. The workflow should work now I believe.
image

@xaviernogueira
Copy link
Member Author

On a side note the documentation seems outdated (no "dap_router", and you would want to register OpenDapPlugin as a plugin not a router)? I can add to that later when I have a moment, but will keep that in a separate pull request.

@abkfenris
Copy link
Member

Docs are definitely out of date, so any help with them would be appreciated. They haven't been a big priority yet, as I haven't set up the library to be published to PyPi, and only having a git install helps folks understand 'here be dragons'.

I'm working on a big docs overhaul for Xpublish itself xpublish-community/xpublish#180 which is part of what I want to get done before cutting the first plugin release. Then I'd like to get -opendap and -edr to points that they can be released on PyPi & Conda-Forge too.

@abkfenris
Copy link
Member

Great, those passed. Thank you Xavier!

@abkfenris abkfenris merged commit dc36d15 into xpublish-community:main Apr 29, 2023
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