Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cargo-generate templates for quickly bootstrapping new projects #702

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ["konstin <[email protected]>"]
name = "maturin"
version = "0.12.2-beta.3"
description = "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages"
exclude = ["test-crates/**/*", "sysconfig/*", "test-data/*", "ci/*", "tests/*"]
exclude = ["test-crates/**/*", "sysconfig/*", "test-data/*", "ci/*", "tests/*", "templates/*"]
homepage = "https://github.com/pyo3/maturin"
readme = "Readme.md"
repository = "https://github.com/pyo3/maturin"
Expand Down
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ bindings = "bin"

[tool.black]
target_version = ['py36']
extend-exclude = '''
# Ignore cargo-generate templates
^/templates
'''
72 changes: 72 additions & 0 deletions templates/.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
20 changes: 20 additions & 0 deletions templates/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "{{project-name}}"
version = "0.1.0"
edition = "2018"
description = "{{description}}"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
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 %}
19 changes: 19 additions & 0 deletions templates/cargo-generate.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[placeholders.mixed_layout]
type = "bool"
prompt = "Use mixed Rust/Python project layout?"
default = false

[placeholders.binding]
type = "string"
prompt = "What binding to use?"
choices = ["pyo3", "rust-cpython", "cffi", "bin"]
default = "pyo3"

[conditional.'mixed_layout != true']
ignore = [ "{{crate_name}}/" ]

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

[conditional.'binding == "bin"']
ignore = [ "src/lib.rs" ]
17 changes: 17 additions & 0 deletions templates/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[build-system]
requires = ["maturin>=0.12,<0.13"]
build-backend = "maturin"

[project]
name = "{{project-name}}"
requires-python = ">=3.6"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
{% if binding == "cffi" -%}
dependencies = ["cffi"]
{%- endif %}
[tool.maturin]
bindings = "{{binding}}"
17 changes: 17 additions & 0 deletions templates/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +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/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

fn main() {

}
4 changes: 4 additions & 0 deletions templates/{{crate_name}}/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .{{crate_name}} import *


__doc__ = {{crate_name}}.__doc__