Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
carderne committed Aug 1, 2024
1 parent 10c233a commit 6f0ac78
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 69 deletions.
36 changes: 3 additions & 33 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,19 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: prep pysqlcipher3
run: |
git clone --depth=1 --branch=master https://github.com/rigglemania/pysqlcipher3.git
cd pysqlcipher3
mkdir amalgamation
cp ../sqlcipher/sqlite3.[ch] amalgamation
mkdir src/python3/sqlcipher
cp ../sqlcipher/sqlite3.[ch] src/python3/sqlcipher
pip install setuptools
- name: build pysqlcipher3 linux
if: matrix.os == 'ubuntu-latest'
run: |
cd pysqlcipher3
python setup.py build_amalgamation
python setup.py build
echo 'PLATFORM_TAG="manylinux2014_x86_64"' >> $GITHUB_ENV
- name: build pysqlcipher3 macOS
- name: extra env vars for macOS
if: matrix.os == 'macos-latest'
run: |
brew install openssl
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
cd pysqlcipher3
python setup.py build_amalgamation
python setup.py build
echo 'PLATFORM_TAG="macosx_10_9_universal2"' >> $GITHUB_ENV
- name: post-build pysqlcipher3
run: |
mkdir src/pysqlcipher3
for f in pysqlcipher3/build/lib.*/pysqlcipher3/*.{py,so}; do cp $f src/pysqlcipher3/; done
- name: build
run: |
pip install build
python -m build
cd dist
NEW_NAME=$(ls *.whl | sed "s/any.whl$/${{ env.PLATFORM_TAG }}.whl/")
mv *.whl $NEW_NAME
echo "WHEEL_NAME=$(ls *.whl)" >> $GITHUB_ENV
echo "SDIST_NAME=$(ls *.tar.gz)" >> $GITHUB_ENV
echo "WHEEL_NAME=$(ls dist/*.whl)" >> $GITHUB_ENV
echo "SDIST_NAME=$(ls dist/*.tar.gz)" >> $GITHUB_ENV
- name: test
run: |
Expand Down
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
graft sqlcipher
graft src

global-exclude *~ *.pyc
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ dev-dependencies = [
"pytest-cov",
"types-Markdown",
"types-emoji",
"setuptools-scm~=8.1.0",
"build~=1.2.1",
]

[project.urls]
Expand Down
7 changes: 7 additions & 0 deletions requirements-dev.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-e file:.
beautifulsoup4==4.12.3
# via signal-export
build==1.2.1
cfgv==3.4.0
# via pre-commit
click==8.1.7
Expand Down Expand Up @@ -40,7 +41,9 @@ nodeenv==1.8.0
# via pre-commit
# via pyright
packaging==24.0
# via build
# via pytest
# via setuptools-scm
platformdirs==4.2.0
# via virtualenv
pluggy==1.4.0
Expand All @@ -50,6 +53,8 @@ pycryptodome==3.20.0
# via signal-export
pygments==2.17.2
# via rich
pyproject-hooks==1.1.0
# via build
pyright==1.1.354
pytest==8.1.1
# via pytest-cov
Expand All @@ -60,6 +65,8 @@ rich==13.7.1
# via typer
setuptools==69.2.0
# via nodeenv
# via setuptools-scm
setuptools-scm==8.1.0
shellingham==1.5.4
# via typer
soupsieve==2.5
Expand Down
51 changes: 15 additions & 36 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,15 @@ def quote_argument(arg: str) -> str:


class AmalgationLibSQLCipherBuilder(build_ext):
description = "Builds a C extension using a sqlcipher amalgamation"

amalgamation_root = "sqlcipher"
amalgamation_header = os.path.join(amalgamation_root, "sqlite3.h")
amalgamation_source = os.path.join(amalgamation_root, "sqlite3.c")

amalgamation_message = """
SQL Cipher amalgamation not found. Please download or build the
amalgamation and make sure the following files are present in the
amalgamation folder: sqlite3.h, sqlite3.c"""

def check_amalgamation(self): # noqa
if not os.path.exists(self.amalgamation_root):
os.mkdir(self.amalgamation_root)

header_exists = os.path.exists(self.amalgamation_header)
source_exists = os.path.exists(self.amalgamation_source)
if not header_exists or not source_exists:
raise RuntimeError(self.amalgamation_message)

def build_extension(self, ext): # noqa # type: ignore
print(self.description)
sqlcipher_root = Path("sqlcipher")
sqlcipher_header = sqlcipher_root / "sqlite3.h"
sqlcipher_source = sqlcipher_root / "sqlite3.c"
if not sqlcipher_header.exists() or not sqlcipher_source.exists():
raise RuntimeError("SQLCipher amalgamation not found")

# it is responsibility of user to provide amalgamation
self.check_amalgamation()
ext.include_dirs.append(str(sqlcipher_root))
ext.sources.append(str(sqlcipher_source))

# build with fulltext search enabled
ext.define_macros.append(("SQLITE_ENABLE_FTS3", "1"))
Expand All @@ -86,9 +70,6 @@ def build_extension(self, ext): # noqa # type: ignore
ext.define_macros.append(("SQLITE_HAS_CODEC", "1"))
ext.define_macros.append(("SQLITE_TEMP_STORE", "2"))

ext.include_dirs.append(self.amalgamation_root)
ext.sources.append(os.path.join(self.amalgamation_root, "sqlite3.c"))

if sys.platform == "win32":
# Try to locate openssl
openssl_conf = os.environ.get("OPENSSL_CONF")
Expand All @@ -113,14 +94,12 @@ def build_extension(self, ext): # noqa # type: ignore


setuptools.setup(
**{
"ext_modules": [
Extension(
name=PACKAGE_NAME + EXTENSION_MODULE_NAME,
sources=sources,
define_macros=define_macros,
)
],
"cmdclass": {"build_ext": AmalgationLibSQLCipherBuilder},
}
ext_modules=[
Extension(
name=PACKAGE_NAME + EXTENSION_MODULE_NAME,
sources=sources,
define_macros=define_macros,
)
],
cmdclass={"build_ext": AmalgationLibSQLCipherBuilder},
)
10 changes: 10 additions & 0 deletions src/pysqlcipher3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ Source: https://github.com/rigglemania/pysqlcipher3/
All files in this tree include their original copyright statements.

Vendored to make static builds easier.

Build on macOS:
```bash
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
python setup.py bdist_wheel

# or
python -m build
```

0 comments on commit 6f0ac78

Please sign in to comment.