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

【OCR Issue No.12】Modify the setuptools configuration from SETUP.py into PYPROJECT.toml #12013

Merged
merged 21 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
pip install setuptools
pip install wheel
- name: Build package
run: python setup.py bdist_wheel
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
Expand Down
1 change: 1 addition & 0 deletions VERSION_NUMBER
Copy link
Collaborator

Choose a reason for hiding this comment

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

加了这个文件的话,就得对 paddleocr.py 进行改造了。
可以试试,在 pyproject.toml 中用 setuptools_scm 自动生成一个 version.py , 然后让 paddleocr.py 从这里获取版本号。 可以参考一下 paddle2onnx 里的做法。

Copy link
Collaborator

Choose a reason for hiding this comment

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

.github/workflows/python-publish.yml
这个也要改

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

如果希望setuptools_scm 生成version,则需要在ppocr/init.py中import这个version.py,打包就会采用默认生成的编号了。这样做将会彻底撇开VERSION_NUMBER。
按照pp2onnx的写法,最终应该还是在读VERSION_NUMBER的版本号。

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.8.0
3 changes: 2 additions & 1 deletion paddleocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from io import BytesIO
from PIL import Image
from tools.infer import predict_system
from ppocr import __version__
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved


def _import_file(module_name, file_path, make_importable=False):
Expand Down Expand Up @@ -78,7 +79,7 @@ def _import_file(module_name, file_path, make_importable=False):
]

SUPPORT_DET_MODEL = ["DB"]
VERSION = "2.8.0"
VERSION = __version__
Copy link
Collaborator

Choose a reason for hiding this comment

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

这行我觉得不需要了。
只是会 break 原来有极少的人用 paddleocr.VERSION 的用法。

Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
SUPPORT_REC_MODEL = ["CRNN", "SVTR_LCNet"]
BASE_DIR = os.path.expanduser("~/.paddleocr/")

Expand Down
6 changes: 6 additions & 0 deletions ppocr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
# 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.
import importlib.metadata as importlib_metadata
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个文件,我觉得不需要改动。
可以在 pyproject.toml 里配置 setuptools_scm 自动生成实现类似功能的代码。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

如果这个文件不需要改动,其实也不需要使用setuptools_scm

Copy link
Collaborator

Choose a reason for hiding this comment

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

我意思是不要自己实现这个功能,而是用 setuptools_scm 这样的标准化工具来实现。


try:
__version__ = importlib_metadata.version(__package__ or __name__)
except importlib_metadata.PackageNotFoundError:
__version__ = "0.0.0"
71 changes: 71 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[build-system]
requires = ["setuptools", "setuptools-scm", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "paddleocr"
# After each version release, the version number needs to be incremented
dynamic = ["version"]
description = "Awesome OCR toolkits based on PaddlePaddle(8.6M ultra-lightweight pre-trained model, support training and deployment among server, mobile, embedded and IoT devices)"
authors = [
{name = "PaddlePaddle", email = "Paddle-better@baidu.com"},
]
maintainers = [
{name = "PaddlePaddle", email = "Paddle-better@baidu.com"},
]
readme = "README.md"
requires-python = ">=3.8"
keywords = [
"ocr",
"textdetection",
"textrecognition",
"paddleocr",
"crnn",
"east",
"star-net",
"rosetta",
"ocrlite",
"db",
"chineseocr",
"chinesetextdetection",
"chinesetextrecognition",
]
license = {text = "Apache License 2.0"}
classifiers = [
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Natural Language :: Chinese (Simplified)",
"Programming Language :: Python :: 3",
"Topic :: Utilities",
]
dependencies = [
"shapely",
"scikit-image",
"imgaug",
"pyclipper",
"lmdb",
"tqdm",
"numpy",
"rapidfuzz",
"opencv-python<=4.6.0.66",
"opencv-contrib-python<=4.6.0.66",
"cython",
"Pillow>=10.0.0",
"pyyaml",
"python-docx",
"beautifulsoup4",
"fonttools>=4.24.0",
"fire>=0.3.0",
]

[project.scripts]
paddleocr = "paddleocr.paddleocr:main"

[tool.setuptools]
packages = ["paddleocr"]
package-dir = { "paddleocr" = "" }
include-package-data = true

[tool.setuptools.dynamic]
version = {file = "VERSION_NUMBER"}

Copy link
Collaborator

Choose a reason for hiding this comment

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

在这里添加类似

[tool.setuptools_scm]
version_file = "pkg/_version.py"

的配置。

详情: https://github.com/pypa/setuptools_scm

64 changes: 1 addition & 63 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,68 +13,6 @@
# limitations under the License.

from setuptools import setup
from io import open
import subprocess

# get version by matchiing, so will not need to setup complex env in github aciton
p = subprocess.Popen(
"grep ^VERSION ./paddleocr.py | awk '{print $3}' | tr -d '\"'",
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True,
)
raw_VERSION, _ = p.communicate()
VERSION = raw_VERSION.decode().strip()


def load_requirements(file_list=None):
if file_list is None:
file_list = ["requirements.txt"]
if isinstance(file_list, str):
file_list = [file_list]
requirements = []
for file in file_list:
with open(file, encoding="utf-8-sig") as f:
requirements.extend(f.readlines())
return requirements


def readme():
with open("doc/doc_en/whl_en.md", encoding="utf-8-sig") as f:
README = f.read()
return README


setup(
name="paddleocr",
packages=["paddleocr"],
package_dir={"paddleocr": ""},
include_package_data=True,
entry_points={"console_scripts": ["paddleocr= paddleocr.paddleocr:main"]},
version=VERSION,
install_requires=load_requirements(
["requirements.txt", "ppstructure/recovery/requirements.txt"]
),
license="Apache License 2.0",
description="Awesome OCR toolkits based on PaddlePaddle(8.6M ultra-lightweight pre-trained model, support training and deployment among server, mobile, embedded and IoT devices)",
long_description=readme(),
long_description_content_type="text/markdown",
url="https://github.com/PaddlePaddle/PaddleOCR",
download_url="https://github.com/PaddlePaddle/PaddleOCR.git",
keywords=[
"ocr textdetection textrecognition paddleocr crnn east star-net rosetta ocrlite db chineseocr chinesetextdetection chinesetextrecognition"
],
classifiers=[
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Natural Language :: Chinese (Simplified)",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Topic :: Utilities",
],
)
setup()
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个文件应该不需要了吧

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个可以留着,用来兼容以前的在命令行下运行 python setup.py 的使用习惯。

Loading