-
Notifications
You must be signed in to change notification settings - Fork 4k
GH-49102: [CI] Add type checking infrastructure and CI workflow for type annotations #48618
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
base: main
Are you sure you want to change the base?
Changes from all commits
9685f8e
4eff9c3
5569418
d551220
122b687
8d0d977
488c4e0
061b985
8fbb873
01428b5
e42b863
2d624b9
501df52
fc83193
9ad3060
d9973d1
095f479
4811159
3033231
b0c9626
42f8f97
716c642
9ed6a53
56c5262
1f50fa5
1c9c14e
da13f80
a43e884
a88b174
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ cython>=3.1 | |
| cloudpickle | ||
| fsspec | ||
| hypothesis | ||
| libcst>=1.8.6 | ||
| numpy>=1.16.6 | ||
| pytest | ||
| pytest-faulthandler | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| set -ex | ||
| pyarrow_dir=${1} | ||
|
|
||
| if [ -n "${ARROW_PYTHON_VENV:-}" ]; then | ||
| # shellcheck source=/dev/null | ||
| . "${ARROW_PYTHON_VENV}/bin/activate" | ||
| fi | ||
|
|
||
| # Install library stubs. Note some libraries contain their own type hints so they need to be installed. | ||
| pip install fsspec pandas-stubs scipy-stubs types-cffi types-psutil types-requests types-python-dateutil | ||
|
|
||
| # Install type checkers | ||
| pip install mypy pyright ty | ||
|
|
||
| # Run type checkers | ||
| pushd "${pyarrow_dir}" | ||
| mypy | ||
| pyright | ||
| ty check | ||
| popd |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,7 +38,7 @@ def validate_wheel(path): | |
| for info in f.filelist), \ | ||
| f"{filename} is missing from the wheel." | ||
| print(f"The wheel: {wheels[0]} seems valid.") | ||
|
|
||
| # TODO(GH-32609): Validate some docstrings were generated and added. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the type checking is split into several PRs, perhaps create sub-issues for clarify as well?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created two issues (for this PR and one following it) and linked them into the original issue #32609 |
||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
|
|
||
| """Type stubs for PyArrow. | ||
|
|
||
| This is a placeholder stub file. | ||
| Complete type annotations will be added in subsequent PRs. | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
| # TODO(GH-48970): remove __getattr__ before release as this | ||
| # will annotate non-existing attributes as Any. | ||
| # https://github.com/apache/arrow/issues/48970 | ||
| def __getattr__(name: str) -> Any: ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
| [build-system] | ||
| requires = [ | ||
| "cython >= 3.1", | ||
| # Needed for build-time stub docstring extraction | ||
| "libcst>=1.8.6", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At some point we'll want to deduplicate
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is probably best done in another PR? |
||
| "numpy>=1.25", | ||
| # configuring setuptools_scm in pyproject.toml requires | ||
| # versions released after 2022 | ||
|
|
@@ -88,11 +90,47 @@ include = ["pyarrow"] | |
| namespaces = false | ||
|
|
||
| [tool.setuptools.package-data] | ||
| pyarrow = ["*.pxd", "*.pyx", "includes/*.pxd"] | ||
| pyarrow = ["*.pxd", "*.pyi", "*.pyx", "includes/*.pxd", "py.typed"] | ||
|
|
||
| [tool.setuptools_scm] | ||
| root = '..' | ||
| version_file = 'pyarrow/_generated_version.py' | ||
| version_scheme = 'guess-next-dev' | ||
| git_describe_command = 'git describe --dirty --tags --long --match "apache-arrow-[0-9]*.*"' | ||
| fallback_version = '24.0.0a0' | ||
|
|
||
| # TODO: Enable type checking once stubs are merged | ||
| [tool.mypy] | ||
| files = ["pyarrow-stubs"] | ||
| mypy_path = "$MYPY_CONFIG_FILE_DIR/pyarrow-stubs" | ||
| exclude = [ | ||
| "^pyarrow/", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This exclusion means we're not checking anything currently, right?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, if we don't we get type check failurea (IIRC). |
||
| "^benchmarks/", | ||
| "^examples/", | ||
| "^scripts/", | ||
| ] | ||
|
|
||
| # TODO: Enable type checking once stubs are merged | ||
| [tool.pyright] | ||
| pythonPlatform = "All" | ||
| pythonVersion = "3.10" | ||
| include = ["pyarrow-stubs"] | ||
| exclude = [ | ||
| "pyarrow", | ||
| "benchmarks", | ||
| "examples", | ||
| "scripts", | ||
| "build", | ||
| ] | ||
| stubPath = "pyarrow-stubs" | ||
| typeCheckingMode = "basic" | ||
|
|
||
| # TODO: Enable type checking once stubs are merged | ||
| [tool.ty.src] | ||
| include = ["pyarrow-stubs"] | ||
| exclude = [ | ||
| "pyarrow", | ||
| "benchmarks", | ||
| "examples", | ||
| "scripts", | ||
| ] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| cython>=3.1 | ||
| libcst>=1.8.6 | ||
| numpy>=1.25 | ||
| setuptools_scm>=8 | ||
| setuptools>=77 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you enable lint for this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll give it a try! I'm afraid runtime annotations might not be seen at this point and in such case we can disable this in a later PR.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Do any of these scripts actually build pyarrow that we could test annotations against?