Skip to content

Commit

Permalink
Update build.yaml (#267)
Browse files Browse the repository at this point in the history
* Update build.yaml
* update deps, version bump for rc, support py3.13
* code changes
* actually pipe in python version
* bump version
  • Loading branch information
wseaton authored Oct 23, 2024
1 parent 600cbe8 commit dad457f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
maturin-version: latest
command: build
manylinux: auto
args: --release --sdist -i 3.8 3.9 3.10 3.11 3.12
args: --release --sdist -i 3.8 3.9 3.10 3.11 3.12 3.13
- uses: actions/upload-artifact@v4
with:
name: linux-wheels-${{ matrix.target }}
Expand All @@ -29,7 +29,7 @@ jobs:
runs-on: macos-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
Expand All @@ -50,20 +50,25 @@ jobs:

windows-wheels:
runs-on: windows-latest
strategy:
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Build wheels
run: |
python -m pip install maturin
maturin build --release
- uses: actions/upload-artifact@v4
with:
name: windows-wheels
name: windows-${{ matrix.python-version }}-wheel
path: target/wheels

push:
Expand All @@ -80,17 +85,23 @@ jobs:
- run: mv ./linux-wheels-x86_64/* wheels
- run: mv ./linux-wheels-i686/* wheels
- run: mv ./linux-wheels-aarch64/* wheels
- run: mv ./osx-3.13-wheel/* wheels
- run: mv ./osx-3.12-wheel/* wheels
- run: mv ./osx-3.11-wheel/* wheels
- run: mv ./osx-3.10-wheel/* wheels
- run: mv ./osx-3.9-wheel/* wheels
- run: mv ./osx-3.8-wheel/* wheels
- run: mv ./windows-wheels/* wheels
- run: mv ./windows-3.13-wheel/* wheels
- run: mv ./windows-3.12-wheel/* wheels
- run: mv ./windows-3.11-wheel/* wheels
- run: mv ./windows-3.10-wheel/* wheels
- run: mv ./windows-3.9-wheel/* wheels
- run: mv ./windows-3.8-wheel/* wheels


- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI }}
packages_dir: wheels/
verify_metadata: false
verify_metadata: false
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sqloxide"
version = "0.1.48"
version = "0.1.51"
authors = ["Will Eaton <[email protected]>"]
edition = "2021"

Expand All @@ -9,13 +9,13 @@ name = "sqloxide"
crate-type = ["cdylib"]

[dependencies]
pythonize = "0.21.1"
pythonize = "0.22"
serde = "1.0.171"

[dependencies.pyo3]
version = "0.21.2"
version = "0.22"
features = ["extension-module"]

[dependencies.sqlparser]
version = "0.47.0"
version = "0.51.0"
features = ["serde", "visitor"]
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "sqloxide"
version = "0.1.48"
version = "0.1.51"
repository = "https://github.com/wseaton/sqloxide"
license = "MIT"
description = "Python bindings for sqlparser-rs"
Expand Down
11 changes: 5 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use pythonize::pythonize;
use pyo3::exceptions::PyValueError;
use pyo3::prelude::*;

use pyo3::wrap_pyfunction;
use pythonize::PythonizeError;

use sqlparser::ast::Statement;
Expand All @@ -20,12 +19,12 @@ use visitor::{extract_expressions, extract_relations, mutate_expressions, mutate
/// Available `dialects`: https://github.com/sqlparser-rs/sqlparser-rs/blob/main/src/dialect/mod.rs#L189-L206
#[pyfunction]
#[pyo3(text_signature = "(sql, dialect)")]
fn parse_sql(py: Python, sql: &str, dialect: &str) -> PyResult<PyObject> {
fn parse_sql(py: Python, sql: String, dialect: String) -> PyResult<PyObject> {
let chosen_dialect = dialect_from_str(dialect).unwrap_or_else(|| {
println!("The dialect you chose was not recognized, falling back to 'generic'");
Box::new(GenericDialect {})
});
let parse_result = Parser::parse_sql(&*chosen_dialect, sql);
let parse_result = Parser::parse_sql(&*chosen_dialect, &sql);

let output = match parse_result {
Ok(statements) => pythonize(py, &statements).map_err(|e| {
Expand All @@ -40,13 +39,13 @@ fn parse_sql(py: Python, sql: &str, dialect: &str) -> PyResult<PyObject> {
}
};

Ok(output)
Ok(output.into())
}

/// This utility function allows reconstituing a modified AST back into list of SQL queries.
#[pyfunction]
#[pyo3(text_signature = "(ast)")]
fn restore_ast(_py: Python, ast: &PyAny) -> PyResult<Vec<String>> {
fn restore_ast(_py: Python, ast: &Bound<'_, PyAny>) -> PyResult<Vec<String>> {
let parse_result: Result<Vec<Statement>, PythonizeError> = pythonize::depythonize(ast);

let output = match parse_result {
Expand All @@ -66,7 +65,7 @@ fn restore_ast(_py: Python, ast: &PyAny) -> PyResult<Vec<String>> {
}

#[pymodule]
fn sqloxide(_py: Python, m: &PyModule) -> PyResult<()> {
fn sqloxide(_py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(parse_sql, m)?)?;
m.add_function(wrap_pyfunction!(restore_ast, m)?)?;
// TODO: maybe refactor into seperate module
Expand Down
18 changes: 9 additions & 9 deletions src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sqlparser::ast::{
};

// Refactored function for handling depythonization
fn depythonize_query(parsed_query: &PyAny) -> Result<Vec<Statement>, PyErr> {
fn depythonize_query(parsed_query: &Bound<'_, PyAny>) -> Result<Vec<Statement>, PyErr> {
match pythonize::depythonize(parsed_query) {
Ok(statements) => Ok(statements),
Err(e) => {
Expand All @@ -27,7 +27,7 @@ where
T: Sized + Serialize,
{
match pythonize::pythonize(py, &output) {
Ok(p) => Ok(p),
Ok(p) => Ok(p.into()),
Err(e) => {
let msg = e.to_string();
Err(PyValueError::new_err(format!(
Expand All @@ -39,7 +39,7 @@ where

#[pyfunction]
#[pyo3(text_signature = "(parsed_query)")]
pub fn extract_relations(py: Python, parsed_query: &PyAny) -> PyResult<PyObject> {
pub fn extract_relations(py: Python, parsed_query: &Bound<'_, PyAny>) -> PyResult<PyObject> {
let statements = depythonize_query(parsed_query)?;

let mut relations = Vec::new();
Expand All @@ -55,7 +55,7 @@ pub fn extract_relations(py: Python, parsed_query: &PyAny) -> PyResult<PyObject>

#[pyfunction]
#[pyo3(text_signature = "(parsed_query, func)")]
pub fn mutate_relations(_py: Python, parsed_query: &PyAny, func: &PyAny) -> PyResult<Vec<String>> {
pub fn mutate_relations(_py: Python, parsed_query: &Bound<'_, PyAny>, func: &Bound<'_, PyAny>) -> PyResult<Vec<String>> {
let mut statements = depythonize_query(parsed_query)?;

for statement in &mut statements {
Expand Down Expand Up @@ -85,8 +85,8 @@ pub fn mutate_relations(_py: Python, parsed_query: &PyAny, func: &PyAny) -> PyRe

#[pyfunction]
#[pyo3(text_signature = "(parsed_query, func)")]
pub fn mutate_expressions(py: Python, parsed_query: &PyAny, func: &PyAny) -> PyResult<Vec<String>> {
let mut statements = depythonize_query(parsed_query)?;
pub fn mutate_expressions(py: Python, parsed_query: &Bound<'_, PyAny>, func: &Bound<'_, PyAny>) -> PyResult<Vec<String>> {
let mut statements: Vec<Statement> = depythonize_query(parsed_query)?;

for statement in &mut statements {
visit_expressions_mut(statement, |expr| {
Expand All @@ -110,7 +110,7 @@ pub fn mutate_expressions(py: Python, parsed_query: &PyAny, func: &PyAny) -> PyR
}
};

*expr = match pythonize::depythonize(func_result) {
*expr = match pythonize::depythonize(&func_result) {
Ok(val) => val,
Err(e) => {
let msg = e.to_string();
Expand All @@ -132,8 +132,8 @@ pub fn mutate_expressions(py: Python, parsed_query: &PyAny, func: &PyAny) -> PyR

#[pyfunction]
#[pyo3(text_signature = "(parsed_query)")]
pub fn extract_expressions(py: Python, parsed_query: &PyAny) -> PyResult<PyObject> {
let statements = depythonize_query(parsed_query)?;
pub fn extract_expressions(py: Python, parsed_query: &Bound<'_, PyAny>) -> PyResult<PyObject> {
let statements: Vec<Statement> = depythonize_query(parsed_query)?;

let mut expressions = Vec::new();
for statement in statements {
Expand Down

0 comments on commit dad457f

Please sign in to comment.