Skip to content

Commit

Permalink
SNOW-1516075: use SQLALchemy 2.0 as default dependency (#511)
Browse files Browse the repository at this point in the history
* SNOW-1516075: use SQLALchemy 2.0 as default dependency
  • Loading branch information
sfc-gh-mraba authored Jul 3, 2024
1 parent d78f0c0 commit 423b8c1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 38 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
strategy:
fail-fast: true
matrix:
hatch-env: [default, sa20]
hatch-env: [default, sa14]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -165,8 +165,8 @@ jobs:
path: |
./coverage.xml
test-dialect-v20:
name: Test dialect v20 ${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
test-dialect-v14:
name: Test dialect v14 ${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
needs: [ lint, build-install ]
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -204,15 +204,15 @@ jobs:
python -m uv pip install -U hatch
python -m hatch env create default
- name: Run tests
run: hatch run sa20:test-dialect
run: hatch run sa14:test-dialect
- uses: actions/upload-artifact@v4
with:
name: coverage.xml_dialect-v20-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
name: coverage.xml_dialect-v14-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
path: |
./coverage.xml
test-dialect-compatibility-v20:
name: Test dialect v20 compatibility ${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
test-dialect-compatibility-v14:
name: Test dialect v14 compatibility ${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
needs: lint
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -250,17 +250,17 @@ jobs:
gpg --quiet --batch --yes --decrypt --passphrase="$PARAMETERS_SECRET" \
.github/workflows/parameters/parameters_${{ matrix.cloud-provider }}.py.gpg > tests/parameters.py
- name: Run tests
run: hatch run sa20:test-dialect-compatibility
run: hatch run sa14:test-dialect-compatibility
- uses: actions/upload-artifact@v4
with:
name: coverage.xml_dialect-v20-compatibility-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
name: coverage.xml_dialect-v14-compatibility-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.cloud-provider }}
path: |
./coverage.xml
combine-coverage:
name: Combine coverage
if: ${{ success() || failure() }}
needs: [test-dialect, test-dialect-compatibility, test-dialect-v20, test-dialect-compatibility-v20]
needs: [test-dialect, test-dialect-compatibility, test-dialect-v14, test-dialect-compatibility-v14]
runs-on: ubuntu-latest
steps:
- name: Set up Python
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ Source code is also available at:

# Release Notes

- v1.6.0(Not released)
- v1.6.0(July 4, 2024)

- support for installing with SQLAlchemy 2.0.x
- use `hatch` & `uv` for managing project virtual environments

- v1.5.4

Expand Down
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ containing special characters need to be URL encoded to be parsed correctly. Thi
characters could lead to authentication failure.

The encoding for the password can be generated using `urllib.parse`:

```python
import urllib.parse
urllib.parse.quote("kx@% jj5/g")
Expand All @@ -111,6 +112,7 @@ urllib.parse.quote("kx@% jj5/g")

To create an engine with the proper encodings, either manually constructing the url string by formatting
or taking advantage of the `snowflake.sqlalchemy.URL` helper method:

```python
import urllib.parse
from snowflake.sqlalchemy import URL
Expand Down Expand Up @@ -191,14 +193,23 @@ engine = create_engine(...)
engine.execute(<SQL>)
engine.dispose()

# Do this.
# Better.
engine = create_engine(...)
connection = engine.connect()
try:
connection.execute(<SQL>)
connection.execute(text(<SQL>))
finally:
connection.close()
engine.dispose()

# Best
try:
with engine.connext() as connection:
connection.execute(text(<SQL>))
# or
connection.exec_driver_sql(<SQL>)
finally:
engine.dispose()
```

### Auto-increment Behavior
Expand Down Expand Up @@ -242,14 +253,14 @@ engine = create_engine(URL(

specific_date = np.datetime64('2016-03-04T12:03:05.123456789Z')

connection = engine.connect()
connection.execute(
"CREATE OR REPLACE TABLE ts_tbl(c1 TIMESTAMP_NTZ)")
connection.execute(
"INSERT INTO ts_tbl(c1) values(%s)", (specific_date,)
)
df = pd.read_sql_query("SELECT * FROM ts_tbl", engine)
assert df.c1.values[0] == specific_date
with engine.connect() as connection:
connection.exec_driver_sql(
"CREATE OR REPLACE TABLE ts_tbl(c1 TIMESTAMP_NTZ)")
connection.exec_driver_sql(
"INSERT INTO ts_tbl(c1) values(%s)", (specific_date,)
)
df = pd.read_sql_query("SELECT * FROM ts_tbl", connection)
assert df.c1.values[0] == specific_date
```

The following `NumPy` data types are supported:
Expand Down
13 changes: 8 additions & 5 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
# Build snowflake-sqlalchemy
set -o pipefail

PYTHON="python3.7"
PYTHON="python3.8"
THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SQLALCHEMY_DIR="$(dirname "${THIS_DIR}")"
DIST_DIR="${SQLALCHEMY_DIR}/dist"

cd "$SQLALCHEMY_DIR"
# Clean up previously built DIST_DIR
if [ -d "${DIST_DIR}" ]; then
echo "[WARN] ${DIST_DIR} already existing, deleting it..."
rm -rf "${DIST_DIR}"
echo "[WARN] ${DIST_DIR} already existing, deleting it..."
rm -rf "${DIST_DIR}"
fi

# Constants and setup

echo "[Info] Building snowflake-sqlalchemy with $PYTHON"
# Clean up possible build artifacts
rm -rf build generated_version.py
${PYTHON} -m pip install --upgrade pip setuptools wheel build
${PYTHON} -m build --outdir ${DIST_DIR} .
# ${PYTHON} -m pip install --upgrade pip setuptools wheel build
# ${PYTHON} -m build --outdir ${DIST_DIR} .
export UV_NO_CACHE=true
${PYTHON} -m pip install uv hatch
${PYTHON} -m hatch build
18 changes: 9 additions & 9 deletions ci/test_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
# - This script assumes that ../dist/repaired_wheels has the wheel(s) built for all versions to be tested
# - This is the script that test_docker.sh runs inside of the docker container

PYTHON_VERSIONS="${1:-3.7 3.8 3.9 3.10 3.11}"
THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SQLALCHEMY_DIR="$( dirname "${THIS_DIR}")"
PYTHON_VERSIONS="${1:-3.8 3.9 3.10 3.11}"
THIS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SQLALCHEMY_DIR="$(dirname "${THIS_DIR}")"

# Install one copy of tox
python3 -m pip install -U tox

# Run tests
cd $SQLALCHEMY_DIR
for PYTHON_VERSION in ${PYTHON_VERSIONS}; do
echo "[Info] Testing with ${PYTHON_VERSION}"
SHORT_VERSION=$(python3 -c "print('${PYTHON_VERSION}'.replace('.', ''))")
SQLALCHEMY_WHL=$(ls $SQLALCHEMY_DIR/dist/snowflake_sqlalchemy-*-py2.py3-none-any.whl | sort -r | head -n 1)
TEST_ENVLIST=fix_lint,py${SHORT_VERSION}-ci,py${SHORT_VERSION}-coverage
echo "[Info] Running tox for ${TEST_ENVLIST}"
python3 -m tox -e ${TEST_ENVLIST} --installpkg ${SQLALCHEMY_WHL}
echo "[Info] Testing with ${PYTHON_VERSION}"
SHORT_VERSION=$(python3 -c "print('${PYTHON_VERSION}'.replace('.', ''))")
SQLALCHEMY_WHL=$(ls $SQLALCHEMY_DIR/dist/snowflake_sqlalchemy-*-py3-none-any.whl | sort -r | head -n 1)
TEST_ENVLIST=fix_lint,py${SHORT_VERSION}-ci,py${SHORT_VERSION}-coverage
echo "[Info] Running tox for ${TEST_ENVLIST}"
python3 -m tox -e ${TEST_ENVLIST} --installpkg ${SQLALCHEMY_WHL}
done
15 changes: 12 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ exclude = ["/.github"]
packages = ["src/snowflake"]

[tool.hatch.envs.default]
extra-dependencies = ["SQLAlchemy>=1.4.19,<2.0.0"]
extra-dependencies = ["SQLAlchemy>=1.4.19,<2.1.0"]
features = ["development", "pandas"]
python = "3.8"
installer = "uv"

[tool.hatch.envs.sa20]
extra-dependencies = ["SQLAlchemy>=1.4.19,<=2.1.0"]
[tool.hatch.envs.sa14]
extra-dependencies = ["SQLAlchemy>=1.4.19,<2.0.0"]
features = ["development", "pandas"]
python = "3.8"

[tool.hatch.envs.default.env-vars]
Expand All @@ -93,6 +94,14 @@ test-dialect-compatibility = "pytest -ra -vvv --tb=short --cov snowflake.sqlalch
gh-cache-sum = "python -VV | sha256sum | cut -d' ' -f1"
check-import = "python -c 'import snowflake.sqlalchemy; print(snowflake.sqlalchemy.__version__)'"

[[tool.hatch.envs.release.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]
features = ["development", "pandas"]

[tool.hatch.envs.release.scripts]
test-dialect = "pytest -ra -vvv --tb=short --ignore=tests/sqlalchemy_test_suite tests/"
test-compatibility = "pytest -ra -vvv --tb=short tests/sqlalchemy_test_suite tests/"

[tool.ruff]
line-length = 88

Expand Down

0 comments on commit 423b8c1

Please sign in to comment.