-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init: move templates to a template folder
We make init.rs a bit more readable by moving the templates to a new folder templates/ which we organise by template type (lib, script) and build system.
- Loading branch information
Showing
12 changed files
with
181 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ license_text }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# {{ name }} | ||
|
||
Describe your project here. | ||
|
||
{%- if license %} | ||
* License: {{ license }} | ||
{%- endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# python generated files | ||
__pycache__/ | ||
*.py[oc] | ||
build/ | ||
dist/ | ||
wheels/ | ||
*.egg-info | ||
|
||
{%- if is_rust %} | ||
# Rust | ||
target/ | ||
{%- endif %} | ||
|
||
# venv | ||
.venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def hello() -> str: | ||
return "Hello from {{ name }}!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = {{ name }} | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
[lib] | ||
name = {{ name_safe }} | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
pyo3 = "0.19.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from {{ name_safe }}._lowlevel import hello | ||
|
||
__all__ = ["hello"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const LIB_RS_TEMPLATE: &str = r#"use pyo3::prelude::*; | ||
|
||
/// Prints a message. | ||
#[pyfunction] | ||
fn hello() -> PyResult<String> { | ||
Ok("Hello from {{ name }}!".into()) | ||
} | ||
|
||
/// A Python module implemented in Rust. | ||
#[pymodule] | ||
fn _lowlevel(_py: Python, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(hello, m)?)?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
[project] | ||
name = {{ name }} | ||
version = {{ version }} | ||
description = {{ description }} | ||
{%- if author %} | ||
authors = [ | ||
{ name = {{ author[0] }}, email = {{ author[1] }} } | ||
] | ||
{%- endif %} | ||
{%- if dependencies %} | ||
dependencies = [ | ||
{%- for dependency in dependencies %} | ||
{{ dependency }}, | ||
{%- endfor %} | ||
] | ||
{%- else %} | ||
dependencies = [] | ||
{%- endif %} | ||
{%- if with_readme %} | ||
readme = "README.md" | ||
{%- endif %} | ||
requires-python = {{ requires_python }} | ||
{%- if license %} | ||
license = { text = {{ license }} } | ||
{%- endif %} | ||
{%- if private %} | ||
classifiers = ["Private :: Do Not Upload"] | ||
{%- endif %} | ||
{%- if is_script %} | ||
|
||
[project.scripts] | ||
hello = {{ name_safe ~ ":main"}} | ||
{%- endif %} | ||
|
||
{%- if not is_virtual %} | ||
|
||
[build-system] | ||
{%- if build_system == "hatchling" %} | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
{%- elif build_system == "setuptools" %} | ||
requires = ["setuptools>=61.0"] | ||
build-backend = "setuptools.build_meta" | ||
{%- elif build_system == "flit" %} | ||
requires = ["flit_core>=3.4"] | ||
build-backend = "flit_core.buildapi" | ||
{%- elif build_system == "pdm" %} | ||
requires = ["pdm-backend"] | ||
build-backend = "pdm.backend" | ||
{%- elif build_system == "maturin" %} | ||
requires = ["maturin>=1.2,<2.0"] | ||
build-backend = "maturin" | ||
{%- endif %} | ||
{%- endif %} | ||
[tool.rye] | ||
managed = true | ||
{%- if is_virtual %} | ||
virtual = true | ||
{%- endif %} | ||
{%- if dev_dependencies %} | ||
dev-dependencies = [ | ||
{%- for dependency in dev_dependencies %} | ||
{{ dependency }}, | ||
{%- endfor %} | ||
] | ||
{%- else %} | ||
dev-dependencies = [] | ||
{%- endif %} | ||
{%- if not is_virtual %} | ||
{%- if build_system == "hatchling" %} | ||
[tool.hatch.metadata] | ||
allow-direct-references = true | ||
[tool.hatch.build.targets.wheel] | ||
packages = [{{ "src/" ~ name_safe }}] | ||
{%- elif build_system == "maturin" %} | ||
[tool.maturin] | ||
python-source = "python" | ||
module-name = {{ name_safe ~ "._lowlevel" }} | ||
features = ["pyo3/extension-module"] | ||
{%- endif %} | ||
{%- endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
def main() -> int: | ||
print("Hello from {{ name }}!") | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import {{ name_safe }} | ||
import sys | ||
|
||
sys.exit({{ name_safe }}.main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import json, sys | ||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
|
||
def setup(**kwargs) -> None: | ||
print(json.dumps(kwargs), file=sys.stderr) | ||
|
||
if __name__ == "setuptools": | ||
_setup_proxy_module = sys.modules.pop("setuptools") | ||
_setup_proxy_cwd = sys.path.pop(0) | ||
import setuptools as __setuptools | ||
sys.path.insert(0, _setup_proxy_cwd) | ||
sys.modules["setuptools"] = _setup_proxy_module | ||
def __getattr__(name): | ||
return getattr(__setuptools, name) |