Skip to content

Commit 126fb77

Browse files
committed
Python support, part 1
1 parent 7ebf8f3 commit 126fb77

15 files changed

+408
-7
lines changed

Cargo.lock

+113-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
resolver = "2"
33
members = [ "greedy_bot",
44
"judge", "gomori_bot_utils",
5-
"gomori", "random_bot", "gomori_tui",
5+
"gomori", "gomori-py", "random_bot", "gomori_tui",
66
]

gomori-py/.gitignore

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/target
2+
3+
# Byte-compiled / optimized / DLL files
4+
__pycache__/
5+
.pytest_cache/
6+
*.py[cod]
7+
8+
# C extensions
9+
*.so
10+
11+
# Distribution / packaging
12+
.Python
13+
.venv/
14+
env/
15+
bin/
16+
build/
17+
develop-eggs/
18+
dist/
19+
eggs/
20+
lib/
21+
lib64/
22+
parts/
23+
sdist/
24+
var/
25+
include/
26+
man/
27+
venv/
28+
*.egg-info/
29+
.installed.cfg
30+
*.egg
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
pip-selfcheck.json
36+
37+
# Unit test / coverage reports
38+
htmlcov/
39+
.tox/
40+
.coverage
41+
.cache
42+
nosetests.xml
43+
coverage.xml
44+
45+
# Translations
46+
*.mo
47+
48+
# Mr Developer
49+
.mr.developer.cfg
50+
.project
51+
.pydevproject
52+
53+
# Rope
54+
.ropeproject
55+
56+
# Django stuff:
57+
*.log
58+
*.pot
59+
60+
.DS_Store
61+
62+
# Sphinx documentation
63+
docs/_build/
64+
65+
# PyCharm
66+
.idea/
67+
68+
# VSCode
69+
.vscode/
70+
71+
# Pyenv
72+
.python-version

gomori-py/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "gomori-py"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
[lib]
8+
name = "gomori"
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
pyo3 = "0.18.1"
13+
gomori = { path = "../gomori" }

gomori-py/pyproject.toml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[build-system]
2+
requires = ["maturin>=0.14,<0.15"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "gomori"
7+
requires-python = ">=3.7"
8+
classifiers = [
9+
"Programming Language :: Rust",
10+
"Programming Language :: Python :: Implementation :: CPython",
11+
"Programming Language :: Python :: Implementation :: PyPy",
12+
]
13+
14+
15+
[tool.maturin]
16+
features = ["pyo3/extension-module"]

gomori-py/src/lib.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use pyo3::prelude::*;
2+
3+
use pyo3::create_exception;
4+
5+
create_exception!(
6+
gomori,
7+
IllegalCardPlayed,
8+
pyo3::exceptions::PyException,
9+
"Describes why the card cannot be played."
10+
);
11+
12+
/// A Python module implemented in Rust.
13+
#[pymodule]
14+
fn gomori(py: Python, m: &PyModule) -> PyResult<()> {
15+
m.add("IllegalCardPlayed", py.get_type::<IllegalCardPlayed>())?;
16+
m.add_class::<::gomori::Card>()?;
17+
m.add_class::<::gomori::Rank>()?;
18+
m.add_class::<::gomori::Suit>()?;
19+
m.add_class::<::gomori::CardsSet>()?;
20+
m.add_class::<::gomori::CompactField>()?;
21+
Ok(())
22+
}

gomori/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
anyhow = "1.0.86"
10+
pyo3 = "0.18.1"
1011
rand = "0.8.5"
1112
serde = { version = "1.0.203", features = ["derive"] }
1213

0 commit comments

Comments
 (0)