Skip to content

Commit 7032983

Browse files
authored
Update PyPi info (#279)
* Update PyPi info * Add project name * Add version in pyproject.toml * Auto gen the project part * Remove project.urls
1 parent 0d0b646 commit 7032983

File tree

3 files changed

+125
-58
lines changed

3 files changed

+125
-58
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@ build-frontend = "pip"
88
[tool.pyright]
99
include = ["chdb"]
1010
exclude = ["src", "contrib", "programs", "build", "buildlib", "dist", "venv", ".venv", ".vscode", ".git", "__pycache__", ".mypy_cache", ".pytest_cache"]
11-

setup.cfg

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ long_description_content_type = text/markdown; charset=UTF-8; variant=GFM
1515
url = https://github.com/chdb-io/chdb
1616
# Add here related links, for example:
1717
project_urls =
18-
Documentation = https://doc.chdb.io/
19-
# Source = https://github.com/pyscaffold/pyscaffold/
20-
# Changelog = https://pyscaffold.org/en/latest/changelog.html
21-
# Tracker = https://github.com/pyscaffold/pyscaffold/issues
22-
# Conda-Forge = https://anaconda.org/conda-forge/pyscaffold
23-
# Download = https://pypi.org/project/PyScaffold/#files
18+
Homepage = https://clickhouse.com/chdb
19+
Documentation = https://clickhouse.com/docs/en/chdb
20+
Source = https://github.com/chdb-io/chdb
21+
Download = https://pypi.org/project/chdb/#files
2422
Twitter = https://twitter.com/chdb_io
2523

2624
# Change if running only on Windows, Mac or Linux (comma-separated)
@@ -38,6 +36,7 @@ classifiers =
3836
Programming Language :: Python :: 3.9
3937
Programming Language :: Python :: 3.10
4038
Programming Language :: Python :: 3.11
39+
Programming Language :: Python :: 3.12
4140
Topic :: Database
4241
Topic :: Scientific/Engineering :: Information Analysis
4342

setup.py

Lines changed: 120 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010

1111
log.set_verbosity(log.DEBUG)
1212

13+
1314
def get_python_ext_suffix():
14-
internal_ext_suffix = sysconfig.get_config_var('EXT_SUFFIX')
15-
p = subprocess.run(['python3', '-c', "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))"], capture_output=True, text=True)
15+
internal_ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
16+
p = subprocess.run(
17+
[
18+
"python3",
19+
"-c",
20+
"import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))",
21+
],
22+
capture_output=True,
23+
text=True,
24+
)
1625
if p.returncode != 0:
1726
print("Failed to get EXT_SUFFIX via python3")
1827
return internal_ext_suffix
@@ -23,38 +32,56 @@ def get_python_ext_suffix():
2332
print("Python3 EXT_SUFFIX: " + py_ext_suffix)
2433
print("Current Python Path: " + sys.executable)
2534
print("Current Python Version: " + sys.version)
26-
print("Outside Python Path: " + subprocess.check_output(['which', 'python3']).decode('utf-8').strip())
27-
print("Outside Python Version: " + subprocess.check_output(['python3', '--version']).decode('utf-8').strip())
35+
print(
36+
"Outside Python Path: "
37+
+ subprocess.check_output(["which", "python3"]).decode("utf-8").strip()
38+
)
39+
print(
40+
"Outside Python Version: "
41+
+ subprocess.check_output(["python3", "--version"]).decode("utf-8").strip()
42+
)
2843
return py_ext_suffix
2944

45+
3046
# get the path of the current file
3147
script_dir = os.path.dirname(os.path.abspath(__file__))
3248
libdir = os.path.join(script_dir, "chdb")
3349

50+
3451
def get_latest_git_tag(minor_ver_auto=False):
3552
try:
3653
# get latest tag commit
37-
completed_process = subprocess.run(['git', 'rev-list', '--tags', '--max-count=1'], capture_output=True, text=True)
54+
completed_process = subprocess.run(
55+
["git", "rev-list", "--tags", "--max-count=1"],
56+
capture_output=True,
57+
text=True,
58+
)
3859
if completed_process.returncode != 0:
3960
print(completed_process.stdout)
4061
print(completed_process.stderr)
4162
# get git version
4263
raise RuntimeError("Failed to get git latest tag commit ")
4364
output = completed_process.stdout.strip()
4465
# get latest tag name by commit
45-
completed_process = subprocess.run(['git', 'describe', '--tags', f"{output}"], capture_output=True, text=True)
66+
completed_process = subprocess.run(
67+
["git", "describe", "--tags", f"{output}"], capture_output=True, text=True
68+
)
4669
if completed_process.returncode != 0:
4770
print(completed_process.stdout)
4871
print(completed_process.stderr)
4972
# get git version
5073
raise RuntimeError("Failed to get git tag")
5174
output = completed_process.stdout.strip()
52-
#strip the v from the tag
75+
# strip the v from the tag
5376
output = output[1:]
54-
parts = output.split('.')
77+
parts = output.split(".")
5578
if len(parts) == 3:
5679
if minor_ver_auto:
57-
completed_process = subprocess.run(['git', 'rev-list', '--count', f"v{output}..HEAD"], capture_output=True, text=True)
80+
completed_process = subprocess.run(
81+
["git", "rev-list", "--count", f"v{output}..HEAD"],
82+
capture_output=True,
83+
text=True,
84+
)
5885
if completed_process.returncode != 0:
5986
print(completed_process.stdout)
6087
print(completed_process.stderr)
@@ -67,31 +94,50 @@ def get_latest_git_tag(minor_ver_auto=False):
6794
print(e)
6895
raise
6996

97+
7098
# replace the version in chdb/__init__.py, which is `chdb_version = ('0', '1', '0')` by default
7199
# regex replace the version string `chdb_version = ('0', '1', '0')` with version parts
72100
def fix_version_init(version):
73101
# split version string into parts
74-
p1, p2, p3 = version.split('.')
102+
p1, p2, p3 = version.split(".")
75103
init_file = os.path.join(script_dir, "chdb", "__init__.py")
76104
with open(init_file, "r+") as f:
77105
init_content = f.read()
78106
# regex replace the version string `chdb_version = ('0', '1', '0')`
79107
regPattern = r"chdb_version = \(\'\d+\', \'\d+\', \'\d+\'\)"
80-
init_content = re.sub(regPattern, f"chdb_version = ('{p1}', '{p2}', '{p3}')", init_content)
108+
init_content = re.sub(
109+
regPattern, f"chdb_version = ('{p1}', '{p2}', '{p3}')", init_content
110+
)
81111
f.seek(0)
82112
f.write(init_content)
83113
f.truncate()
84114

85115

116+
# Update version in pyproject.toml
117+
def update_pyproject_version(version):
118+
pyproject_file = os.path.join(script_dir, "pyproject.toml")
119+
with open(pyproject_file, "r") as f:
120+
content = f.read()
121+
122+
# Use regex to replace the version
123+
updated_content = re.sub(
124+
r'version\s*=\s*"[^"]*"', f'version = "{version}"', content
125+
)
126+
127+
with open(pyproject_file, "w") as f:
128+
f.write(updated_content)
129+
130+
86131
# As of Python 3.6, CCompiler has a `has_flag` method.
87132
# cf http://bugs.python.org/issue26689
88133
def has_flag(compiler, flagname):
89134
"""Return a boolean indicating whether a flag name is supported on
90135
the specified compiler.
91136
"""
92137
import tempfile
93-
with tempfile.NamedTemporaryFile('w', suffix='.cpp') as f:
94-
f.write('int main (int argc, char **argv) { return 0; }')
138+
139+
with tempfile.NamedTemporaryFile("w", suffix=".cpp") as f:
140+
f.write("int main (int argc, char **argv) { return 0; }")
95141
try:
96142
compiler.compile([f.name], extra_postargs=[flagname])
97143
except setuptools.distutils.errors.CompileError:
@@ -103,55 +149,74 @@ def cpp_flag(compiler):
103149
"""Return the -std=c++[11/2a] compiler flag.
104150
The c++2a is prefered over c++11 (when it is available).
105151
"""
106-
if has_flag(compiler, '-std=c++2a'):
107-
return '-std=c++2a'
108-
elif has_flag(compiler, '-std=c++17'):
109-
return '-std=c++17'
110-
elif has_flag(compiler, '-std=c++14'):
111-
return '-std=c++14'
112-
elif has_flag(compiler, '-std=c++11'):
113-
return '-std=c++11'
152+
if has_flag(compiler, "-std=c++2a"):
153+
return "-std=c++2a"
154+
elif has_flag(compiler, "-std=c++17"):
155+
return "-std=c++17"
156+
elif has_flag(compiler, "-std=c++14"):
157+
return "-std=c++14"
158+
elif has_flag(compiler, "-std=c++11"):
159+
return "-std=c++11"
114160
else:
115-
raise RuntimeError('Unsupported compiler -- at least C++11 support '
116-
'is needed!')
161+
raise RuntimeError(
162+
"Unsupported compiler -- at least C++11 support " "is needed!"
163+
)
117164

118165

119166
class BuildExt(build_ext):
120167
"""A custom build extension for adding compiler-specific options."""
121168

122169
def build_extensions(self):
123170
# Determine which compiler to use, if CC and CXX env exist, use them
124-
if os.environ.get('CC') is not None and os.environ.get('CXX') is not None:
171+
if os.environ.get("CC") is not None and os.environ.get("CXX") is not None:
125172
print("Using CC and CXX from env")
126-
print("CC: " + os.environ.get('CC'))
127-
print("CXX: " + os.environ.get('CXX'))
128-
if sys.platform == 'darwin':
173+
print("CC: " + os.environ.get("CC"))
174+
print("CXX: " + os.environ.get("CXX"))
175+
if sys.platform == "darwin":
129176
try:
130-
brew_prefix = subprocess.check_output('brew --prefix', shell=True).decode("utf-8").strip("\n")
177+
brew_prefix = (
178+
subprocess.check_output("brew --prefix", shell=True)
179+
.decode("utf-8")
180+
.strip("\n")
181+
)
131182
except Exception:
132183
raise RuntimeError("Must install brew")
133-
if os.system('which '+brew_prefix+'/opt/llvm/bin/clang++ > /dev/null') == 0:
134-
os.environ['CC'] = brew_prefix + '/opt/llvm/bin/clang'
135-
os.environ['CXX'] = brew_prefix + '/opt/llvm/bin/clang++'
136-
elif os.system('which '+brew_prefix+'/opt/llvm@15/bin/clang++ > /dev/null') == 0:
137-
os.environ['CC'] = brew_prefix + '/opt/llvm@15/bin/clang'
138-
os.environ['CXX'] = brew_prefix + '/opt/llvm@15/bin/clang++'
184+
if (
185+
os.system("which " + brew_prefix + "/opt/llvm/bin/clang++ > /dev/null")
186+
== 0
187+
):
188+
os.environ["CC"] = brew_prefix + "/opt/llvm/bin/clang"
189+
os.environ["CXX"] = brew_prefix + "/opt/llvm/bin/clang++"
190+
elif (
191+
os.system(
192+
"which " + brew_prefix + "/opt/llvm@15/bin/clang++ > /dev/null"
193+
)
194+
== 0
195+
):
196+
os.environ["CC"] = brew_prefix + "/opt/llvm@15/bin/clang"
197+
os.environ["CXX"] = brew_prefix + "/opt/llvm@15/bin/clang++"
139198
else:
140199
raise RuntimeError("Must use brew clang++")
141-
elif sys.platform == 'linux':
200+
elif sys.platform == "linux":
142201
pass
143-
#os.environ['CC'] = 'clang-15'
144-
#os.environ['CXX'] = 'clang++-15'
202+
# os.environ['CC'] = 'clang-15'
203+
# os.environ['CXX'] = 'clang++-15'
145204
else:
146205
raise RuntimeError("Unsupported platform")
147206

148-
#exec chdb/build.sh and print the output if it fails
207+
# exec chdb/build.sh and print the output if it fails
149208
# Run the build script and capture its output
150209
# if macOS and arch is arm64, run with arch -arm64 /bin/bash
151-
if sys.platform == 'darwin' and os.uname().machine == 'arm64':
152-
completed_process = subprocess.run(["arch", "-arm64", "/bin/bash", "chdb/build.sh"], capture_output=True, text=True)
210+
if sys.platform == "darwin" and os.uname().machine == "arm64":
211+
completed_process = subprocess.run(
212+
["arch", "-arm64", "/bin/bash", "chdb/build.sh"],
213+
capture_output=True,
214+
text=True,
215+
)
153216
else:
154-
completed_process = subprocess.run(["bash", "chdb/build.sh"], capture_output=True, text=True)
217+
completed_process = subprocess.run(
218+
["bash", "chdb/build.sh"], capture_output=True, text=True
219+
)
155220
# If it failed, print the output
156221
print(completed_process.stdout)
157222
print(completed_process.stderr)
@@ -161,7 +226,9 @@ def build_extensions(self):
161226
raise RuntimeError("Build failed")
162227

163228
# add the _chdb.cpython-37m-darwin.so or _chdb.cpython-39-x86_64-linux.so to the chdb package
164-
self.distribution.package_data['chdb'] = [ "chdb/_chdb" + get_python_ext_suffix()]
229+
self.distribution.package_data["chdb"] = [
230+
"chdb/_chdb" + get_python_ext_suffix()
231+
]
165232
# super().build_extensions()
166233

167234

@@ -172,9 +239,9 @@ def build_extensions(self):
172239
chdb_so = libdir + "/_chdb" + get_python_ext_suffix()
173240
ext_modules = [
174241
Extension(
175-
'_chdb',
242+
"_chdb",
176243
sources=["programs/local/LocalChdb.cpp"],
177-
language='c++',
244+
language="c++",
178245
libraries=[],
179246
library_dirs=[libdir],
180247
extra_objects=[chdb_so],
@@ -183,23 +250,25 @@ def build_extensions(self):
183250
# fix the version in chdb/__init__.py
184251
versionStr = get_latest_git_tag()
185252
fix_version_init(versionStr)
186-
253+
# Call the function to update pyproject.toml
254+
# update_pyproject_version(versionStr)
255+
187256
# scan the chdb directory and add all the .py files to the package
188257
pkg_files = []
189258
for root, dirs, files in os.walk(libdir):
190259
for file in files:
191260
if file.endswith(".py"):
192261
pkg_files.append(os.path.join(root, file))
193262
pkg_files.append(chdb_so)
194-
263+
195264
setup(
196-
packages=['chdb'],
265+
packages=["chdb"],
197266
version=versionStr,
198-
package_data={'chdb': pkg_files},
199-
exclude_package_data={'': ['*.pyc', 'src/**']},
267+
package_data={"chdb": pkg_files},
268+
exclude_package_data={"": ["*.pyc", "src/**"]},
200269
ext_modules=ext_modules,
201-
python_requires='>=3.8',
202-
cmdclass={'build_ext': BuildExt},
270+
python_requires=">=3.8",
271+
cmdclass={"build_ext": BuildExt},
203272
test_suite="tests",
204273
zip_safe=False,
205274
)

0 commit comments

Comments
 (0)