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

[Typing] Ensure packaging tensor.pyi into wheel #64575

Merged
merged 24 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
29e27dd
[Update] CMakeLists.txt for pack tensor.pyi
megemini May 24, 2024
53ac455
[Update] CMakeLists.txt
megemini May 24, 2024
4d2ab65
[Change] CMakeLists.txt depends
megemini May 24, 2024
18ca0ca
[Change] add CMakeLists.txt target
megemini May 24, 2024
a2bbbdd
[Update] CMakeLists.txt target dep
megemini May 24, 2024
badc1f9
[Update] CMakeLists.txt target dep
megemini May 24, 2024
9b7eb0b
[Change] framework.py paddle_version to paddle.version
megemini May 24, 2024
e26ff49
[Change] quantized_linear.py from paddle import version
megemini May 24, 2024
2293d02
[Change] check is_paddle_installed
megemini May 24, 2024
ebcc87b
[Change] CMakeLists deps
megemini May 25, 2024
84fd3cd
[Change] CMakeLists deps on infer
megemini May 25, 2024
4424f19
[Change] CMakeLists gen after wheel
megemini May 25, 2024
877d97e
[debug] core import
megemini May 25, 2024
1b79366
[debug] copy libs
megemini May 25, 2024
80afecc
[Change] add dll dirs in win
megemini May 25, 2024
921cb7b
[Update] gen_tensor_stub format
megemini May 27, 2024
53670fc
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
megemini May 27, 2024
abc48ff
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
megemini May 28, 2024
328a10b
[Change] gen tensor stub from setup
megemini May 28, 2024
dafb932
[Update] del comments
megemini May 28, 2024
4fbd7ea
[Update] setup.py.in add function check_build_dependency
megemini May 28, 2024
93f7350
[Update] gen_tensor_stub.py
megemini May 28, 2024
3580be7
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
megemini Jun 2, 2024
d77e427
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into…
megemini Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 50 additions & 10 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ if(WIN32)
${PADDLE_BINARY_DIR}/python/paddle/
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PADDLE_SOURCE_DIR}/test
${PADDLE_BINARY_DIR}/test
# generate tensor.pyi for type hints
COMMAND
${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
${PYTHON_EXECUTABLE} ${PADDLE_SOURCE_DIR}/tools/gen_tensor_stub.py
--input-file
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.prototype.pyi
--output-file ${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
# copy tensor.pyi to source dir
COMMAND
${CMAKE_COMMAND} -E copy
${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.pyi
Copy link
Member

@SigureMo SigureMo May 24, 2024

Choose a reason for hiding this comment

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

话说这几部分有可以复用的么?是否可以写成函数?

COMMENT "Packing whl packages------>>>"
DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
pass_desc_py_proto ${PY_FILES})
Expand All @@ -131,6 +143,18 @@ if(WIN32)

add_custom_command(
OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp_wheel
# generate tensor.pyi for type hints
COMMAND
${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
${PYTHON_EXECUTABLE} ${PADDLE_SOURCE_DIR}/tools/gen_tensor_stub.py
--input-file
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.prototype.pyi
--output-file ${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
# copy tensor.pyi to source dir
COMMAND
${CMAKE_COMMAND} -E copy
${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.pyi
COMMAND ${CMAKE_COMMAND} -E env ${py_env} ${PYTHON_EXECUTABLE} setup.py
bdist_wheel
COMMENT "Packing whl packages------>>>"
Expand All @@ -144,6 +168,18 @@ else()
COMMAND cp -r ${PADDLE_SOURCE_DIR}/python/paddle
${PADDLE_BINARY_DIR}/python
COMMAND cp -r ${PADDLE_SOURCE_DIR}/test ${PADDLE_BINARY_DIR}/
# generate tensor.pyi for type hints
COMMAND
${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
${PYTHON_EXECUTABLE} ${PADDLE_SOURCE_DIR}/tools/gen_tensor_stub.py
--input-file
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.prototype.pyi
--output-file ${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
# copy tensor.pyi to source dir
COMMAND
${CMAKE_COMMAND} -E copy
${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.pyi
COMMENT "Packing whl packages------>>>"
DEPENDS copy_libpaddle ${FLUID_CORE} framework_py_proto profiler_py_proto
pass_desc_py_proto ${PY_FILES})
Expand All @@ -159,6 +195,18 @@ else()

add_custom_command(
OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp_wheel
# generate tensor.pyi for type hints
COMMAND
${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
${PYTHON_EXECUTABLE} ${PADDLE_SOURCE_DIR}/tools/gen_tensor_stub.py
--input-file
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.prototype.pyi
--output-file ${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
# copy tensor.pyi to source dir
COMMAND
${CMAKE_COMMAND} -E copy
${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.pyi
COMMAND env ${py_env} ${PYTHON_EXECUTABLE} setup.py bdist_wheel
COMMENT "Packing whl packages------>>>")
endif()
Expand All @@ -167,16 +215,8 @@ endif()
add_custom_target(paddle_python ALL
DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp)
if(BUILD_WHL_PACKAGE AND NOT WITH_SETUP_INSTALL)
add_custom_target(
paddle_copy ALL
# generate tensor.pyi for type hints
COMMAND
${CMAKE_COMMAND} -E env PYTHONPATH=${PADDLE_BINARY_DIR}/python
${PYTHON_EXECUTABLE} ${PADDLE_SOURCE_DIR}/tools/gen_tensor_stub.py
--input-file
${PADDLE_SOURCE_DIR}/python/paddle/tensor/tensor.prototype.pyi
--output-file ${PADDLE_BINARY_DIR}/python/paddle/tensor/tensor.pyi
DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp_wheel)
add_custom_target(paddle_copy ALL
DEPENDS ${PADDLE_PYTHON_BUILD_DIR}/.timestamp_wheel)
add_dependencies(paddle_copy paddle_python)
endif()

Expand Down
4 changes: 2 additions & 2 deletions python/paddle/tensor/tensor.prototype.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# The `Tensor` template for `tools/gen_tensor_stub.py` generates the stub file `tensor.pyi`.
# Add docstring, attributes, methods and alias with type annotaions for `Tensor`
# The `Tensor` template `tensor.prototype.pyi` for `tools/gen_tensor_stub.py` to generate the stub file `tensor.pyi`.
# Add docstring, attributes, methods and alias with type annotaions for `Tensor` in `tensor.prototype.pyi`
# if not conveniently coding in original place (like c++ source file).

from typing import Any, overload
Expand Down
5 changes: 4 additions & 1 deletion tools/gen_tensor_stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ def add_doc(self, doc: str):
self.insert_template(docstring, _end_index, _end_index)

def codegen(self) -> str:
return self._template
header = (
'# This file is auto generated by `tools/gen_tensor_stub.py`.\n\n'
)
return header + self._template


def is_inherited_member(name: str, cls: type) -> bool:
Expand Down