Skip to content

Commit

Permalink
Let users choose binding mode
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Nov 24, 2021
1 parent 6cc1fe2 commit 8ce6a0c
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 0 deletions.
72 changes: 72 additions & 0 deletions templates/mixed/.gitignore
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions templates/mixed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ name = "{{crate_name}}"
crate-type = ["cdylib"]

[dependencies]
{% case binding -%}
{%- when "pyo3" -%}
pyo3 = { version = "0.15.1", features = ["extension-module"] }
{%- when "rust-cpython" -%}
cpython = { version = "0.7.0", features = ["extension-module"] }
{%- else -%}
{%- endcase %}
5 changes: 5 additions & 0 deletions templates/mixed/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[placeholders.binding]
type = "string"
prompt = "What binding to use?"
choices = ["pyo3", "rust-cpython", "cffi"]
default = "pyo3"
5 changes: 5 additions & 0 deletions templates/mixed/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
{% if binding == "cffi" -%}
dependencies = ["cffi"]
{%- endif %}
[tool.maturin]
bindings = "{{binding}}"
11 changes: 11 additions & 0 deletions templates/mixed/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{%- case binding -%}
{%- when "pyo3" -%}
use pyo3::prelude::*;

#[pymodule]
fn {{crate_name}}(_py: Python, m: &PyModule) -> PyResult<()> {
Ok(())
}
{%- when "rust-cpython" -%}
use cpython::py_module_initializer;

py_module_initializer!({{crate_name}}, |py, m| {
m.add(py, "__doc__", "Module documentation string")?;
Ok(())
});
{%- else -%}
{% endcase %}
72 changes: 72 additions & 0 deletions templates/pure-rust/.gitignore
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions templates/pure-rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ name = "{{crate_name}}"
crate-type = ["cdylib"]

[dependencies]
{% case binding -%}
{%- when "pyo3" -%}
pyo3 = { version = "0.15.1", features = ["extension-module"] }
{%- when "rust-cpython" -%}
cpython = { version = "0.7.0", features = ["extension-module"] }
{%- else -%}
{%- endcase %}
11 changes: 11 additions & 0 deletions templates/pure-rust/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[placeholders.binding]
type = "string"
prompt = "What binding to use?"
choices = ["pyo3", "rust-cpython", "cffi", "bin"]
default = "pyo3"

[conditional.'binding != "bin"']
ignore = [ "src/main.rs" ]

[conditional.'binding == "bin"']
ignore = [ "src/lib.rs" ]
5 changes: 5 additions & 0 deletions templates/pure-rust/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
{% if binding == "cffi" -%}
dependencies = ["cffi"]
{%- endif %}
[tool.maturin]
bindings = "{{binding}}"
11 changes: 11 additions & 0 deletions templates/pure-rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{%- case binding -%}
{%- when "pyo3" -%}
use pyo3::prelude::*;

#[pymodule]
fn {{crate_name}}(_py: Python, m: &PyModule) -> PyResult<()> {
Ok(())
}
{%- when "rust-cpython" -%}
use cpython::py_module_initializer;

py_module_initializer!({{crate_name}}, |py, m| {
m.add(py, "__doc__", "Module documentation string")?;
Ok(())
});
{%- else -%}
{% endcase %}
4 changes: 4 additions & 0 deletions templates/pure-rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

fn main() {

}

0 comments on commit 8ce6a0c

Please sign in to comment.