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

Python API typing, lint, config/makefile #3023

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

alexander-beedie
Copy link
Contributor

@alexander-beedie alexander-beedie commented Mar 11, 2024

I realise this is a relatively enormous-looking PR; however, I promise it is a LOT less involved than it may initially look! 🤣 (And there are zero logical/functional changes).

Summary

I made a few smaller PRs to add Polars support to Kùzu recently, and working with (and testing) the Python module had a little friction, so I thought I'd reduce it.

Specifically:

  • The PythonAPI surface is now fully typed1 (function signatures, return types, etc). This should lead to an improved developer experience in real-world usage (IDE autocomplete & hinting, integration with other projects that already implement static type checking, etc).
  • The entire Python API now passes both ruff check2 and mypy3 linting rules.
  • Consistent formatting was applied, via ruff format4 (this is likely worth integrating into CI and/or pre-commit, but I haven't done that). The existing formatting actually changed very little, so this change mostly just ensures consistent string quoting and max line-length. I set line-length at a level that would result in minimal change.
  • Switched out all usage of os.path for pathlib.Path.
  • Created a Makefile in tools/python_api that can:
    • Setup a clean Python .venv for testing/validating changes.
    • Download/resolve requirements for that venv (using uv)5.
    • Trigger a make python build from the existing root Makefile.
    • Run the Python unit tests.
    • Output its own "help".

Being able to quickly get up and running in a virtual environment and trigger builds/tests is now a lot smoother, and all the configuration for mypy & ruff is centralised in the new/added pyproject.toml file (which is based on what we use for Polars, with Kùzu-specific customisation).

Examples

  • Find out what the Makefile can do:

    "make help"

  • Install/update the venv requirements:

    "make requirements"

  • Check lint and apply formatting:

    "make lint"

  • Run unit tests:

    "make test"

...and so on 👌

CLA

(In case this is a "per-PR" requirement?)
I have read and agree to the terms under CLA.md

Footnotes

  1. https://peps.python.org/pep-0484/

  2. https://astral.sh/ruff

  3. https://mypy-lang.org/

  4. https://docs.astral.sh/ruff/formatter/

  5. https://astral.sh/blog/uv

@ray6080 ray6080 requested a review from mewim March 11, 2024 12:46
@alexander-beedie
Copy link
Contributor Author

FYI: I've also seen how to enormously speed up the Python unit tests, but I'll leave that for a follow up PR. Didn't want to mix functional changes with lint/formatting/config...

@mewim
Copy link
Collaborator

mewim commented Mar 12, 2024

@alexander-beedie
Nice PR. Thanks for your contribution.

@mewim mewim merged commit 3bdc752 into kuzudb:master Mar 12, 2024
7 of 14 checks passed
@alexander-beedie alexander-beedie deleted the python-typing-lint-config branch March 12, 2024 09:36
@andyfengHKU andyfengHKU mentioned this pull request Apr 15, 2024
32 tasks
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.

None yet

2 participants