Linting and fix build

This commit is contained in:
laggykiller 2024-02-24 03:58:58 +08:00
parent 3ad1b108a4
commit 50ba3498e9
2 changed files with 63 additions and 91 deletions

View file

@ -21,34 +21,6 @@ jobs:
sqlcipher/sqlite3.c sqlcipher/sqlite3.c
sqlcipher/sqlite3.h sqlcipher/sqlite3.h
tests:
needs: [prepare-sqlite]
strategy:
fail-fast: true
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']
os: [ubuntu-20.04, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
submodules: false
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v3
with:
name: sqlite-amalgamation
path: ./src/sqlcipher
- name: Build module
run: |
python setup.py build_ext -i
- name: Run tests
run: |
python -m test
build-wheels: build-wheels:
needs: [prepare-sqlite, tests] needs: [prepare-sqlite, tests]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}

126
setup.py
View file

@ -12,11 +12,11 @@ from setuptools import setup, Extension
# Mapping from Conan architectures to Python machine types # Mapping from Conan architectures to Python machine types
CONAN_ARCHS = { CONAN_ARCHS = {
'x86_64': ['amd64', 'x86_64', 'x64'], "x86_64": ["amd64", "x86_64", "x64"],
'x86': ['i386', 'i686', 'x86'], "x86": ["i386", "i686", "x86"],
'armv8': ['arm64', 'aarch64', 'aarch64_be', 'armv8b', 'armv8l'], "armv8": ["arm64", "aarch64", "aarch64_be", "armv8b", "armv8l"],
'ppc64le': ['ppc64le', 'powerpc'], "ppc64le": ["ppc64le", "powerpc"],
's390x': ['s390', 's390x'], "s390x": ["s390", "s390x"],
} }
# define sqlite sources # define sqlite sources
@ -26,29 +26,29 @@ include_dirs = ["./src"]
# Work around clang raising hard error for unused arguments # Work around clang raising hard error for unused arguments
if sys.platform == "darwin": if sys.platform == "darwin":
os.environ['CFLAGS'] = "-Qunused-arguments" os.environ["CFLAGS"] = "-Qunused-arguments"
def get_arch() -> str: def get_arch() -> str:
"""Get the Conan compilation target architecture. """Get the Conan compilation target architecture.
If not explicitly set using the `SQLCIPHER3_COMPILE_TARGET` environment variable, this will be If not explicitly set using the `SQLCIPHER3_COMPILE_TARGET` environment variable, this will be
determined using the host machine's platform information. determined using the host machine"s platform information.
""" """
env_arch = os.getenv('SQLCIPHER3_COMPILE_TARGET', '') env_arch = os.getenv("SQLCIPHER3_COMPILE_TARGET", "")
if env_arch: if env_arch:
return env_arch return env_arch
if ( if (
platform.architecture()[0] == '32bit' platform.architecture()[0] == "32bit"
and platform.machine().lower() in (CONAN_ARCHS['x86'] + CONAN_ARCHS['x86_64']) and platform.machine().lower() in (CONAN_ARCHS["x86"] + CONAN_ARCHS["x86_64"])
): ):
return 'x86' return "x86"
for k, v in CONAN_ARCHS.items(): for k, v in CONAN_ARCHS.items():
if platform.machine().lower() in v: if platform.machine().lower() in v:
return k return k
raise RuntimeError('Unable to determine the compilation target architecture') raise RuntimeError("Unable to determine the compilation target architecture")
def install_openssl(arch: str) -> dict: def install_openssl(arch: str) -> dict:
@ -56,35 +56,35 @@ def install_openssl(arch: str) -> dict:
""" """
settings = [] settings = []
if platform.system() == 'Windows': if platform.system() == "Windows":
settings.append('os=Windows') settings.append("os=Windows")
elif platform.system() == 'Darwin': elif platform.system() == "Darwin":
settings.append('os=Macos') settings.append("os=Macos")
if arch == 'x86_64': if arch == "x86_64":
settings.append('os.version=10.9') settings.append("os.version=10.9")
else: else:
settings.append('os.version=11.0') settings.append("os.version=11.0")
settings.append('compiler=apple-clang') settings.append("compiler=apple-clang")
settings.append('compiler.libcxx=libc++') settings.append("compiler.libcxx=libc++")
elif platform.system() == 'Linux': elif platform.system() == "Linux":
settings.append('os=Linux') settings.append("os=Linux")
settings.append(f'arch={arch}') settings.append(f"arch={arch}")
build = ['missing'] build = ["missing"]
if os.path.isdir('/lib') and any(e.startswith('libc.musl') for e in os.listdir('/lib')): if os.path.isdir("/lib") and any(e.startswith("libc.musl") for e in os.listdir("/lib")):
# Need to compile openssl if musllinux # Need to compile openssl if musllinux
build.append('openssl*') build.append("openssl*")
subprocess.run(['conan', 'profile', 'detect']) subprocess.run(["conan", "profile", "detect"])
conan_output = os.path.join('conan_output', arch) conan_output = os.path.join("conan_output", arch)
result = subprocess.run([ result = subprocess.run([
'conan', 'install', "conan", "install",
*[x for s in settings for x in ('-s', s)], *[x for s in settings for x in ("-s", s)],
*[x for b in build for x in ('-b', b)], *[x for b in build for x in ("-b", b)],
'-of', conan_output, '--deployer=direct_deploy', '--format=json', '.' "-of", conan_output, "--deployer=direct_deploy", "--format=json", "."
], stdout=subprocess.PIPE).stdout.decode() ], stdout=subprocess.PIPE).stdout.decode()
conan_info = json.loads(result) conan_info = json.loads(result)
@ -93,50 +93,50 @@ def install_openssl(arch: str) -> dict:
def fetch_openssl_dir(conan_info: dict) -> str: def fetch_openssl_dir(conan_info: dict) -> str:
"""Find directory of openssl. """Find directory of openssl.
""" """
for dep in conan_info['graph']['nodes'].values(): for dep in conan_info["graph"]["nodes"].values():
if dep.get('name') == 'openssl': if dep.get("name") == "openssl":
return dep.get('package_folder') return dep.get("package_folder")
def quote_argument(arg): def quote_argument(arg):
q = '\\"' if sys.platform == 'win32' and sys.version_info < (3, 8) else '"' q = '\\"' if sys.platform == "win32" and sys.version_info < (3, 8) else '"'
return q + arg + q return q + arg + q
define_macros = [ define_macros = [
('MODULE_NAME', quote_argument('sqlcipher3.dbapi2')), ("MODULE_NAME", quote_argument("sqlcipher3.dbapi2")),
('ENABLE_FTS3', '1'), ("ENABLE_FTS3", "1"),
('ENABLE_FTS3_PARENTHESIS', '1'), ("ENABLE_FTS3_PARENTHESIS", "1"),
('ENABLE_FTS4', '1'), ("ENABLE_FTS4", "1"),
('ENABLE_FTS5', '1'), ("ENABLE_FTS5", "1"),
('ENABLE_JSON1', '1'), ("ENABLE_JSON1", "1"),
('ENABLE_LOAD_EXTENSION', '1'), ("ENABLE_LOAD_EXTENSION", "1"),
('ENABLE_RTREE', '1'), ("ENABLE_RTREE", "1"),
('ENABLE_STAT4', '1'), ("ENABLE_STAT4", "1"),
('ENABLE_UPDATE_DELETE_LIMIT', '1'), ("ENABLE_UPDATE_DELETE_LIMIT", "1"),
('SOUNDEX', '1'), ("SOUNDEX", "1"),
('USE_URI', '1'), ("USE_URI", "1"),
# Required for SQLCipher. # Required for SQLCipher.
('SQLITE_HAS_CODEC', '1'), ("SQLITE_HAS_CODEC", "1"),
('HAS_CODEC', '1'), ("HAS_CODEC", "1"),
("SQLITE_TEMP_STORE", "2"), ("SQLITE_TEMP_STORE", "2"),
# Increase the maximum number of "host parameters". # Increase the maximum number of "host parameters".
("SQLITE_MAX_VARIABLE_NUMBER", "250000"), ("SQLITE_MAX_VARIABLE_NUMBER", "250000"),
# Additional nice-to-have. # Additional nice-to-have.
('SQLITE_DEFAULT_PAGE_SIZE', '4096'), ("SQLITE_DEFAULT_PAGE_SIZE", "4096"),
('SQLITE_DEFAULT_CACHE_SIZE', '-8000'), ("SQLITE_DEFAULT_CACHE_SIZE", "-8000"),
] ]
arch = get_arch() arch = get_arch()
if arch == 'universal2': if arch == "universal2":
conan_info_x64 = install_openssl('x86_64') conan_info_x64 = install_openssl("x86_64")
openssl_dir_x64 = fetch_openssl_dir(conan_info_x64) openssl_dir_x64 = fetch_openssl_dir(conan_info_x64)
conan_info_arm = install_openssl('armv8') conan_info_arm = install_openssl("armv8")
openssl_dir_arm = fetch_openssl_dir(conan_info_arm) openssl_dir_arm = fetch_openssl_dir(conan_info_arm)
openssl_dir_universal2 = openssl_dir_arm.replace('armv8', 'universal2') openssl_dir_universal2 = openssl_dir_arm.replace("armv8", "universal2")
subprocess.run( subprocess.run(
[ [
'python3', "python3",
'./lipo-dir-merge/lipo-dir-merge.py', "./lipo-dir-merge/lipo-dir-merge.py",
openssl_dir_x64, openssl_dir_x64,
openssl_dir_arm, openssl_dir_arm,
openssl_dir_universal2 openssl_dir_universal2
@ -168,9 +168,9 @@ if sys.platform == "win32":
extra_link_args.append("ADVAPI32.LIB") extra_link_args.append("ADVAPI32.LIB")
extra_link_args.append("CRYPT32.LIB") extra_link_args.append("CRYPT32.LIB")
extra_link_args.append("USER32.LIB") extra_link_args.append("USER32.LIB")
extra_link_args.append('libcrypto.lib') extra_link_args.append("libcrypto.lib")
else: else:
extra_link_args.append('libcrypto.a') extra_link_args.append("libcrypto.a")
module = Extension( module = Extension(
name="sqlcipher3._sqlite3", name="sqlcipher3._sqlite3",
@ -185,8 +185,8 @@ module = Extension(
if __name__ == "__main__": if __name__ == "__main__":
setup( setup(
platforms="ALL", platforms="ALL",
package_dir={'sqlcipher3': "sqlcipher3"}, package_dir={"sqlcipher3": "sqlcipher3"},
packages=['sqlcipher3'], packages=["sqlcipher3"],
ext_modules=[module], ext_modules=[module],
classifiers=[ classifiers=[
"Development Status :: 4 - Beta", "Development Status :: 4 - Beta",