Skip to content

Commit

Permalink
versions of stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Oct 30, 2024
1 parent e425f02 commit 9b5dca3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
5 changes: 3 additions & 2 deletions pyklang/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Defines the top-level package for PyKlang."""

__version__ = "0.0.1"
from .bindings import get_version

from .bindings import add
# Use the version from the Rust bindings.
__version__ = get_version()
2 changes: 1 addition & 1 deletion pyklang/bindings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# ruff: noqa: E501, F401


def add(a:int,b:int) -> int:
def get_version() -> str:
...

7 changes: 4 additions & 3 deletions pyklang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use pyo3_stub_gen::derive::*;

#[pyfunction]
#[gen_stub_pyfunction]
fn add(a: u64, b: u64) -> u64 {
a + b
fn get_version() -> String {
const VERSION: &str = env!("CARGO_PKG_VERSION");
VERSION.to_string()
}

#[pymodule]
fn bindings(m: &Bound<PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(add, m)?)?;
m.add_function(wrap_pyfunction!(get_version, m)?)?;
Ok(())
}

Expand Down
14 changes: 3 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#!/usr/bin/env python
"""Setup script for the project."""

import glob
import re
import subprocess

Expand All @@ -22,16 +21,11 @@
requirements_dev: list[str] = f.read().splitlines()


with open("pyklang/__init__.py", "r", encoding="utf-8") as fh:
version_re = re.search(r"^__version__ = \"([^\"]*)\"", fh.read(), re.MULTILINE)
assert version_re is not None, "Could not find version in pyklang/__init__.py"
with open("Cargo.toml", "r", encoding="utf-8") as fh:
version_re = re.search(r"^version = \"([^\"]*)\"", fh.read(), re.MULTILINE)
assert version_re is not None, "Could not find version in Cargo.toml"
version: str = version_re.group(1)

package_data = [f"pyklang/{name}" for name in ("py.typed", "requirements.txt", "requirements-dev.txt")]
package_data.append("Cargo.toml")
for ext in ("pyi", "rs", "toml", "so"):
package_data.extend(glob.iglob(f"pyklang/**/*.{ext}", recursive=True))


class RustBuildExt(build_ext):
def run(self) -> None:
Expand Down Expand Up @@ -61,8 +55,6 @@ def run(self) -> None:
python_requires=">=3.11",
install_requires=requirements,
extras_require={"dev": requirements_dev},
include_package_data=True,
package_data={"pyklang": package_data},
packages=find_packages(include=["pyklang"]),
cmdclass={"build_ext": RustBuildExt},
)

0 comments on commit 9b5dca3

Please sign in to comment.