meta: initial commit (archival)

This commit is contained in:
2023-12-27 14:33:55 -05:00
commit 5f381f9ad5
8 changed files with 1408 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.history/

66
string_sum/.github/workflows/CI.yml vendored Normal file
View File

@@ -0,0 +1,66 @@
name: CI
on:
push:
pull_request:
jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: messense/maturin-action@v1
with:
manylinux: auto
command: build
args: --release --sdist -o dist
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: messense/maturin-action@v1
with:
command: build
args: --release -o dist
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: messense/maturin-action@v1
with:
command: build
args: --release -o dist --universal2
- name: Upload wheels
uses: actions/upload-artifact@v2
with:
name: wheels
path: dist
release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [ macos, windows, linux ]
steps:
- uses: actions/download-artifact@v2
with:
name: wheels
- name: Publish to PyPI
uses: messense/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --skip-existing *

72
string_sum/.gitignore vendored Normal file
View File

@@ -0,0 +1,72 @@
/target
# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
.venv/
env/
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
include/
man/
venv/
*.egg-info/
.installed.cfg
*.egg
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
pip-selfcheck.json
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Rope
.ropeproject
# Django stuff:
*.log
*.pot
.DS_Store
# Sphinx documentation
docs/_build/
# PyCharm
.idea/
# VSCode
.vscode/
# Pyenv
.python-version

1168
string_sum/Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

17
string_sum/Cargo.toml Normal file
View File

@@ -0,0 +1,17 @@
[package]
name = "string_sum"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "string_sum"
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.16.5", features = ["extension-module"] }
pyo3-asyncio = { version = "0.16", features = ["tokio-runtime"] }
reqwest = { version = "0.11.11" }
serde = { version = "1.0.138", features = ["derive"] }
serde_json = "1.0.82"
tokio = { version = "1.19.2", features = ["full"] }

13
string_sum/pyproject.toml Normal file
View File

@@ -0,0 +1,13 @@
[tool.poetry]
name = "string-sum"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

39
string_sum/src/lib.rs Normal file
View File

@@ -0,0 +1,39 @@
use pyo3::{prelude::*};
#[pyfunction]
fn do_something(
instance: &PyAny,
) -> String {
println!("whoo 2023 year of the gamer");
let word = String::from("bark");
let repetition = instance.call_method("repeat", (word,), None);
let repetition = repetition.unwrap();
let repetition = repetition.extract::<String>();
let repetition = repetition.unwrap();
println!("repetition: {repetition:?}");
repetition
}
#[pyfunction]
fn run_this_function(function: &PyAny, instance: &PyAny) -> usize {
let res = function.call1((instance,));
let x = res.unwrap().extract::<usize>().unwrap();
println!("x: {x}");
x
}
/// A Python module implemented in Rust.
#[pymodule]
fn string_sum(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(do_something, m)?)?;
m.add_function(wrap_pyfunction!(run_this_function, m)?)?;
Ok(())
}

31
string_sum/usage.py Normal file
View File

@@ -0,0 +1,31 @@
import string_sum
class CustomClass:
x: int
def repeat(self, word: str) -> str:
return (word + " ")*self.x
def use_my_custom_class(custom: CustomClass) -> int:
return custom.x
async def main():
print("here we go")
instance = CustomClass()
instance.x = 8
barks = string_sum.do_something(instance)
print(f"{barks=}")
num = string_sum.run_this_function(use_my_custom_class, instance)
print(f"{num=}")
# ret = await get_average_coordinate()
# print(f"{ret=}")
if __name__ == "__main__":
from asyncio import run
run(main())