From bee5780ca4fc4e63a2155ea2c914c56fc3d438e4 Mon Sep 17 00:00:00 2001 From: messense Date: Wed, 24 Nov 2021 22:19:31 +0800 Subject: [PATCH] Merge pure-rust and mixed templates --- templates/{mixed => }/.gitignore | 0 templates/{mixed => }/Cargo.toml | 0 templates/{pure-rust => }/cargo-generate.toml | 8 +++ templates/mixed/cargo-generate.toml | 5 -- templates/pure-rust/.gitignore | 72 ------------------- templates/pure-rust/Cargo.toml | 20 ------ templates/pure-rust/pyproject.toml | 17 ----- templates/pure-rust/src/lib.rs | 17 ----- templates/{mixed => }/pyproject.toml | 0 templates/{mixed => }/src/lib.rs | 0 templates/{pure-rust => }/src/main.rs | 0 .../{mixed => }/{{crate_name}}/__init__.py | 0 12 files changed, 8 insertions(+), 131 deletions(-) rename templates/{mixed => }/.gitignore (100%) rename templates/{mixed => }/Cargo.toml (100%) rename templates/{pure-rust => }/cargo-generate.toml (59%) delete mode 100644 templates/mixed/cargo-generate.toml delete mode 100644 templates/pure-rust/.gitignore delete mode 100644 templates/pure-rust/Cargo.toml delete mode 100644 templates/pure-rust/pyproject.toml delete mode 100644 templates/pure-rust/src/lib.rs rename templates/{mixed => }/pyproject.toml (100%) rename templates/{mixed => }/src/lib.rs (100%) rename templates/{pure-rust => }/src/main.rs (100%) rename templates/{mixed => }/{{crate_name}}/__init__.py (100%) diff --git a/templates/mixed/.gitignore b/templates/.gitignore similarity index 100% rename from templates/mixed/.gitignore rename to templates/.gitignore diff --git a/templates/mixed/Cargo.toml b/templates/Cargo.toml similarity index 100% rename from templates/mixed/Cargo.toml rename to templates/Cargo.toml diff --git a/templates/pure-rust/cargo-generate.toml b/templates/cargo-generate.toml similarity index 59% rename from templates/pure-rust/cargo-generate.toml rename to templates/cargo-generate.toml index a97dcdc26..22d00065d 100644 --- a/templates/pure-rust/cargo-generate.toml +++ b/templates/cargo-generate.toml @@ -1,9 +1,17 @@ +[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" ] diff --git a/templates/mixed/cargo-generate.toml b/templates/mixed/cargo-generate.toml deleted file mode 100644 index daaf646db..000000000 --- a/templates/mixed/cargo-generate.toml +++ /dev/null @@ -1,5 +0,0 @@ -[placeholders.binding] -type = "string" -prompt = "What binding to use?" -choices = ["pyo3", "rust-cpython", "cffi"] -default = "pyo3" diff --git a/templates/pure-rust/.gitignore b/templates/pure-rust/.gitignore deleted file mode 100644 index c8f044299..000000000 --- a/templates/pure-rust/.gitignore +++ /dev/null @@ -1,72 +0,0 @@ -/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/pure-rust/Cargo.toml b/templates/pure-rust/Cargo.toml deleted file mode 100644 index c977fdf2d..000000000 --- a/templates/pure-rust/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[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/pure-rust/pyproject.toml b/templates/pure-rust/pyproject.toml deleted file mode 100644 index 397439554..000000000 --- a/templates/pure-rust/pyproject.toml +++ /dev/null @@ -1,17 +0,0 @@ -[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/pure-rust/src/lib.rs b/templates/pure-rust/src/lib.rs deleted file mode 100644 index 777ef9dac..000000000 --- a/templates/pure-rust/src/lib.rs +++ /dev/null @@ -1,17 +0,0 @@ -{%- 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/mixed/pyproject.toml b/templates/pyproject.toml similarity index 100% rename from templates/mixed/pyproject.toml rename to templates/pyproject.toml diff --git a/templates/mixed/src/lib.rs b/templates/src/lib.rs similarity index 100% rename from templates/mixed/src/lib.rs rename to templates/src/lib.rs diff --git a/templates/pure-rust/src/main.rs b/templates/src/main.rs similarity index 100% rename from templates/pure-rust/src/main.rs rename to templates/src/main.rs diff --git a/templates/mixed/{{crate_name}}/__init__.py b/templates/{{crate_name}}/__init__.py similarity index 100% rename from templates/mixed/{{crate_name}}/__init__.py rename to templates/{{crate_name}}/__init__.py