diff --git a/.github/workflows/build-distributions.yml b/.github/workflows/build-distributions.yml new file mode 100644 index 000000000..0d4a8f606 --- /dev/null +++ b/.github/workflows/build-distributions.yml @@ -0,0 +1,254 @@ +name: Build Distributions + +# The single owner of the wheel platform matrix, the maturin settings and the distribution smoke +# tests. Distributions builds the wheels for pull requests that touch packaging, Release +# Distributions builds and keeps every distribution for a release pull request, and Publish either +# smoke tests and reuses those distributions or builds them here from the release tag. +on: + workflow_call: + inputs: + ref: + description: "Commit, tag or branch to build; empty builds the triggering commit" + required: false + type: string + default: "" + sdist: + description: "Also build the source distributions" + required: false + type: boolean + default: true + upload: + description: "Upload the distributions and a manifest recording their source commit and tree" + required: false + type: boolean + default: false + prebuilt-run-id: + description: >- + Release Distributions run whose distributions are smoke tested and uploaded instead of + building; its manifest must record the tree of ref. The caller grants actions: read. + required: false + type: string + default: "" + retention-days: + description: "Retention of uploaded artifacts in days; 0 uses the repository default" + required: false + type: number + default: 0 + outputs: + sha: + description: "Commit the distributions were built from" + value: ${{ jobs.source.outputs.sha }} + tree: + description: "Tree of the commit the distributions were built from" + value: ${{ jobs.source.outputs.tree }} + +jobs: + source: + name: Resolve source + runs-on: ubuntu-24.04 + outputs: + sha: ${{ steps.source.outputs.sha }} + tree: ${{ steps.source.outputs.tree }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.ref }} + - name: Pin the source commit + id: source + run: | + sha="$(git rev-parse HEAD)" + tree="$(git rev-parse 'HEAD^{tree}')" + echo "sha=${sha}" >> "${GITHUB_OUTPUT}" + echo "tree=${tree}" >> "${GITHUB_OUTPUT}" + echo "Distributions for commit ${sha} with tree ${tree}" >> "${GITHUB_STEP_SUMMARY}" + - name: Download the prebuilt manifest + if: inputs.prebuilt-run-id != '' + uses: actions/download-artifact@v4 + with: + name: release-manifest + path: ${{ runner.temp }}/prebuilt + run-id: ${{ inputs.prebuilt-run-id }} + github-token: ${{ github.token }} + - name: Require prebuilt distributions from this exact tree + if: inputs.prebuilt-run-id != '' + env: + MANIFEST: ${{ runner.temp }}/prebuilt/release-manifest.json + PREBUILT_RUN_ID: ${{ inputs.prebuilt-run-id }} + TREE: ${{ steps.source.outputs.tree }} + run: | + recorded="$(jq -r '.tree // empty' "${MANIFEST}")" + if [[ "${recorded}" != "${TREE}" ]]; then + echo "Run ${PREBUILT_RUN_ID} built tree ${recorded:-}, not ${TREE}" >&2 + exit 1 + fi + echo "Reusing distributions of run ${PREBUILT_RUN_ID}, built from tree ${TREE}" \ + >> "${GITHUB_STEP_SUMMARY}" + + wheels: + name: Build wheels (${{ matrix.platform.name }}) + needs: source + runs-on: ${{ matrix.platform.runner }} + timeout-minutes: 90 + strategy: + fail-fast: false + matrix: + platform: + - name: linux-x86_64 + runner: ubuntu-24.04 + target: x86_64 + - name: linux-aarch64 + runner: ubuntu-24.04-arm + target: aarch64 + # DuckDB's C++ needs aligned deallocation, available from macOS 10.13. + - name: macos-x86_64 + runner: macos-15-intel + target: x86_64 + macos-target: "10.15" + - name: macos-arm64 + runner: macos-15 + target: aarch64 + macos-target: "11.0" + - name: windows-x86_64 + runner: windows-2025 + target: x86_64 + steps: + - uses: actions/checkout@v4 + if: inputs.prebuilt-run-id == '' + with: + ref: ${{ needs.source.outputs.sha }} + - uses: actions/setup-python@v5 + with: + python-version: "3.12" + # Both wheels compile DuckDB in (the `bundled` feature), so neither needs a system DuckDB. + - name: Set the oldest macOS the wheels support + if: matrix.platform.macos-target + shell: bash + run: echo "MACOSX_DEPLOYMENT_TARGET=${{ matrix.platform.macos-target }}" >> "$GITHUB_ENV" + - uses: PyO3/maturin-action@v1 + if: inputs.prebuilt-run-id == '' + with: + command: build + args: --release --locked --out ../dist + working-directory: python + target: ${{ matrix.platform.target }} + manylinux: "2_28" + - uses: PyO3/maturin-action@v1 + if: inputs.prebuilt-run-id == '' + with: + command: build + args: --release --locked --out ../../dist + working-directory: crates/sqlquack + target: ${{ matrix.platform.target }} + manylinux: "2_28" + - name: Download prebuilt wheels + if: inputs.prebuilt-run-id != '' + uses: actions/download-artifact@v4 + with: + name: dist-wheel-${{ matrix.platform.name }} + path: dist + run-id: ${{ inputs.prebuilt-run-id }} + github-token: ${{ github.token }} + - name: Smoke test the installed wheels as the site's quick start runs them + shell: bash + run: | + python -m venv "${RUNNER_TEMP}/wheel-smoke" + if [[ -x "${RUNNER_TEMP}/wheel-smoke/Scripts/python.exe" ]]; then + bin="${RUNNER_TEMP}/wheel-smoke/Scripts" + else + bin="${RUNNER_TEMP}/wheel-smoke/bin" + fi + # Only the wheels just built: sqlquack-cli must resolve from dist, never from an index. + "${bin}/python" -m pip install --no-index --find-links dist sqlquack + cd "${RUNNER_TEMP}" + "${bin}/sqlquack" --version + "${bin}/python" -c "import sqlquack.api" + set +e + check="$(echo "SELECT 1 QUALIFY TRUE" | "${bin}/sqlquack" check 2>&1)" + status=$? + set -e + echo "${check}" + if [[ ${status} -ne 1 ]] || ! grep -q 'error\[SQ0203\]' <<< "${check}"; then + echo "check should refuse QUALIFY without a window function with SQ0203 and exit 1" >&2 + exit 1 + fi + converted="$(echo "SELECT 1 AS total" | "${bin}/sqlquack" convert --builtin-policy)" + echo "${converted}" + grep -qx 'SELECT CAST(1 AS DECIMAL(1,0)) AS "TOTAL"' <<< "${converted}" + - uses: actions/upload-artifact@v4 + if: inputs.upload + with: + name: dist-wheel-${{ matrix.platform.name }} + path: dist + if-no-files-found: error + retention-days: ${{ inputs.retention-days }} + + sdist: + name: Build sdists + needs: source + if: inputs.sdist + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + if: inputs.prebuilt-run-id == '' + with: + ref: ${{ needs.source.outputs.sha }} + - uses: PyO3/maturin-action@v1 + if: inputs.prebuilt-run-id == '' + with: + command: sdist + args: --out ../dist + working-directory: python + - uses: PyO3/maturin-action@v1 + if: inputs.prebuilt-run-id == '' + with: + command: sdist + args: --out ../../dist + working-directory: crates/sqlquack + - name: Download prebuilt source distributions + if: inputs.prebuilt-run-id != '' + uses: actions/download-artifact@v4 + with: + name: dist-sdist + path: dist + run-id: ${{ inputs.prebuilt-run-id }} + github-token: ${{ github.token }} + - name: Inspect source distribution contents + run: | + for archive in dist/*.tar.gz; do + tar -tzf "$archive" > "${RUNNER_TEMP}/archive-contents.txt" + if grep -E '(__pycache__/|\.pyc$|\.tmp$)' "${RUNNER_TEMP}/archive-contents.txt"; then + echo "Source distribution contains generated or temporary script files" + exit 1 + fi + done + - uses: actions/upload-artifact@v4 + if: inputs.upload + with: + name: dist-sdist + path: dist + if-no-files-found: error + retention-days: ${{ inputs.retention-days }} + + manifest: + name: Record distribution source + needs: [source, wheels, sdist] + if: >- + ${{ !cancelled() && inputs.upload && needs.wheels.result == 'success' + && (needs.sdist.result == 'success' || needs.sdist.result == 'skipped') }} + runs-on: ubuntu-24.04 + steps: + - name: Write the manifest + env: + SHA: ${{ needs.source.outputs.sha }} + TREE: ${{ needs.source.outputs.tree }} + run: | + jq -n --arg sha "${SHA}" --arg tree "${TREE}" --arg run_id "${GITHUB_RUN_ID}" \ + '{sha: $sha, tree: $tree, run_id: $run_id}' \ + > "${RUNNER_TEMP}/release-manifest.json" + cat "${RUNNER_TEMP}/release-manifest.json" + - uses: actions/upload-artifact@v4 + with: + name: release-manifest + path: ${{ runner.temp }}/release-manifest.json + if-no-files-found: error + retention-days: ${{ inputs.retention-days }} diff --git a/.github/workflows/distributions.yml b/.github/workflows/distributions.yml new file mode 100644 index 000000000..d4db4a2ca --- /dev/null +++ b/.github/workflows/distributions.yml @@ -0,0 +1,27 @@ +name: Distributions + +# Builds and smoke tests every wheel and sdist when a pull request changes what goes into them. +on: + pull_request: + paths: + - "python/**" + - "crates/sqlquack/pyproject.toml" + - "crates/sqlquack-python/**" + - "Cargo.toml" + - "Cargo.lock" + - "rust-toolchain.toml" + - ".github/workflows/build-distributions.yml" + - ".github/workflows/distributions.yml" + workflow_dispatch: + +permissions: + contents: read + +concurrency: + group: distributions-${{ github.ref }} + cancel-in-progress: true + +jobs: + distributions: + name: Distributions + uses: ./.github/workflows/build-distributions.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 000000000..05bd20833 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,147 @@ +name: Publish + +on: + workflow_dispatch: + inputs: + tag: + description: "Release tag to publish, for example v0.52.0" + required: true + type: string + +permissions: + contents: read + +jobs: + release-tag: + name: Resolve release tag + runs-on: ubuntu-24.04 + permissions: + actions: read + contents: read + outputs: + tag: ${{ steps.release-tag.outputs.tag }} + tree: ${{ steps.prebuilt.outputs.tree }} + prebuilt-run-id: ${{ steps.prebuilt.outputs.run_id }} + steps: + - name: Resolve release tag + id: release-tag + env: + TAG: ${{ inputs.tag }} + run: | + case "${TAG}" in + v0*) ;; + *) + echo "Refusing to publish tag '${TAG}'. PyPI publishing is limited to v0* tags." + exit 1 + ;; + esac + + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@v4 + with: + ref: ${{ steps.release-tag.outputs.tag }} + + # Release Distributions builds every distribution on the release pull request. Its run is + # reused only when it succeeded and its commit has exactly the release tag's tree, so the + # reused distributions come from the same sources and the same reviewed build workflow. + - name: Find distributions built from the release tree + id: prebuilt + env: + GH_TOKEN: ${{ github.token }} + run: | + tree="$(git rev-parse 'HEAD^{tree}')" + echo "tree=${tree}" >> "${GITHUB_OUTPUT}" + runs="$(gh api \ + "repos/${GITHUB_REPOSITORY}/actions/workflows/release-distributions.yml/runs?event=workflow_dispatch&status=success&per_page=50" \ + --jq '.workflow_runs[] + | select(.conclusion == "success" and .event == "workflow_dispatch") + | "\(.id) \(.head_sha)"')" || runs="" + run_id="" + while read -r candidate head_sha; do + [[ -n "${candidate}" ]] || continue + candidate_tree="$(gh api "repos/${GITHUB_REPOSITORY}/git/commits/${head_sha}" \ + --jq .tree.sha 2>/dev/null)" || continue + [[ "${candidate_tree}" == "${tree}" ]] || continue + artifacts="$(gh api \ + "repos/${GITHUB_REPOSITORY}/actions/runs/${candidate}/artifacts?per_page=100")" \ + || continue + if ! jq -e '([.artifacts[] | select(.expired)] | length == 0) + and ([.artifacts[].name] | index("release-manifest") and index("dist-sdist"))' \ + <<< "${artifacts}" > /dev/null; then + echo "Run ${candidate} built tree ${tree}, but its artifacts are incomplete or expired" + continue + fi + run_id="${candidate}" + break + done <<< "${runs}" + echo "run_id=${run_id}" >> "${GITHUB_OUTPUT}" + if [[ -n "${run_id}" ]]; then + echo "Publishing distributions prebuilt by run ${run_id} from tree ${tree}" \ + | tee -a "${GITHUB_STEP_SUMMARY}" + else + echo "No prebuilt distributions for tree ${tree}; building from the tag" \ + | tee -a "${GITHUB_STEP_SUMMARY}" + fi + + distributions: + name: Distributions + needs: release-tag + permissions: + actions: read + contents: read + uses: ./.github/workflows/build-distributions.yml + with: + ref: ${{ needs.release-tag.outputs.tag }} + upload: true + prebuilt-run-id: ${{ needs.release-tag.outputs.prebuilt-run-id }} + + pypi: + name: Publish to PyPI + needs: + - release-tag + - distributions + runs-on: ubuntu-24.04 + environment: pypi + permissions: + contents: read + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + pattern: dist-* + path: dist + merge-multiple: true + - name: Check distributions match the release tag + env: + TAG: ${{ needs.release-tag.outputs.tag }} + TREE: ${{ needs.release-tag.outputs.tree }} + BUILT_TREE: ${{ needs.distributions.outputs.tree }} + run: | + if [[ -z "${TREE}" || "${BUILT_TREE}" != "${TREE}" ]]; then + echo "Distributions were built from tree ${BUILT_TREE:-}, not ${TREE:-}" >&2 + exit 1 + fi + version="${TAG#v}" + shopt -s nullglob + files=(dist/*) + if (( ${#files[@]} == 0 )); then + echo "No distributions were downloaded" >&2 + exit 1 + fi + for file in "${files[@]}"; do + name="$(basename "${file}")" + case "${name}" in + sqlquack-"${version}"-*.whl|sqlquack-"${version}".tar.gz) ;; + sqlquack_cli-"${version}"-*.whl|sqlquack_cli-"${version}".tar.gz) ;; + *) + echo "Unexpected distribution ${name} for ${TAG}" >&2 + exit 1 + ;; + esac + done + printf '%s\n' "${files[@]}" + - name: Publish distributions + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist diff --git a/.github/workflows/release-distributions.yml b/.github/workflows/release-distributions.yml new file mode 100644 index 000000000..ee59caca3 --- /dev/null +++ b/.github/workflows/release-distributions.yml @@ -0,0 +1,22 @@ +name: Release Distributions + +# Release Please dispatches this for each release pull request. Publish uploads these +# distributions once the release is tagged instead of rebuilding them, but only from a successful +# run of this workflow whose commit has exactly the release tag's tree; otherwise it builds from +# the tag. +on: + workflow_dispatch: + +permissions: + contents: read + +jobs: + distributions: + name: Distributions + uses: ./.github/workflows/build-distributions.yml + with: + # Pin the dispatched commit so every job builds the tree this run is matched on. + ref: ${{ github.sha }} + upload: true + # Comfortably longer than a release pull request stays open before it is merged and published. + retention-days: 30 diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 000000000..3bbd17caa --- /dev/null +++ b/.github/workflows/release-please.yml @@ -0,0 +1,53 @@ +name: Release Please + +# Opens the release pull request from Conventional Commits on main and, once it merges, tags the +# release and dispatches Publish. Nothing runs until the repository variable SQLQUACK_RELEASES is +# set to "enabled", so no release pull request, tag or upload can happen before launch. +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + actions: write + contents: write + pull-requests: write + +concurrency: + group: release-please + cancel-in-progress: false + +jobs: + release-please: + if: vars.SQLQUACK_RELEASES == 'enabled' + runs-on: ubuntu-24.04 + steps: + - uses: googleapis/release-please-action@v4 + id: release + with: + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + + - name: Publish the created release + if: steps.release.outputs.release_created == 'true' + env: + GH_TOKEN: ${{ github.token }} + RELEASE_TAG: ${{ steps.release.outputs.tag_name }} + run: | + gh workflow run publish.yml --repo "${GITHUB_REPOSITORY}" --ref main \ + -f "tag=${RELEASE_TAG}" + + - name: Build the release pull request's distributions + if: steps.release.outputs.prs_created == 'true' + env: + GH_TOKEN: ${{ github.token }} + RELEASE_PRS: ${{ steps.release.outputs.prs }} + run: | + release_branch="$(jq -r '.[0].headBranchName // empty' <<< "${RELEASE_PRS}")" + if [[ -z "${release_branch}" ]]; then + echo "Release Please reported a created pull request without a head branch" >&2 + exit 1 + fi + gh workflow run release-distributions.yml --repo "${GITHUB_REPOSITORY}" \ + --ref "${release_branch}" diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 000000000..2be9c43c8 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1,3 @@ +{ + ".": "0.2.0" +} diff --git a/Cargo.lock b/Cargo.lock index 149ecdafe..92eaa66a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -352,6 +352,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86e055fa6e3e40ad6187ba25b6855eeb635d5271f8e0f0e1e9a5826b8d75bea0" dependencies = [ "find-msvc-tools", + "jobserver", + "libc", "shlex", ] @@ -778,6 +780,16 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" +[[package]] +name = "jobserver" +version = "0.1.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" +dependencies = [ + "getrandom 0.4.3", + "libc", +] + [[package]] name = "js-sys" version = "0.3.106" @@ -858,6 +870,7 @@ version = "1.20000.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac1dcdcfde48e11bbd46112ed3b0423acd8c644413b3891e7be8104edce7fdda" dependencies = [ + "cc", "flate2", "pkg-config", "serde", diff --git a/Makefile b/Makefile index 076be54a2..f1c7a8a9c 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ PYTHON_TYPED := scripts tests/unit/scripts python/src $(PYTHON_API_TESTS) PYTHON_TESTS := tests/unit/scripts $(PYTHON_API_TESTS) endif -.PHONY: format rust-lint python-check fensu syntax-coverage gate-build evidence-guard polyglot-guard generate-cases generated-cases generate-referee-cases referee-cases referee-pending translation-results check-ci check-merge test test-rust test-python python-module python-api python-wheel verify-recorded polyglot-duckshop census-duckshop fuzz-smoke gate gate-parallel census duckshop-compiled duckshop-measure +.PHONY: distribution-notices format rust-lint python-check fensu syntax-coverage gate-build evidence-guard polyglot-guard generate-cases generated-cases generate-referee-cases referee-cases referee-pending translation-results check-ci check-merge test test-rust test-python python-module python-api python-wheel verify-recorded polyglot-duckshop census-duckshop fuzz-smoke gate gate-parallel census duckshop-compiled duckshop-measure format: cargo fmt --all @@ -92,7 +92,15 @@ referee-pending: uv run python -m scripts.write_referee_pending $(REFEREE_ARGS) # The static gate, the first step of `gate`, and the Python API's tests. -check-ci: rust-lint python-check fensu syntax-coverage evidence-guard polyglot-guard generated-cases referee-cases python-api +check-ci: rust-lint python-check fensu syntax-coverage evidence-guard polyglot-guard generated-cases referee-cases python-api distribution-notices + +# Each distribution ships the licence and third-party notices; its copies must match the root files. +distribution-notices: + @for dir in python crates/sqlquack; do \ + for file in LICENSE THIRD_PARTY_NOTICES; do \ + cmp -s "$$file" "$$dir/$$file" || { echo "$$dir/$$file differs from $$file; copy it again"; exit 1; }; \ + done; \ + done # The gate builds everything it runs once, in `gate-build`: one profile, GATE_PROFILE (Cargo.toml's # `gate`), and one feature set, GATE_FEATURES. Cargo unifies features per invocation, so a build of a diff --git a/THIRD_PARTY_NOTICES b/THIRD_PARTY_NOTICES index 7c515c781..22c1a42d7 100644 --- a/THIRD_PARTY_NOTICES +++ b/THIRD_PARTY_NOTICES @@ -142,3 +142,28 @@ NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPO NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +DuckDB +------ + +The sqlquack and sqlquack-cli wheels compile in DuckDB, from the sources the libduckdb-sys crate +ships. DuckDB is distributed under the following licence: + +MIT License + +Copyright 2021-2026 Stichting DuckDB Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/crates/sqlquack-duckdb/Cargo.toml b/crates/sqlquack-duckdb/Cargo.toml index 64dd6de09..03948fb15 100644 --- a/crates/sqlquack-duckdb/Cargo.toml +++ b/crates/sqlquack-duckdb/Cargo.toml @@ -14,6 +14,8 @@ rust-version.workspace = true [features] default = ["engine"] engine = ["dep:duckdb"] +# Compiles DuckDB into the binary, for distributions that must not need a system DuckDB. +bundled = ["engine", "duckdb/bundled"] [dependencies] duckdb = { workspace = true, optional = true } diff --git a/crates/sqlquack-python/Cargo.toml b/crates/sqlquack-python/Cargo.toml index cb5509644..328a9b12d 100644 --- a/crates/sqlquack-python/Cargo.toml +++ b/crates/sqlquack-python/Cargo.toml @@ -18,6 +18,8 @@ doctest = false [features] # Set when building the module the interpreter loads, so it does not link libpython itself. extension-module = ["pyo3/extension-module"] +# DuckDB compiled in, as the sqlquack wheel ships it. +bundled = ["sqlquack/bundled"] [dependencies] pyo3.workspace = true diff --git a/crates/sqlquack-python/build.rs b/crates/sqlquack-python/build.rs index 2735b23f4..5b0f027f5 100644 --- a/crates/sqlquack-python/build.rs +++ b/crates/sqlquack-python/build.rs @@ -1,9 +1,16 @@ //! The module finds the DuckDB library copied next to it, in its package. fn main() { - let origin = match std::env::var("CARGO_CFG_TARGET_OS").as_deref() { + let target_os = std::env::var("CARGO_CFG_TARGET_OS"); + let origin = match target_os.as_deref() { Ok("macos") => "@loader_path", _ => "$ORIGIN", }; println!("cargo:rustc-link-arg-cdylib=-Wl,-rpath,{origin}"); + // With DuckDB compiled in, libduckdb-sys places the archive that calls DuckDB's static extension + // loader after the one that defines it. GNU ld does not look back, so the module would load with + // the loader unresolved; marking it undefined up front keeps it. + if std::env::var_os("CARGO_FEATURE_BUNDLED").is_some() && target_os.as_deref() == Ok("linux") { + println!("cargo:rustc-link-arg=-Wl,--undefined=duckdb_register_static_extensions"); + } } diff --git a/crates/sqlquack/Cargo.toml b/crates/sqlquack/Cargo.toml index 6089ff83f..2b77c7fa8 100644 --- a/crates/sqlquack/Cargo.toml +++ b/crates/sqlquack/Cargo.toml @@ -16,6 +16,10 @@ rust-version.workspace = true name = "sqlquack" path = "src/bin/sqlquack.rs" +[features] +# DuckDB compiled in, as the sqlquack-cli wheel ships it. +bundled = ["sqlquack-duckdb/bundled"] + [dependencies] clap.workspace = true rayon.workspace = true diff --git a/crates/sqlquack/LICENSE b/crates/sqlquack/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/crates/sqlquack/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/crates/sqlquack/THIRD_PARTY_NOTICES b/crates/sqlquack/THIRD_PARTY_NOTICES new file mode 100644 index 000000000..22c1a42d7 --- /dev/null +++ b/crates/sqlquack/THIRD_PARTY_NOTICES @@ -0,0 +1,169 @@ +Third-party notices +=================== + +sqlglot test suite +------------------ + +Case files under cases/imported/ whose `origin` field names sqlglot are derived from the test +suite of sqlglot (https://github.com/tobymao/sqlglot), file tests/dialects/test_snowflake.py. +Only the Snowflake SQL of each fixture is used as case input; SQLQuack records the expected +answer from Snowflake itself. sqlglot's expected DuckDB output is kept in the `sqlglot_duckdb` +field as reference side data only: it is never asserted, does not count toward verification and +is not part of the case hash. + +The exact-check corpus corpora/polyglot-check/sqlglot.json holds the SQL of sqlglot's test +fixtures at v30.14.0 (tests/fixtures/identity.sql, tests/test_parser.py and tests/dialects/), +as extracted by polyglot's fixture tooling. polyglot, below, is itself inspired by sqlglot and +ships sqlglot's licence. corpora/polyglot-check/sqlglot_postgres.json holds the SQL of +tests/dialects/test_postgres.py at the same version, and corpora/polyglot-check/sqlglot_sqlite.json +that of tests/dialects/test_sqlite.py. + +The referee corpus referee/corpora/sqlglot.json holds the query statements passed to +`validate_identity` and `validate_all` in tests/dialects/test_snowflake.py at the sqlglot commit +its `origin` field names. Only Snowflake's syntax verdict on each statement is recorded. + +sqlglot is distributed under the following licence: + +MIT License + +Copyright (c) 2026 Toby Mao + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +polyglot +-------- + +Parts of SQLQuack's tokenizer and parser, in crates/sqlquack-syntax and +crates/sqlquack-syntax-derive, are derived from polyglot (https://github.com/tobilg/polyglot), +as forked at https://github.com/sqlstack-io/polyglot. The exact-check corpus +corpora/polyglot-check/polyglot_tests.json holds the SQL inputs of polyglot's tests. +SQLQuack's DuckDB result-type rules, in crates/sqlquack-semantics/src/lineage/_helpers/duckdb_typing.rs +and duckdb_types.rs, are ported from polyglot's engine type rules, and the fixture +crates/sqlquack-semantics/src/lineage/tests/fixtures/duckdb_engine_types.json is polyglot's +tests/fixtures/engine_types/duckdb.json, the result types DuckDB bound for its synthetic cases. + +polyglot is distributed under the following licence: + +MIT License + +Copyright (c) 2026 TobiLG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +PostgreSQL regression tests +--------------------------- + +corpora/polyglot-check/postgres_regress.json holds the SQL statements of PostgreSQL 17.2's +regression tests (src/test/regress/sql at tag REL_17_2), split at top-level semicolons, with psql +meta-commands dropped and a few statements left out. They are distributed under the PostgreSQL +License: + +PostgreSQL Database Management System +(formerly known as Postgres, then as Postgres95) + +Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group + +Portions Copyright (c) 1994, The Regents of the University of California + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without a written agreement +is hereby granted, provided that the above copyright notice and this +paragraph and the following two paragraphs appear in all copies. + +IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING +LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO +PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + + +sqllogictest +------------ + +corpora/polyglot-check/sqllogictest.json holds SQL statements from sqllogictest +(https://www.sqlite.org/sqllogictest), test/**/*.test: every hand-written statement under +test/evidence/ that SQLite runs and a seeded random sample of the others. Its author offers it under +any of the GNU General Public License, the BSD License, the MIT License or CC0, and requires no +attribution; SQLQuack uses it under the MIT License: + +Copyright (c) 2008 D. Richard Hipp + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +DuckDB +------ + +The sqlquack and sqlquack-cli wheels compile in DuckDB, from the sources the libduckdb-sys crate +ships. DuckDB is distributed under the following licence: + +MIT License + +Copyright 2021-2026 Stichting DuckDB Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/crates/sqlquack/build.rs b/crates/sqlquack/build.rs new file mode 100644 index 000000000..1c893641d --- /dev/null +++ b/crates/sqlquack/build.rs @@ -0,0 +1,11 @@ +//! With DuckDB compiled in, Linux links must keep DuckDB's static extension loader. + +fn main() { + // libduckdb-sys places the archive that calls the loader after the one that defines it, and GNU + // ld does not look back, so the link fails. Marking the loader undefined up front keeps it. + if std::env::var_os("CARGO_FEATURE_BUNDLED").is_some() + && std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("linux") + { + println!("cargo:rustc-link-arg=-Wl,--undefined=duckdb_register_static_extensions"); + } +} diff --git a/crates/sqlquack/pyproject.toml b/crates/sqlquack/pyproject.toml new file mode 100644 index 000000000..80a048495 --- /dev/null +++ b/crates/sqlquack/pyproject.toml @@ -0,0 +1,17 @@ +[build-system] +requires = ["maturin>=1.9,<2"] +build-backend = "maturin" + +[project] +name = "sqlquack-cli" +dynamic = ["version"] +description = "The native sqlquack executable: check Snowflake SQL and convert it into DuckDB SQL." +readme = "../../README.md" +requires-python = ">=3.12" +license = "Apache-2.0 AND MIT" +# Copies of the repository root files; `make distribution-notices` checks they match. +license-files = ["LICENSE", "THIRD_PARTY_NOTICES"] + +[tool.maturin] +bindings = "bin" +features = ["bundled"] diff --git a/fensu.toml b/fensu.toml index adf85af31..7c3f0a0a8 100644 --- a/fensu.toml +++ b/fensu.toml @@ -13,6 +13,21 @@ tooling = ["crates/sqlquack-polyglot-check"] rule_packs = ["rust"] select = ["FPRS"] +# A crate that is also a Python distribution keeps its pyproject.toml and shipped notices beside Cargo.toml. +[targets.rust.rule_options.FPRSR311] +allowed_entries = [ + "Cargo.toml", + "build.rs", + "src/", + "tests/", + "benches/", + "examples/", + "README*", + "LICENSE*", + "THIRD_PARTY_NOTICES", + "pyproject.toml", +] + # Layer: only the command-line crates may depend on the conversion rules. [targets.rust_rules_layer] analyzer = "rust" diff --git a/python/LICENSE b/python/LICENSE new file mode 100644 index 000000000..261eeb9e9 --- /dev/null +++ b/python/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/python/THIRD_PARTY_NOTICES b/python/THIRD_PARTY_NOTICES new file mode 100644 index 000000000..22c1a42d7 --- /dev/null +++ b/python/THIRD_PARTY_NOTICES @@ -0,0 +1,169 @@ +Third-party notices +=================== + +sqlglot test suite +------------------ + +Case files under cases/imported/ whose `origin` field names sqlglot are derived from the test +suite of sqlglot (https://github.com/tobymao/sqlglot), file tests/dialects/test_snowflake.py. +Only the Snowflake SQL of each fixture is used as case input; SQLQuack records the expected +answer from Snowflake itself. sqlglot's expected DuckDB output is kept in the `sqlglot_duckdb` +field as reference side data only: it is never asserted, does not count toward verification and +is not part of the case hash. + +The exact-check corpus corpora/polyglot-check/sqlglot.json holds the SQL of sqlglot's test +fixtures at v30.14.0 (tests/fixtures/identity.sql, tests/test_parser.py and tests/dialects/), +as extracted by polyglot's fixture tooling. polyglot, below, is itself inspired by sqlglot and +ships sqlglot's licence. corpora/polyglot-check/sqlglot_postgres.json holds the SQL of +tests/dialects/test_postgres.py at the same version, and corpora/polyglot-check/sqlglot_sqlite.json +that of tests/dialects/test_sqlite.py. + +The referee corpus referee/corpora/sqlglot.json holds the query statements passed to +`validate_identity` and `validate_all` in tests/dialects/test_snowflake.py at the sqlglot commit +its `origin` field names. Only Snowflake's syntax verdict on each statement is recorded. + +sqlglot is distributed under the following licence: + +MIT License + +Copyright (c) 2026 Toby Mao + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +polyglot +-------- + +Parts of SQLQuack's tokenizer and parser, in crates/sqlquack-syntax and +crates/sqlquack-syntax-derive, are derived from polyglot (https://github.com/tobilg/polyglot), +as forked at https://github.com/sqlstack-io/polyglot. The exact-check corpus +corpora/polyglot-check/polyglot_tests.json holds the SQL inputs of polyglot's tests. +SQLQuack's DuckDB result-type rules, in crates/sqlquack-semantics/src/lineage/_helpers/duckdb_typing.rs +and duckdb_types.rs, are ported from polyglot's engine type rules, and the fixture +crates/sqlquack-semantics/src/lineage/tests/fixtures/duckdb_engine_types.json is polyglot's +tests/fixtures/engine_types/duckdb.json, the result types DuckDB bound for its synthetic cases. + +polyglot is distributed under the following licence: + +MIT License + +Copyright (c) 2026 TobiLG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + +PostgreSQL regression tests +--------------------------- + +corpora/polyglot-check/postgres_regress.json holds the SQL statements of PostgreSQL 17.2's +regression tests (src/test/regress/sql at tag REL_17_2), split at top-level semicolons, with psql +meta-commands dropped and a few statements left out. They are distributed under the PostgreSQL +License: + +PostgreSQL Database Management System +(formerly known as Postgres, then as Postgres95) + +Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group + +Portions Copyright (c) 1994, The Regents of the University of California + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose, without fee, and without a written agreement +is hereby granted, provided that the above copyright notice and this +paragraph and the following two paragraphs appear in all copies. + +IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR +DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING +LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS +DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS +ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO +PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + + +sqllogictest +------------ + +corpora/polyglot-check/sqllogictest.json holds SQL statements from sqllogictest +(https://www.sqlite.org/sqllogictest), test/**/*.test: every hand-written statement under +test/evidence/ that SQLite runs and a seeded random sample of the others. Its author offers it under +any of the GNU General Public License, the BSD License, the MIT License or CC0, and requires no +attribution; SQLQuack uses it under the MIT License: + +Copyright (c) 2008 D. Richard Hipp + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or +substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT +OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +DuckDB +------ + +The sqlquack and sqlquack-cli wheels compile in DuckDB, from the sources the libduckdb-sys crate +ships. DuckDB is distributed under the following licence: + +MIT License + +Copyright 2021-2026 Stichting DuckDB Foundation + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, +including without limitation the rights to use, copy, modify, merge, publish, distribute, +sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT +NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES +OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/python/pyproject.toml b/python/pyproject.toml index 8339275d0..cab228138 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -6,11 +6,15 @@ build-backend = "maturin" name = "sqlquack" description = "Check Snowflake SQL and convert it into DuckDB SQL, or refuse it with coded diagnostics." requires-python = ">=3.12" -license = "Apache-2.0" +license = "Apache-2.0 AND MIT" +# Copies of the repository root files; `make distribution-notices` checks they match. +license-files = ["LICENSE", "THIRD_PARTY_NOTICES"] dynamic = ["version"] +# The `sqlquack` command, as a native executable built from the same sources. +dependencies = ["sqlquack-cli==0.2.0"] # x-release-please-version [tool.maturin] manifest-path = "../crates/sqlquack-python/Cargo.toml" python-source = "src" module-name = "sqlquack._native" -features = ["extension-module"] +features = ["extension-module", "bundled"] diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 000000000..365027a18 --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,83 @@ +{ + "changelog-sections": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "perf", + "section": "Performance Improvements" + }, + { + "type": "revert", + "section": "Reverts" + }, + { + "type": "deps", + "section": "Dependencies" + }, + { + "type": "docs", + "section": "Documentation", + "hidden": true + }, + { + "type": "style", + "section": "Styles", + "hidden": true + }, + { + "type": "chore", + "section": "Miscellaneous Chores", + "hidden": true + }, + { + "type": "refactor", + "section": "Code Refactoring", + "hidden": true + }, + { + "type": "test", + "section": "Tests", + "hidden": true + }, + { + "type": "build", + "section": "Build System", + "hidden": true + }, + { + "type": "ci", + "section": "Continuous Integration", + "hidden": true + } + ], + "packages": { + ".": { + "release-type": "rust", + "package-name": "sqlquack", + "include-v-in-tag": true, + "include-component-in-tag": false, + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": false, + "extra-files": [ + { + "type": "toml", + "path": "Cargo.toml", + "jsonpath": "$.workspace.package.version" + }, + { + "type": "generic", + "path": "python/pyproject.toml" + } + ], + "exclude-paths": [ + "website" + ] + } + } +}