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