From 5dc2a33f4fffe6ce2e291857642556f24ae61357 Mon Sep 17 00:00:00 2001 From: WD Date: Tue, 15 Aug 2023 14:14:43 +0800 Subject: [PATCH] feat: migrate from `setup.py` to `pyproject.toml` (#45) * migrate to pyproject.toml * update README --- README.md | 36 ++++++++++++++++++++++--- django_tidb/functions.py | 2 +- pyproject.toml | 41 +++++++++++++++++++++++++++++ setup.cfg | 22 ---------------- setup.py | 57 ---------------------------------------- 5 files changed, 74 insertions(+), 84 deletions(-) create mode 100644 pyproject.toml delete mode 100644 setup.cfg delete mode 100644 setup.py diff --git a/README.md b/README.md index 05a3146..e05db6f 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,37 @@ This adds compatibility for [TiDB](https://github.com/pingcap/tidb) to Django. -## Install +## Installation Guide +### Prerequisites + +Before installing django-tidb, ensure you have a MySQL driver installed. You can choose either `mysqlclient`(recommended) or `pymysql`. + +#### Install mysqlclient (Recommended) + +Please refer to the [mysqlclient official guide](https://github.com/PyMySQL/mysqlclient#install) + +#### Install pymysql + +To install pymysql, use the following command: + +```bash +pip install pymysql +``` + +Then add the following code at the beginning of your Django's `manage.py`: + +```python +import pymysql + +pymysql.install_as_MySQLdb() ``` + +### Installing django-tidb + +Once you have a MySQL driver in place, proceed to install django-tidb: + +```bash pip install django-tidb ``` @@ -17,7 +45,7 @@ pip install django-tidb Set `'ENGINE': 'django_tidb'` in your settings to this: -``` +```python DATABASES = { 'default': { 'ENGINE': 'django_tidb', @@ -43,7 +71,7 @@ SECRET_KEY = 'django_tests_secret_key' create your virtualenv with: -``` +```bash $ virtualenv venv $ source venv/bin/activate ``` @@ -52,7 +80,7 @@ you can use the command ```deactivate``` to exit from the virtual environment. run all integration tests. -``` +```bash $ DJANGO_VERSION=3.2.12 python run_testing_worker.py ``` diff --git a/django_tidb/functions.py b/django_tidb/functions.py index 17b20c6..4a3acd8 100644 --- a/django_tidb/functions.py +++ b/django_tidb/functions.py @@ -23,7 +23,7 @@ def char(self, compiler, connection, **extra_context): connection, function="CHAR", template="%(function)s(%(expressions)s USING utf8mb4)", - **extra_context + **extra_context, ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ff85827 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,41 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "django-tidb" +authors = [ + { name="Xiang Zhang", email="zhangxiang02@pingcap.com" }, + { name="Di Wang", email="wangdi@pingcap.com" } +] +description = "Django backend for TiDB" +readme = "README.md" +requires-python = ">=3.6" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Framework :: Django", + "Framework :: Django :: 3.2", + "Framework :: Django :: 4.1", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11" +] +dynamic = ["version"] + +[project.urls] +"Homepage" = "https://github.com/pingcap/tidb" +"Bug Reports" = "https://github.com/pingcap/django-tidb/issues" +"Source" = "https://github.com/pingcap/django-tidb" + +[tool.setuptools] +packages = ["django_tidb"] + +[tool.setuptools.dynamic] +version = {attr = "django_tidb.__version__"} \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index c3ea696..0000000 --- a/setup.cfg +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2021 PingCAP, Inc. -# -# Licensed 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, -# See the License for the specific language governing permissions and -# limitations under the License. - -[flake8] -max-line-length = 119 - -[isort] -combine_as_imports = true -default_section = THIRDPARTY -include_trailing_comma = true -line_length = 79 -multi_line_output = 5 diff --git a/setup.py b/setup.py deleted file mode 100644 index 3b703be..0000000 --- a/setup.py +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright 2021 PingCAP, Inc. -# -# Licensed 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, -# See the License for the specific language governing permissions and -# limitations under the License. - -import re -import os - -from setuptools import find_packages, setup - -with open(os.path.join(os.path.dirname(__file__), "django_tidb", "__init__.py")) as v: - version = re.compile( - r'.*__version__ = "(.*?)"', - re.S).match( - v.read()).group(1) - -setup( - name='django-tidb', - version=version, - python_requires='>=3.6', - url='https://github.com/pingcap/django-tidb', - maintainer='Xiang Zhang', - maintainer_email='zhangxiang02@pingcap.com', - description='Django backend for TiDB', - long_description=open('README.md').read(), - long_description_content_type='text/markdown', - packages=find_packages(), - classifiers=[ - 'Development Status :: 5 - Production/Stable', - 'Framework :: Django', - 'Framework :: Django :: 3.2', - 'Framework :: Django :: 4.1', - 'License :: OSI Approved :: Apache Software License', - 'Operating System :: OS Independent', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: 3.11', - ], - install_requires=["mysqlclient"], - project_urls={ - 'Source': 'https://github.com/pingcap/django-tidb', - 'Tracker': 'https://github.com/pingcap/django-tidb/issues', - }, -)