real-ladybug 0.0.1.dev1__cp311-cp311-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of real-ladybug might be problematic. Click here for more details.

Files changed (114) hide show
  1. real_ladybug/__init__.py +83 -0
  2. real_ladybug/_lbug.cp311-win_amd64.pyd +0 -0
  3. real_ladybug/_lbug.exp +0 -0
  4. real_ladybug/_lbug.lib +0 -0
  5. real_ladybug/async_connection.py +226 -0
  6. real_ladybug/connection.py +323 -0
  7. real_ladybug/constants.py +7 -0
  8. real_ladybug/database.py +307 -0
  9. real_ladybug/prepared_statement.py +51 -0
  10. real_ladybug/py.typed +0 -0
  11. real_ladybug/query_result.py +511 -0
  12. real_ladybug/torch_geometric_feature_store.py +185 -0
  13. real_ladybug/torch_geometric_graph_store.py +131 -0
  14. real_ladybug/torch_geometric_result_converter.py +282 -0
  15. real_ladybug/types.py +39 -0
  16. real_ladybug-0.0.1.dev1.dist-info/METADATA +88 -0
  17. real_ladybug-0.0.1.dev1.dist-info/RECORD +114 -0
  18. real_ladybug-0.0.1.dev1.dist-info/WHEEL +5 -0
  19. real_ladybug-0.0.1.dev1.dist-info/licenses/LICENSE +21 -0
  20. real_ladybug-0.0.1.dev1.dist-info/top_level.txt +3 -0
  21. real_ladybug-0.0.1.dev1.dist-info/zip-safe +1 -0
  22. real_ladybug-source/scripts/antlr4/hash.py +2 -0
  23. real_ladybug-source/scripts/antlr4/keywordhandler.py +47 -0
  24. real_ladybug-source/scripts/collect-extensions.py +68 -0
  25. real_ladybug-source/scripts/collect-single-file-header.py +126 -0
  26. real_ladybug-source/scripts/export-dbs.py +101 -0
  27. real_ladybug-source/scripts/export-import-test.py +345 -0
  28. real_ladybug-source/scripts/extension/purge-beta.py +34 -0
  29. real_ladybug-source/scripts/generate-cpp-docs/collect_files.py +122 -0
  30. real_ladybug-source/scripts/generate-tinysnb.py +34 -0
  31. real_ladybug-source/scripts/get-clangd-diagnostics.py +233 -0
  32. real_ladybug-source/scripts/migrate-lbug-db.py +308 -0
  33. real_ladybug-source/scripts/multiplatform-test-helper/collect-results.py +71 -0
  34. real_ladybug-source/scripts/multiplatform-test-helper/notify-discord.py +68 -0
  35. real_ladybug-source/scripts/pip-package/package_tar.py +90 -0
  36. real_ladybug-source/scripts/pip-package/setup.py +130 -0
  37. real_ladybug-source/scripts/run-clang-format.py +408 -0
  38. real_ladybug-source/scripts/setup-extension-repo.py +67 -0
  39. real_ladybug-source/scripts/test-simsimd-dispatch.py +45 -0
  40. real_ladybug-source/scripts/update-nightly-build-version.py +81 -0
  41. real_ladybug-source/third_party/brotli/scripts/dictionary/step-01-download-rfc.py +16 -0
  42. real_ladybug-source/third_party/brotli/scripts/dictionary/step-02-rfc-to-bin.py +34 -0
  43. real_ladybug-source/third_party/brotli/scripts/dictionary/step-03-validate-bin.py +35 -0
  44. real_ladybug-source/third_party/brotli/scripts/dictionary/step-04-generate-java-literals.py +85 -0
  45. real_ladybug-source/third_party/pybind11/tools/codespell_ignore_lines_from_errors.py +35 -0
  46. real_ladybug-source/third_party/pybind11/tools/libsize.py +36 -0
  47. real_ladybug-source/third_party/pybind11/tools/make_changelog.py +63 -0
  48. real_ladybug-source/tools/python_api/build/real_ladybug/__init__.py +83 -0
  49. real_ladybug-source/tools/python_api/build/real_ladybug/async_connection.py +226 -0
  50. real_ladybug-source/tools/python_api/build/real_ladybug/connection.py +323 -0
  51. real_ladybug-source/tools/python_api/build/real_ladybug/constants.py +7 -0
  52. real_ladybug-source/tools/python_api/build/real_ladybug/database.py +307 -0
  53. real_ladybug-source/tools/python_api/build/real_ladybug/prepared_statement.py +51 -0
  54. real_ladybug-source/tools/python_api/build/real_ladybug/py.typed +0 -0
  55. real_ladybug-source/tools/python_api/build/real_ladybug/query_result.py +511 -0
  56. real_ladybug-source/tools/python_api/build/real_ladybug/torch_geometric_feature_store.py +185 -0
  57. real_ladybug-source/tools/python_api/build/real_ladybug/torch_geometric_graph_store.py +131 -0
  58. real_ladybug-source/tools/python_api/build/real_ladybug/torch_geometric_result_converter.py +282 -0
  59. real_ladybug-source/tools/python_api/build/real_ladybug/types.py +39 -0
  60. real_ladybug-source/tools/python_api/src_py/__init__.py +83 -0
  61. real_ladybug-source/tools/python_api/src_py/async_connection.py +226 -0
  62. real_ladybug-source/tools/python_api/src_py/connection.py +323 -0
  63. real_ladybug-source/tools/python_api/src_py/constants.py +7 -0
  64. real_ladybug-source/tools/python_api/src_py/database.py +307 -0
  65. real_ladybug-source/tools/python_api/src_py/prepared_statement.py +51 -0
  66. real_ladybug-source/tools/python_api/src_py/py.typed +0 -0
  67. real_ladybug-source/tools/python_api/src_py/query_result.py +511 -0
  68. real_ladybug-source/tools/python_api/src_py/torch_geometric_feature_store.py +185 -0
  69. real_ladybug-source/tools/python_api/src_py/torch_geometric_graph_store.py +131 -0
  70. real_ladybug-source/tools/python_api/src_py/torch_geometric_result_converter.py +282 -0
  71. real_ladybug-source/tools/python_api/src_py/types.py +39 -0
  72. real_ladybug-source/tools/python_api/test/conftest.py +230 -0
  73. real_ladybug-source/tools/python_api/test/disabled_test_extension.py +73 -0
  74. real_ladybug-source/tools/python_api/test/ground_truth.py +430 -0
  75. real_ladybug-source/tools/python_api/test/test_arrow.py +694 -0
  76. real_ladybug-source/tools/python_api/test/test_async_connection.py +159 -0
  77. real_ladybug-source/tools/python_api/test/test_blob_parameter.py +145 -0
  78. real_ladybug-source/tools/python_api/test/test_connection.py +49 -0
  79. real_ladybug-source/tools/python_api/test/test_database.py +234 -0
  80. real_ladybug-source/tools/python_api/test/test_datatype.py +372 -0
  81. real_ladybug-source/tools/python_api/test/test_df.py +564 -0
  82. real_ladybug-source/tools/python_api/test/test_dict.py +112 -0
  83. real_ladybug-source/tools/python_api/test/test_exception.py +54 -0
  84. real_ladybug-source/tools/python_api/test/test_fsm.py +227 -0
  85. real_ladybug-source/tools/python_api/test/test_get_header.py +49 -0
  86. real_ladybug-source/tools/python_api/test/test_helper.py +8 -0
  87. real_ladybug-source/tools/python_api/test/test_issue.py +147 -0
  88. real_ladybug-source/tools/python_api/test/test_iteration.py +96 -0
  89. real_ladybug-source/tools/python_api/test/test_networkx.py +437 -0
  90. real_ladybug-source/tools/python_api/test/test_parameter.py +340 -0
  91. real_ladybug-source/tools/python_api/test/test_prepared_statement.py +117 -0
  92. real_ladybug-source/tools/python_api/test/test_query_result.py +54 -0
  93. real_ladybug-source/tools/python_api/test/test_query_result_close.py +44 -0
  94. real_ladybug-source/tools/python_api/test/test_scan_pandas.py +676 -0
  95. real_ladybug-source/tools/python_api/test/test_scan_pandas_pyarrow.py +714 -0
  96. real_ladybug-source/tools/python_api/test/test_scan_polars.py +165 -0
  97. real_ladybug-source/tools/python_api/test/test_scan_pyarrow.py +167 -0
  98. real_ladybug-source/tools/python_api/test/test_timeout.py +11 -0
  99. real_ladybug-source/tools/python_api/test/test_torch_geometric.py +640 -0
  100. real_ladybug-source/tools/python_api/test/test_torch_geometric_remote_backend.py +111 -0
  101. real_ladybug-source/tools/python_api/test/test_udf.py +207 -0
  102. real_ladybug-source/tools/python_api/test/test_version.py +6 -0
  103. real_ladybug-source/tools/python_api/test/test_wal.py +80 -0
  104. real_ladybug-source/tools/python_api/test/type_aliases.py +10 -0
  105. real_ladybug-source/tools/rust_api/update_version.py +47 -0
  106. real_ladybug-source/tools/shell/test/conftest.py +218 -0
  107. real_ladybug-source/tools/shell/test/test_helper.py +60 -0
  108. real_ladybug-source/tools/shell/test/test_shell_basics.py +325 -0
  109. real_ladybug-source/tools/shell/test/test_shell_commands.py +656 -0
  110. real_ladybug-source/tools/shell/test/test_shell_control_edit.py +438 -0
  111. real_ladybug-source/tools/shell/test/test_shell_control_search.py +468 -0
  112. real_ladybug-source/tools/shell/test/test_shell_esc_edit.py +232 -0
  113. real_ladybug-source/tools/shell/test/test_shell_esc_search.py +162 -0
  114. real_ladybug-source/tools/shell/test/test_shell_flags.py +645 -0
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import os
4
+ import shutil
5
+ import subprocess
6
+ import sys
7
+ import tarfile
8
+ from tempfile import TemporaryDirectory
9
+
10
+ base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
11
+
12
+
13
+ def _get_lbug_version():
14
+ cmake_file = os.path.abspath(os.path.join(base_dir, "..", "CMakeLists.txt"))
15
+ with open(cmake_file) as f:
16
+ for line in f:
17
+ if line.startswith("project(Lbug VERSION"):
18
+ raw_version = line.split(" ")[2].strip()
19
+ version_nums = raw_version.split(".")
20
+ if len(version_nums) <= 3:
21
+ return raw_version
22
+ else:
23
+ dev_suffix = version_nums[3]
24
+ version = ".".join(version_nums[:3])
25
+ version += ".dev%s" % dev_suffix
26
+ return version
27
+
28
+
29
+ if __name__ == "__main__":
30
+ if len(sys.argv) == 2:
31
+ file_name = sys.argv[1]
32
+ else:
33
+ file_name = "real_ladybug-%s.tar.gz" % _get_lbug_version()
34
+ print("Creating %s..." % file_name)
35
+
36
+ with TemporaryDirectory() as tempdir:
37
+ subprocess.check_call(
38
+ [
39
+ "git",
40
+ "archive",
41
+ "--format",
42
+ "tar",
43
+ "-o",
44
+ os.path.join(tempdir, "real_ladybug-source.tar"),
45
+ "HEAD",
46
+ ],
47
+ cwd="../..",
48
+ )
49
+
50
+ with tarfile.open(os.path.join(tempdir, "real_ladybug-source.tar")) as tar:
51
+ tar.extractall(path=os.path.join(tempdir, "real_ladybug-source"), filter=None)
52
+
53
+ os.remove(os.path.join(tempdir, "real_ladybug-source.tar"))
54
+
55
+ # Remove components that are not needed for the pip package
56
+ shutil.rmtree(os.path.join(tempdir, "real_ladybug-source/dataset"))
57
+ shutil.rmtree(os.path.join(tempdir, "real_ladybug-source/examples"))
58
+ shutil.rmtree(os.path.join(tempdir, "real_ladybug-source/benchmark"))
59
+ shutil.rmtree(os.path.join(tempdir, "real_ladybug-source/logo"))
60
+ shutil.rmtree(os.path.join(tempdir, "real_ladybug-source/extension"))
61
+ shutil.rmtree(os.path.join(tempdir, "real_ladybug-source/test"))
62
+ shutil.rmtree(os.path.join(tempdir, "real_ladybug-source/.github"))
63
+
64
+ os.makedirs(os.path.join(tempdir, "real_ladybug"))
65
+ for path in ["setup.py", "setup.cfg", "MANIFEST.in"]:
66
+ shutil.copy2(path, os.path.join(tempdir, path))
67
+ shutil.copy2("../../LICENSE", os.path.join(tempdir, "LICENSE"))
68
+ shutil.copy2("../../README.md", os.path.join(tempdir, "README.md"))
69
+
70
+ shutil.copy2(
71
+ "../../tools/python_api/pyproject.toml",
72
+ os.path.join(tempdir, "pyproject.toml"),
73
+ )
74
+ # Update the version in pyproject.toml
75
+ with open(os.path.join(tempdir, "pyproject.toml"), "r") as f:
76
+ lines = f.readlines()
77
+ with open(os.path.join(tempdir, "pyproject.toml"), "w") as f:
78
+ for line in lines:
79
+ if line.startswith("version ="):
80
+ f.write('version = "%s"\n' % _get_lbug_version())
81
+ else:
82
+ f.write(line)
83
+ shutil.copy2("README.md", os.path.join(tempdir, "README_PYTHON_BUILD.md"))
84
+ subprocess.check_call([sys.executable, "setup.py", "egg_info"], cwd=tempdir)
85
+ shutil.copy2(
86
+ os.path.join(tempdir, "real_ladybug.egg-info", "PKG-INFO"),
87
+ os.path.join(tempdir, "PKG-INFO"),
88
+ )
89
+ with tarfile.open(file_name, "w:gz") as sdist:
90
+ sdist.add(tempdir, "sdist")
@@ -0,0 +1,130 @@
1
+ import shutil
2
+ import subprocess
3
+ import multiprocessing
4
+ import os
5
+ import sys
6
+
7
+ from setuptools import setup, Extension
8
+ from setuptools.command.build_ext import build_ext
9
+ from setuptools.command.build_py import build_py as _build_py
10
+
11
+ base_dir = os.path.dirname(__file__)
12
+
13
+ with open(os.path.join(base_dir, 'real_ladybug-source', 'tools', 'python_api', 'requirements_dev.txt')) as f:
14
+ requirements = f.read().splitlines()
15
+
16
+
17
+ def _get_lbug_version():
18
+ cmake_file = os.path.join(base_dir, 'real_ladybug-source', 'CMakeLists.txt')
19
+ with open(cmake_file) as f:
20
+ for line in f:
21
+ if line.startswith('project(Lbug VERSION'):
22
+ raw_version = line.split(' ')[2].strip()
23
+ version_nums = raw_version.split('.')
24
+ if len(version_nums) <= 3:
25
+ return raw_version
26
+ else:
27
+ dev_suffix = version_nums[3]
28
+ version = '.'.join(version_nums[:3])
29
+ version += ".dev%s" % dev_suffix
30
+ return version
31
+
32
+ lbug_version = _get_lbug_version()
33
+ print("The version of this build is %s" % lbug_version)
34
+
35
+
36
+ class CMakeExtension(Extension):
37
+ def __init__(self, name: str, sourcedir: str = "") -> None:
38
+ super().__init__(name, sources=[])
39
+ self.sourcedir = os.path.abspath(sourcedir)
40
+
41
+
42
+ class CMakeBuild(build_ext):
43
+ def build_extension(self, ext: CMakeExtension) -> None:
44
+ self.announce("Building native extension...")
45
+ # Pass the platform architecture for arm64 to cmake for
46
+ # cross-compilation.
47
+ env_vars = os.environ.copy()
48
+ python_version = '.'.join(
49
+ (str(sys.version_info.major), str(sys.version_info.minor)))
50
+ self.announce("Python version is %s" % python_version)
51
+ env_vars['PYBIND11_PYTHON_VERSION'] = python_version
52
+ env_vars['PYTHON_EXECUTABLE'] = sys.executable
53
+
54
+ if sys.platform == 'darwin':
55
+ archflags = os.getenv("ARCHFLAGS", "")
56
+
57
+ if len(archflags) > 0:
58
+ self.announce("The ARCHFLAGS is set to '%s'." %
59
+ archflags)
60
+ if archflags == "-arch arm64":
61
+ env_vars['CMAKE_OSX_ARCHITECTURES'] = "arm64"
62
+ elif archflags == "-arch x86_64":
63
+ env_vars['CMAKE_OSX_ARCHITECTURES'] = "x86_64"
64
+ else:
65
+ self.announce(
66
+ "The ARCHFLAGS is not valid and will be ignored.")
67
+ else:
68
+ self.announce("The ARCHFLAGS is not set.")
69
+
70
+ deploy_target = os.getenv("MACOSX_DEPLOYMENT_TARGET", "")
71
+ if len(deploy_target) > 0:
72
+ self.announce("The deployment target is set to '%s'." %
73
+ deploy_target)
74
+ env_vars['CMAKE_OSX_DEPLOYMENT_TARGET'] = deploy_target
75
+
76
+ build_dir = os.path.join(ext.sourcedir, 'real_ladybug-source')
77
+
78
+ # Clean the build directory.
79
+ subprocess.run(['make', 'clean'], check=True, cwd=build_dir)
80
+
81
+ try:
82
+ num_cores = int(os.environ['NUM_THREADS'])
83
+ self.announce("Using %d cores for building the native extension." % num_cores)
84
+ except:
85
+ self.announce("NUM_THREADS is not set. Using all available cores.")
86
+ num_cores = multiprocessing.cpu_count()
87
+
88
+ # Build the native extension.
89
+ full_cmd = ['make', 'python', 'NUM_THREADS=%d' % num_cores]
90
+ subprocess.run(full_cmd, cwd=build_dir, check=True, env=env_vars)
91
+ self.announce("Done building native extension.")
92
+ self.announce("Copying native extension...")
93
+ dst = os.path.join(ext.sourcedir, ext.name)
94
+ shutil.rmtree(dst, ignore_errors=True)
95
+ shutil.copytree(os.path.join(build_dir, 'tools', 'python_api', 'build',
96
+ ext.name), dst)
97
+ # Copy to build directory (for wheel packaging) - THIS IS CRITICAL
98
+ self.announce("Copying native extension to build directory...")
99
+ build_dst = os.path.join(self.build_lib, ext.name)
100
+ shutil.rmtree(build_dst, ignore_errors=True)
101
+ shutil.copytree(os.path.join(build_dir, 'tools', 'python_api', 'build',
102
+ ext.name), build_dst)
103
+
104
+ self.announce("Done copying native extension.")
105
+
106
+
107
+ class BuildExtFirst(_build_py):
108
+ # Override the build_py command to build the extension first.
109
+ def run(self):
110
+ self.run_command("build_ext")
111
+ return super().run()
112
+
113
+
114
+ setup(name='real_ladybug',
115
+ version=lbug_version,
116
+ install_requires=[],
117
+ ext_modules=[CMakeExtension(
118
+ name="real_ladybug", sourcedir=base_dir)],
119
+ description='An in-process property graph database management system built for query speed and scalability.',
120
+ license='MIT',
121
+ long_description=open(os.path.join(base_dir, "README.md"), 'r').read(),
122
+ long_description_content_type="text/markdown",
123
+ packages=["real_ladybug"],
124
+ zip_safe=True,
125
+ include_package_data=True,
126
+ cmdclass={
127
+ 'build_py': BuildExtFirst,
128
+ 'build_ext': CMakeBuild,
129
+ }
130
+ )
@@ -0,0 +1,408 @@
1
+ #!/usr/bin/env python3
2
+ """A wrapper script around clang-format, suitable for linting multiple files
3
+ and to use for continuous integration.
4
+
5
+ This is an alternative API for the clang-format command line.
6
+ It runs over multiple files and directories in parallel.
7
+ A diff output is produced and a sensible exit code is returned.
8
+
9
+ """
10
+
11
+ from __future__ import print_function, unicode_literals
12
+
13
+ import argparse
14
+ import codecs
15
+ import difflib
16
+ import errno
17
+ import fnmatch
18
+ import io
19
+ import multiprocessing
20
+ import os
21
+ import signal
22
+ import subprocess
23
+ import sys
24
+ import traceback
25
+ from functools import partial
26
+
27
+ try:
28
+ from subprocess import DEVNULL # py3k
29
+ except ImportError:
30
+ DEVNULL = open(os.devnull, "wb")
31
+
32
+ DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx'
33
+ DEFAULT_CLANG_FORMAT_IGNORE = '.clang-format-ignore'
34
+
35
+
36
+ class ExitStatus:
37
+ SUCCESS = 0
38
+ DIFF = 1
39
+ TROUBLE = 2
40
+
41
+
42
+ def excludes_from_file(ignore_file):
43
+ excludes = []
44
+ try:
45
+ with io.open(ignore_file, 'r', encoding='utf-8') as f:
46
+ for line in f:
47
+ if line.startswith('#'):
48
+ # ignore comments
49
+ continue
50
+ pattern = line.rstrip()
51
+ if not pattern:
52
+ # allow empty lines
53
+ continue
54
+ excludes.append(pattern)
55
+ except EnvironmentError as e:
56
+ if e.errno != errno.ENOENT:
57
+ raise
58
+ return excludes;
59
+
60
+
61
+ def list_files(files, recursive=False, extensions=None, exclude=None):
62
+ if extensions is None:
63
+ extensions = []
64
+ if exclude is None:
65
+ exclude = []
66
+
67
+ out = []
68
+ for file in files:
69
+ if recursive and os.path.isdir(file):
70
+ for dirpath, dnames, fnames in os.walk(file):
71
+ fpaths = [os.path.join(dirpath, fname) for fname in fnames]
72
+ for pattern in exclude:
73
+ # os.walk() supports trimming down the dnames list
74
+ # by modifying it in-place,
75
+ # to avoid unnecessary directory listings.
76
+ dnames[:] = [
77
+ x for x in dnames
78
+ if
79
+ not fnmatch.fnmatch(os.path.join(dirpath, x), pattern)
80
+ ]
81
+ fpaths = [
82
+ x for x in fpaths if not fnmatch.fnmatch(x, pattern)
83
+ ]
84
+ for f in fpaths:
85
+ ext = os.path.splitext(f)[1][1:]
86
+ if ext in extensions:
87
+ out.append(f)
88
+ else:
89
+ out.append(file)
90
+ return out
91
+
92
+
93
+ def make_diff(file, original, reformatted):
94
+ return list(
95
+ difflib.unified_diff(
96
+ original,
97
+ reformatted,
98
+ fromfile='{}\t(original)'.format(file),
99
+ tofile='{}\t(reformatted)'.format(file),
100
+ n=3))
101
+
102
+
103
+ class DiffError(Exception):
104
+ def __init__(self, message, errs=None):
105
+ super(DiffError, self).__init__(message)
106
+ self.errs = errs or []
107
+
108
+
109
+ class UnexpectedError(Exception):
110
+ def __init__(self, message, exc=None):
111
+ super(UnexpectedError, self).__init__(message)
112
+ self.formatted_traceback = traceback.format_exc()
113
+ self.exc = exc
114
+
115
+
116
+ def run_clang_format_diff_wrapper(args, file):
117
+ try:
118
+ ret = run_clang_format_diff(args, file)
119
+ return ret
120
+ except DiffError:
121
+ raise
122
+ except Exception as e:
123
+ raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__,
124
+ e), e)
125
+
126
+
127
+ def run_clang_format_diff(args, file):
128
+ try:
129
+ with io.open(file, 'r', encoding='utf-8') as f:
130
+ original = f.readlines()
131
+ except IOError as exc:
132
+ raise DiffError(str(exc))
133
+
134
+ if args.in_place:
135
+ invocation = [args.clang_format_executable, '-i', file]
136
+ else:
137
+ invocation = [args.clang_format_executable, file]
138
+
139
+ if args.style:
140
+ invocation.extend(['--style', args.style])
141
+
142
+ if args.dry_run:
143
+ print(" ".join(invocation))
144
+ return [], []
145
+
146
+ # Use of utf-8 to decode the process output.
147
+ #
148
+ # Hopefully, this is the correct thing to do.
149
+ #
150
+ # It's done due to the following assumptions (which may be incorrect):
151
+ # - clang-format will returns the bytes read from the files as-is,
152
+ # without conversion, and it is already assumed that the files use utf-8.
153
+ # - if the diagnostics were internationalized, they would use utf-8:
154
+ # > Adding Translations to Clang
155
+ # >
156
+ # > Not possible yet!
157
+ # > Diagnostic strings should be written in UTF-8,
158
+ # > the client can translate to the relevant code page if needed.
159
+ # > Each translation completely replaces the format string
160
+ # > for the diagnostic.
161
+ # > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation
162
+ #
163
+ # It's not pretty, due to Python 2 & 3 compatibility.
164
+ encoding_py3 = {}
165
+ if sys.version_info[0] >= 3:
166
+ encoding_py3['encoding'] = 'utf-8'
167
+
168
+ try:
169
+ proc = subprocess.Popen(
170
+ invocation,
171
+ stdout=subprocess.PIPE,
172
+ stderr=subprocess.PIPE,
173
+ universal_newlines=True,
174
+ **encoding_py3)
175
+ except OSError as exc:
176
+ raise DiffError(
177
+ "Command '{}' failed to start: {}".format(
178
+ subprocess.list2cmdline(invocation), exc
179
+ )
180
+ )
181
+ proc_stdout = proc.stdout
182
+ proc_stderr = proc.stderr
183
+ if sys.version_info[0] < 3:
184
+ # make the pipes compatible with Python 3,
185
+ # reading lines should output unicode
186
+ encoding = 'utf-8'
187
+ proc_stdout = codecs.getreader(encoding)(proc_stdout)
188
+ proc_stderr = codecs.getreader(encoding)(proc_stderr)
189
+ # hopefully the stderr pipe won't get full and block the process
190
+ outs = list(proc_stdout.readlines())
191
+ errs = list(proc_stderr.readlines())
192
+ proc.wait()
193
+ if proc.returncode:
194
+ raise DiffError(
195
+ "Command '{}' returned non-zero exit status {}".format(
196
+ subprocess.list2cmdline(invocation), proc.returncode
197
+ ),
198
+ errs,
199
+ )
200
+ if args.in_place:
201
+ return [], errs
202
+ return make_diff(file, original, outs), errs
203
+
204
+
205
+ def bold_red(s):
206
+ return '\x1b[1m\x1b[31m' + s + '\x1b[0m'
207
+
208
+
209
+ def colorize(diff_lines):
210
+ def bold(s):
211
+ return '\x1b[1m' + s + '\x1b[0m'
212
+
213
+ def cyan(s):
214
+ return '\x1b[36m' + s + '\x1b[0m'
215
+
216
+ def green(s):
217
+ return '\x1b[32m' + s + '\x1b[0m'
218
+
219
+ def red(s):
220
+ return '\x1b[31m' + s + '\x1b[0m'
221
+
222
+ for line in diff_lines:
223
+ if line[:4] in ['--- ', '+++ ']:
224
+ yield bold(line)
225
+ elif line.startswith('@@ '):
226
+ yield cyan(line)
227
+ elif line.startswith('+'):
228
+ yield green(line)
229
+ elif line.startswith('-'):
230
+ yield red(line)
231
+ else:
232
+ yield line
233
+
234
+
235
+ def print_diff(diff_lines, use_color):
236
+ if use_color:
237
+ diff_lines = colorize(diff_lines)
238
+ if sys.version_info[0] < 3:
239
+ sys.stdout.writelines((l.encode('utf-8') for l in diff_lines))
240
+ else:
241
+ sys.stdout.writelines(diff_lines)
242
+
243
+
244
+ def print_trouble(prog, message, use_colors):
245
+ error_text = 'error:'
246
+ if use_colors:
247
+ error_text = bold_red(error_text)
248
+ print("{}: {} {}".format(prog, error_text, message), file=sys.stderr)
249
+
250
+
251
+ def main():
252
+ parser = argparse.ArgumentParser(description=__doc__)
253
+ parser.add_argument(
254
+ '--clang-format-executable',
255
+ metavar='EXECUTABLE',
256
+ help='path to the clang-format executable',
257
+ default='clang-format-11')
258
+ parser.add_argument(
259
+ '--extensions',
260
+ help='comma separated list of file extensions (default: {})'.format(
261
+ DEFAULT_EXTENSIONS),
262
+ default=DEFAULT_EXTENSIONS)
263
+ parser.add_argument(
264
+ '-r',
265
+ '--recursive',
266
+ action='store_true',
267
+ help='run recursively over directories')
268
+ parser.add_argument(
269
+ '-d',
270
+ '--dry-run',
271
+ action='store_true',
272
+ help='just print the list of files')
273
+ parser.add_argument(
274
+ '-i',
275
+ '--in-place',
276
+ action='store_true',
277
+ help='format file instead of printing differences')
278
+ parser.add_argument('files', metavar='file', nargs='+')
279
+ parser.add_argument(
280
+ '-q',
281
+ '--quiet',
282
+ action='store_true',
283
+ help="disable output, useful for the exit code")
284
+ parser.add_argument(
285
+ '-j',
286
+ metavar='N',
287
+ type=int,
288
+ default=0,
289
+ help='run N clang-format jobs in parallel'
290
+ ' (default number of cpus + 1)')
291
+ parser.add_argument(
292
+ '--color',
293
+ default='auto',
294
+ choices=['auto', 'always', 'never'],
295
+ help='show colored diff (default: auto)')
296
+ parser.add_argument(
297
+ '-e',
298
+ '--exclude',
299
+ metavar='PATTERN',
300
+ action='append',
301
+ default=[],
302
+ help='exclude paths matching the given glob-like pattern(s)'
303
+ ' from recursive search')
304
+ parser.add_argument(
305
+ '--style',
306
+ help='formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)')
307
+
308
+ args = parser.parse_args()
309
+
310
+ # use default signal handling, like diff return SIGINT value on ^C
311
+ # https://bugs.python.org/issue14229#msg156446
312
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
313
+ try:
314
+ signal.SIGPIPE
315
+ except AttributeError:
316
+ # compatibility, SIGPIPE does not exist on Windows
317
+ pass
318
+ else:
319
+ signal.signal(signal.SIGPIPE, signal.SIG_DFL)
320
+
321
+ colored_stdout = False
322
+ colored_stderr = False
323
+ if args.color == 'always':
324
+ colored_stdout = True
325
+ colored_stderr = True
326
+ elif args.color == 'auto':
327
+ colored_stdout = sys.stdout.isatty()
328
+ colored_stderr = sys.stderr.isatty()
329
+
330
+ version_invocation = [args.clang_format_executable, str("--version")]
331
+ try:
332
+ subprocess.check_call(version_invocation, stdout=DEVNULL)
333
+ except subprocess.CalledProcessError as e:
334
+ print_trouble(parser.prog, str(e), use_colors=colored_stderr)
335
+ return ExitStatus.TROUBLE
336
+ except OSError as e:
337
+ print_trouble(
338
+ parser.prog,
339
+ "Command '{}' failed to start: {}".format(
340
+ subprocess.list2cmdline(version_invocation), e
341
+ ),
342
+ use_colors=colored_stderr,
343
+ )
344
+ return ExitStatus.TROUBLE
345
+
346
+ retcode = ExitStatus.SUCCESS
347
+
348
+ excludes = excludes_from_file(DEFAULT_CLANG_FORMAT_IGNORE)
349
+ excludes.extend(args.exclude)
350
+
351
+ files = list_files(
352
+ args.files,
353
+ recursive=args.recursive,
354
+ exclude=excludes,
355
+ extensions=args.extensions.split(','))
356
+
357
+ if not files:
358
+ return
359
+
360
+ njobs = args.j
361
+ if njobs == 0:
362
+ njobs = multiprocessing.cpu_count() + 1
363
+ njobs = min(len(files), njobs)
364
+
365
+ if njobs == 1:
366
+ # execute directly instead of in a pool,
367
+ # less overhead, simpler stacktraces
368
+ it = (run_clang_format_diff_wrapper(args, file) for file in files)
369
+ pool = None
370
+ else:
371
+ pool = multiprocessing.Pool(njobs)
372
+ it = pool.imap_unordered(
373
+ partial(run_clang_format_diff_wrapper, args), files)
374
+ pool.close()
375
+ while True:
376
+ try:
377
+ outs, errs = next(it)
378
+ except StopIteration:
379
+ break
380
+ except DiffError as e:
381
+ print_trouble(parser.prog, str(e), use_colors=colored_stderr)
382
+ retcode = ExitStatus.TROUBLE
383
+ sys.stderr.writelines(e.errs)
384
+ except UnexpectedError as e:
385
+ print_trouble(parser.prog, str(e), use_colors=colored_stderr)
386
+ sys.stderr.write(e.formatted_traceback)
387
+ retcode = ExitStatus.TROUBLE
388
+ # stop at the first unexpected error,
389
+ # something could be very wrong,
390
+ # don't process all files unnecessarily
391
+ if pool:
392
+ pool.terminate()
393
+ break
394
+ else:
395
+ sys.stderr.writelines(errs)
396
+ if outs == []:
397
+ continue
398
+ if not args.quiet:
399
+ print_diff(outs, use_color=colored_stdout)
400
+ if retcode == ExitStatus.SUCCESS:
401
+ retcode = ExitStatus.DIFF
402
+ if pool:
403
+ pool.join()
404
+ return retcode
405
+
406
+
407
+ if __name__ == '__main__':
408
+ sys.exit(main())
@@ -0,0 +1,67 @@
1
+ import os
2
+ import shutil
3
+ import sys
4
+ import platform
5
+ import requests
6
+
7
+ def extract_extension_version() -> str:
8
+ import re
9
+ pattern = r'-DLBUG_EXTENSION_VERSION=(["\'])(.*?)\1'
10
+ with open('./CMakeLists.txt', 'r') as f:
11
+ for line in f:
12
+ match = re.search(pattern, line)
13
+ if match:
14
+ version = match.group(2)
15
+ return version
16
+ raise Exception("Failed to infer LBUG extension version from CMAKE file.")
17
+
18
+
19
+ def get_os() -> str:
20
+ os_name = "linux"
21
+ if sys.platform.startswith("win32"):
22
+ os_name = "win"
23
+ elif sys.platform.startswith("darwin"):
24
+ os_name = "osx"
25
+ return os_name
26
+
27
+
28
+ def get_arch() -> str:
29
+ machine = platform.machine().lower()
30
+ if "aarch64" in machine or "arm64" in machine:
31
+ return "arm64"
32
+ return "amd64" # Default to amd64
33
+
34
+
35
+ extension_repo_path = 'extension/repo'
36
+ lbug_version = 'v' + extract_extension_version()
37
+ arch_version = f"{get_os()}_{get_arch()}"
38
+ shutil.rmtree(extension_repo_path, ignore_errors=True)
39
+ os.mkdir(extension_repo_path)
40
+ path = os.path.join(extension_repo_path, lbug_version)
41
+ os.mkdir(path)
42
+ path = os.path.join(path, arch_version)
43
+ os.mkdir(path)
44
+
45
+ # Create common dir
46
+ extensions = [d for d in os.listdir('extension') if os.path.isdir(os.path.join('extension', d)) and d != 'repo']
47
+ for extension in extensions:
48
+ shutil.copytree(os.path.join('extension', extension, 'build'), os.path.join(path, extension))
49
+
50
+ # Download duckdb lib from official repo to local
51
+ if get_os() != "win":
52
+ os.mkdir(os.path.join(path, "common"))
53
+ file_name = 'libduckdb'
54
+ if get_os() == "osx":
55
+ file_name += '.dylib'
56
+ else:
57
+ file_name += '.so'
58
+ official_repo = f"https://extension.lbugdb.com/{lbug_version}/{arch_version}/common/{file_name}"
59
+ response = requests.get(official_repo)
60
+ if response.status_code == 200:
61
+ with open(os.path.join(path, 'common', file_name), "wb") as f:
62
+ f.write(response.content)
63
+ else:
64
+ print(official_repo)
65
+ raise Exception("Failed to download shared duckdb library from official repo.")
66
+
67
+ os.system("python3 -m RangeHTTPServer 80")