Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed May 27, 2024
1 parent eed8688 commit dd33f29
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions pyrekordbox/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import urllib.request
from pathlib import Path
from subprocess import run, CalledProcessError
from subprocess import CalledProcessError, run

from pyrekordbox.config import _cache_file, write_db6_key_cache

Expand Down Expand Up @@ -43,22 +43,27 @@ def __exit__(self, exc_type, exc_val, exc_tb):
if self.path != self._prev:
os.chdir(self._prev)


def set_sqlcipher_paths():
result = run(["brew", "--prefix", "sqlcipher"], capture_output=True, text=True)
if result.returncode != 0:
raise CalledProcessError(result.returncode, result.args, output=result.stdout, stderr=result.stderr)
raise CalledProcessError(
result.returncode, result.args, output=result.stdout, stderr=result.stderr
)
sqlcipher_path = result.stdout.strip()

# Ensure OpenSSL paths
openssl_include_path = "/usr/local/opt/openssl/include"
openssl_lib_path = "/usr/local/opt/openssl/lib"

os.environ["C_INCLUDE_PATH"] = f"{sqlcipher_path}/include:{openssl_include_path}"
os.environ["LIBRARY_PATH"] = f"{sqlcipher_path}/lib:{openssl_lib_path}"
os.environ["PKG_CONFIG_PATH"] = f"{sqlcipher_path}/lib/pkgconfig"
os.environ["CFLAGS"] = f"-I{sqlcipher_path}/include -I{openssl_include_path} -Wno-deprecated-declarations -Wno-unused-variable -Wno-unreachable-code -Wno-sign-compare"
os.environ["CFLAGS"] = (
f"-I{sqlcipher_path}/include -I{openssl_include_path} -Wno-deprecated-declarations -Wno-unused-variable -Wno-unreachable-code -Wno-sign-compare"
)
os.environ["LDFLAGS"] = f"-L{sqlcipher_path}/lib -L{openssl_lib_path}"

print(f"SQLCipher path: {sqlcipher_path}")
print(f"C_INCLUDE_PATH: {os.environ['C_INCLUDE_PATH']}")
print(f"LIBRARY_PATH: {os.environ['LIBRARY_PATH']}")
Expand All @@ -70,7 +75,9 @@ def set_sqlcipher_paths():
def create_symlinks():
result = run(["brew", "--prefix", "sqlcipher"], capture_output=True, text=True)
if result.returncode != 0:
raise CalledProcessError(result.returncode, result.args, output=result.stdout, stderr=result.stderr)
raise CalledProcessError(
result.returncode, result.args, output=result.stdout, stderr=result.stderr
)
sqlcipher_path = result.stdout.strip()
symlink_dir = Path("/usr/local")

Expand All @@ -79,21 +86,27 @@ def create_symlinks():
symlink_dir.mkdir(parents=True, exist_ok=True)
(symlink_dir / "lib").mkdir(parents=True, exist_ok=True)
(symlink_dir / "include").mkdir(parents=True, exist_ok=True)

lib_sqlcipher_a = symlink_dir / "lib/libsqlcipher.a"
if not lib_sqlcipher_a.exists():
lib_sqlcipher_a.symlink_to(f"{sqlcipher_path}/lib/libsqlcipher.a", target_is_directory=False)

lib_sqlcipher_a.symlink_to(
f"{sqlcipher_path}/lib/libsqlcipher.a", target_is_directory=False
)

include_sqlcipher = symlink_dir / "include/sqlcipher"
if not include_sqlcipher.exists():
include_sqlcipher.symlink_to(f"{sqlcipher_path}/include/sqlcipher", target_is_directory=True)
include_sqlcipher.symlink_to(
f"{sqlcipher_path}/include/sqlcipher", target_is_directory=True
)

if not (symlink_dir / "include/sqlcipher").exists():
print("Creating necessary symlinks for SQLCipher headers...")
(symlink_dir / "include").mkdir(parents=True, exist_ok=True)
include_sqlcipher = symlink_dir / "include/sqlcipher"
if not include_sqlcipher.exists():
include_sqlcipher.symlink_to(f"{sqlcipher_path}/include/sqlcipher", target_is_directory=True)
include_sqlcipher.symlink_to(
f"{sqlcipher_path}/include/sqlcipher", target_is_directory=True
)


def clone_repo(https_url: str) -> Path:
Expand Down Expand Up @@ -136,6 +149,7 @@ def prepare_pysqlcipher(pysqlcipher_dir: Path, amalgamation_src: Path):
shutil.copy2(amalgamation_src / "sqlite3.c", root / "sqlite3.c")
shutil.copy2(amalgamation_src / "sqlite3.h", root / "sqlite3.h")


def install_pysqlcipher(
tmpdir="pysqlcipher3",
crypto_lib="libcrypto.lib",
Expand Down Expand Up @@ -173,7 +187,6 @@ def install_pysqlcipher(
# Install pysqlcipher package
print()


# Remove temporary files
if cleanup:
try:
Expand Down

0 comments on commit dd33f29

Please sign in to comment.