diff --git a/Cargo.toml b/Cargo.toml index 4ac63866a..a640d2ac3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ authors = ["konstin "] 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" diff --git a/pyproject.toml b/pyproject.toml index 7f0b5d7d9..eaba11d71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,3 +19,7 @@ bindings = "bin" [tool.black] target_version = ['py36'] +extend-exclude = ''' +# Ignore cargo-generate templates +^/templates +''' diff --git a/templates/.gitignore b/templates/.gitignore new file mode 100644 index 000000000..c8f044299 --- /dev/null +++ b/templates/.gitignore @@ -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 diff --git a/templates/Cargo.toml b/templates/Cargo.toml new file mode 100644 index 000000000..c977fdf2d --- /dev/null +++ b/templates/Cargo.toml @@ -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 %} diff --git a/templates/cargo-generate.toml b/templates/cargo-generate.toml new file mode 100644 index 000000000..22d00065d --- /dev/null +++ b/templates/cargo-generate.toml @@ -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" ] diff --git a/templates/pyproject.toml b/templates/pyproject.toml new file mode 100644 index 000000000..397439554 --- /dev/null +++ b/templates/pyproject.toml @@ -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}}" diff --git a/templates/src/lib.rs b/templates/src/lib.rs new file mode 100644 index 000000000..777ef9dac --- /dev/null +++ b/templates/src/lib.rs @@ -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 %} diff --git a/templates/src/main.rs b/templates/src/main.rs new file mode 100644 index 000000000..3033f6266 --- /dev/null +++ b/templates/src/main.rs @@ -0,0 +1,4 @@ + +fn main() { + +} diff --git a/templates/{{crate_name}}/__init__.py b/templates/{{crate_name}}/__init__.py new file mode 100644 index 000000000..374627e07 --- /dev/null +++ b/templates/{{crate_name}}/__init__.py @@ -0,0 +1,4 @@ +from .{{crate_name}} import * + + +__doc__ = {{crate_name}}.__doc__