started python side

This commit is contained in:
John Lancaster
2025-09-12 18:39:17 -05:00
parent 09582a2efb
commit 470b68cc1a
9 changed files with 173 additions and 3 deletions

1
.python-version Normal file
View File

@@ -0,0 +1 @@
3.12

1
.rustfmt.toml Normal file
View File

@@ -0,0 +1 @@
ignore = ["src/pyo3_server"]

101
Cargo.lock generated
View File

@@ -575,6 +575,12 @@ version = "0.15.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"
[[package]]
name = "heck"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.5.2" version = "0.5.2"
@@ -732,6 +738,12 @@ dependencies = [
"hashbrown 0.15.5", "hashbrown 0.15.5",
] ]
[[package]]
name = "indoc"
version = "2.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd"
[[package]] [[package]]
name = "interpolator" name = "interpolator"
version = "0.5.0" version = "0.5.0"
@@ -1006,6 +1018,15 @@ version = "2.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0"
[[package]]
name = "memoffset"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "minicov" name = "minicov"
version = "0.3.7" version = "0.3.7"
@@ -1133,6 +1154,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "portable-atomic"
version = "1.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
[[package]] [[package]]
name = "potential_utf" name = "potential_utf"
version = "0.1.3" version = "0.1.3"
@@ -1217,11 +1244,73 @@ dependencies = [
"leptos_meta", "leptos_meta",
"leptos_router", "leptos_router",
"log", "log",
"pyo3",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-test", "wasm-bindgen-test",
"web-sys", "web-sys",
] ]
[[package]]
name = "pyo3"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ba0117f4212101ee6544044dae45abe1083d30ce7b29c4b5cbdfa2354e07383"
dependencies = [
"indoc",
"libc",
"memoffset",
"once_cell",
"portable-atomic",
"pyo3-build-config",
"pyo3-ffi",
"pyo3-macros",
"unindent",
]
[[package]]
name = "pyo3-build-config"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fc6ddaf24947d12a9aa31ac65431fb1b851b8f4365426e182901eabfb87df5f"
dependencies = [
"target-lexicon",
]
[[package]]
name = "pyo3-ffi"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "025474d3928738efb38ac36d4744a74a400c901c7596199e20e45d98eb194105"
dependencies = [
"libc",
"pyo3-build-config",
]
[[package]]
name = "pyo3-macros"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e64eb489f22fe1c95911b77c44cc41e7c19f3082fc81cce90f657cdc42ffded"
dependencies = [
"proc-macro2",
"pyo3-macros-backend",
"quote",
"syn",
]
[[package]]
name = "pyo3-macros-backend"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "100246c0ecf400b475341b8455a9213344569af29a3c841d29270e53102e0fcf"
dependencies = [
"heck",
"proc-macro2",
"pyo3-build-config",
"quote",
"syn",
]
[[package]] [[package]]
name = "quote" name = "quote"
version = "1.0.40" version = "1.0.40"
@@ -1644,6 +1733,12 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "target-lexicon"
version = "0.13.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df7f62577c25e07834649fc3b39fafdc597c0a3527dc1c60129201ccfcbaa50c"
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.69" version = "1.0.69"
@@ -1778,6 +1873,12 @@ version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
[[package]]
name = "unindent"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.7" version = "2.5.7"

View File

@@ -6,6 +6,15 @@ authors = ["John Lancaster <32917998+jsl12@users.noreply.github.com>"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
# The name of the native library. This is the name which will be used in Python to import the
# library (i.e. `import string_sum`). If you change this, you must also change the name of the
# `#[pymodule]` in `src/lib.rs`.
name = "pyo3_server"
# "cdylib" is necessary to produce a shared library for Python to import from.
crate-type = ["cdylib"]
[dependencies] [dependencies]
leptos = { version = "0.8", features = ["csr"] } leptos = { version = "0.8", features = ["csr"] }
leptos_meta = { version = "0.8" } leptos_meta = { version = "0.8" }
@@ -14,6 +23,8 @@ console_log = "1"
log = "0.4" log = "0.4"
console_error_panic_hook = "0.1" console_error_panic_hook = "0.1"
pyo3 = { version = "0.26.0", features = ["extension-module"] }
# utils # utils
# strum = { version = "0.25", features = ["derive", "strum_macros"] } # strum = { version = "0.25", features = ["derive", "strum_macros"] }
# strum_macros = "0.25" # strum_macros = "0.25"

View File

@@ -10,12 +10,23 @@
# rustc rustfmt cargo # rustc rustfmt cargo
trunk cargo-generate trunk cargo-generate
# LLVM tools for WebAssembly compilation # LLVM tools for WebAssembly compilation
llvm # llvm
lld # lld
]; ];
# https://devenv.sh/languages/ # https://devenv.sh/languages/
languages.rust.enable = true; languages.rust.enable = true;
languages.python = {
enable = true;
package = pkgs.python312;
uv = {
enable = true;
sync = {
enable = true;
allExtras = true;
};
};
};
# https://devenv.sh/processes/ # https://devenv.sh/processes/
# processes.cargo-watch.exec = "cargo-watch"; # processes.cargo-watch.exec = "cargo-watch";
@@ -42,7 +53,9 @@
# https://devenv.sh/tests/ # https://devenv.sh/tests/
enterTest = '' enterTest = ''
echo "Running tests" echo "Running tests"
git --version | grep --color=auto "${pkgs.git.version}" git --version
python --version
rustc --version
''; '';
# https://devenv.sh/git-hooks/ # https://devenv.sh/git-hooks/

26
pyproject.toml Normal file
View File

@@ -0,0 +1,26 @@
[project]
name = "pyo3-server"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
authors = [
{ name = "John Lancaster", email = "32917998+jsl12@users.noreply.github.com" },
]
requires-python = ">=3.12"
dependencies = []
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
[project.scripts]
pyo3-server = "pyo3_server:main"
# [build-system]
# requires = ["uv_build>=0.8.2,<0.9.0"]
# build-backend = "uv_build"
[build-system]
requires = ["maturin>=1,<2"]
build-backend = "maturin"

View File

@@ -1,6 +1,8 @@
use leptos::prelude::*; use leptos::prelude::*;
use py_leptos::App; use py_leptos::App;
use pyo3::prelude::*;
#[pyfunction]
fn main() { fn main() {
// set up logging // set up logging
_ = console_log::init_with_level(log::Level::Debug); _ = console_log::init_with_level(log::Level::Debug);
@@ -12,3 +14,8 @@ fn main() {
} }
}) })
} }
#[pymodule(name = "pyo3_server")]
fn my_extension(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(double, m)?)
}

View File

@@ -0,0 +1,2 @@
def main() -> None:
print("Hello from pyo3-server!")

8
uv.lock generated Normal file
View File

@@ -0,0 +1,8 @@
version = 1
revision = 2
requires-python = ">=3.12"
[[package]]
name = "pyo3-server"
version = "0.1.0"
source = { editable = "." }