Merge pull request #2051 from davidhewitt/generate-examples
examples: add cargo-generate configuration
This commit is contained in:
commit
233a14fa1e
|
@ -10,3 +10,14 @@ Below is a brief description of each of these:
|
||||||
| `maturin-starter` | A template project which is configured to use [`maturin`](https://github.com/PyO3/maturin) for development. |
|
| `maturin-starter` | A template project which is configured to use [`maturin`](https://github.com/PyO3/maturin) for development. |
|
||||||
| `setuptools-rust-starter` | A template project which is configured to use [`setuptools_rust`](https://github.com/PyO3/setuptools-rust/) for development. |
|
| `setuptools-rust-starter` | A template project which is configured to use [`setuptools_rust`](https://github.com/PyO3/setuptools-rust/) for development. |
|
||||||
| `word-count` | A quick performance comparison between word counter implementations written in each of Rust and Python. |
|
| `word-count` | A quick performance comparison between word counter implementations written in each of Rust and Python. |
|
||||||
|
|
||||||
|
## Creating new projects from these examples
|
||||||
|
|
||||||
|
To copy an example, use [`cargo-generate`](https://crates.io/crates/cargo-generate). Follow the commands below, replacing `<example>` with the example to start from:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo install cargo-generate
|
||||||
|
$ cargo generate --git https://github.com/PyO3/pyo3 examples/<example>
|
||||||
|
```
|
||||||
|
|
||||||
|
(`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
authors = ["{{authors}}"]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "decorator"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
|
|
@ -0,0 +1,5 @@
|
||||||
|
variable::set("PYO3_VERSION", "0.15.1");
|
||||||
|
file::rename(".template/Cargo.toml", "Cargo.toml");
|
||||||
|
file::rename(".template/pyproject.toml", "pyproject.toml");
|
||||||
|
file::rename(".template/tox.ini", "tox.ini");
|
||||||
|
file::delete(".template");
|
|
@ -0,0 +1,7 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["maturin>=0.12,<0.13"]
|
||||||
|
build-backend = "maturin"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
version = "0.1.0"
|
|
@ -0,0 +1,7 @@
|
||||||
|
[tox]
|
||||||
|
isolated_build = true
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
description = Run the unit tests under {basepython}
|
||||||
|
deps = -rrequirements-dev.txt
|
||||||
|
commands = pytest {posargs}
|
|
@ -3,17 +3,11 @@ name = "decorator"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "decorator"
|
name = "decorator"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[dependencies.pyo3]
|
[dependencies]
|
||||||
# If you copy this example, you should uncomment this...
|
pyo3 = { path = "../../", features = ["extension-module"] }
|
||||||
# version = "0.15.1"
|
|
||||||
|
|
||||||
# ...and delete this path
|
|
||||||
path = "../.."
|
|
||||||
features = ["extension-module"]
|
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -23,3 +23,14 @@ Alternatively, install tox and run the tests inside an isolated environment:
|
||||||
```shell
|
```shell
|
||||||
tox -e py
|
tox -e py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Copying this example
|
||||||
|
|
||||||
|
Use [`cargo-generate`](https://crates.io/crates/cargo-generate):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo install cargo-generate
|
||||||
|
$ cargo generate --git https://github.com/PyO3/pyo3 examples/decorator
|
||||||
|
```
|
||||||
|
|
||||||
|
(`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
[template]
|
||||||
|
ignore = [".tox"]
|
||||||
|
|
||||||
|
[hooks]
|
||||||
|
pre = [".template/pre-script.rhai"]
|
|
@ -1,3 +1,16 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["maturin>=0.12,<0.13"]
|
requires = ["maturin>=0.12,<0.13"]
|
||||||
build-backend = "maturin"
|
build-backend = "maturin"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "decorator"
|
||||||
|
version = "0.1.0"
|
||||||
|
classifier=[
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Development Status :: 3 - Alpha",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Rust",
|
||||||
|
"Operating System :: POSIX",
|
||||||
|
"Operating System :: MacOS :: MacOS X",
|
||||||
|
]
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
authors = ["{{authors}}"]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "maturin_starter"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
|
|
@ -0,0 +1,5 @@
|
||||||
|
variable::set("PYO3_VERSION", "0.15.1");
|
||||||
|
file::rename(".template/Cargo.toml", "Cargo.toml");
|
||||||
|
file::rename(".template/pyproject.toml", "pyproject.toml");
|
||||||
|
file::rename(".template/tox.ini", "tox.ini");
|
||||||
|
file::delete(".template");
|
|
@ -0,0 +1,7 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["maturin>=0.12,<0.13"]
|
||||||
|
build-backend = "maturin"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
version = "0.1.0"
|
|
@ -0,0 +1,7 @@
|
||||||
|
[tox]
|
||||||
|
isolated_build = true
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
description = Run the unit tests under {basepython}
|
||||||
|
deps = -rrequirements-dev.txt
|
||||||
|
commands = pytest {posargs}
|
|
@ -1,29 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["PyO3 Authors"]
|
|
||||||
name = "maturin-starter"
|
name = "maturin-starter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "An example project to get started using PyO3 with maturin"
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
|
|
||||||
[dependencies.pyo3]
|
|
||||||
path = "../../"
|
|
||||||
features = ["extension-module"]
|
|
||||||
|
|
||||||
[workspace]
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "maturin_starter"
|
name = "maturin_starter"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[package.metadata.maturin]
|
[dependencies]
|
||||||
classifier=[
|
pyo3 = { path = "../../", features = ["extension-module"] }
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Development Status :: 3 - Alpha",
|
[workspace]
|
||||||
"Intended Audience :: Developers",
|
|
||||||
"Programming Language :: Python",
|
|
||||||
"Programming Language :: Rust",
|
|
||||||
"Operating System :: POSIX",
|
|
||||||
"Operating System :: MacOS :: MacOS X",
|
|
||||||
]
|
|
||||||
|
|
|
@ -22,3 +22,14 @@ Alternatively, install tox and run the tests inside an isolated environment:
|
||||||
```shell
|
```shell
|
||||||
tox -e py
|
tox -e py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Copying this example
|
||||||
|
|
||||||
|
Use [`cargo-generate`](https://crates.io/crates/cargo-generate):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo install cargo-generate
|
||||||
|
$ cargo generate --git https://github.com/PyO3/pyo3 examples/maturin-starter
|
||||||
|
```
|
||||||
|
|
||||||
|
(`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
[template]
|
||||||
|
ignore = [".tox"]
|
||||||
|
|
||||||
|
[hooks]
|
||||||
|
pre = [".template/pre-script.rhai"]
|
|
@ -1,3 +1,16 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["maturin>=0.12,<0.13"]
|
requires = ["maturin>=0.12,<0.13"]
|
||||||
build-backend = "maturin"
|
build-backend = "maturin"
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "maturin-starter"
|
||||||
|
version = "0.1.0"
|
||||||
|
classifier=[
|
||||||
|
"License :: OSI Approved :: MIT License",
|
||||||
|
"Development Status :: 3 - Alpha",
|
||||||
|
"Intended Audience :: Developers",
|
||||||
|
"Programming Language :: Python",
|
||||||
|
"Programming Language :: Rust",
|
||||||
|
"Operating System :: POSIX",
|
||||||
|
"Operating System :: MacOS :: MacOS X",
|
||||||
|
]
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
authors = ["{{authors}}"]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "setuptools_rust_starter"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
|
|
@ -0,0 +1,5 @@
|
||||||
|
variable::set("PYO3_VERSION", "0.15.1");
|
||||||
|
file::rename(".template/Cargo.toml", "Cargo.toml");
|
||||||
|
file::rename(".template/setup.cfg", "setup.cfg");
|
||||||
|
file::rename(".template/tox.ini", "tox.ini");
|
||||||
|
file::delete(".template");
|
|
@ -0,0 +1,9 @@
|
||||||
|
[metadata]
|
||||||
|
name = {{project-name}}
|
||||||
|
version = 0.1.0
|
||||||
|
packages =
|
||||||
|
setuptools_rust_starter
|
||||||
|
|
||||||
|
[options]
|
||||||
|
include_package_data = True
|
||||||
|
zip_safe = False
|
|
@ -0,0 +1,7 @@
|
||||||
|
[tox]
|
||||||
|
isolated_build = true
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
description = Run the unit tests under {basepython}
|
||||||
|
deps = -rrequirements-dev.txt
|
||||||
|
commands = pytest {posargs}
|
|
@ -1,30 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["PyO3 Authors"]
|
|
||||||
name = "setuptools-rust-starter"
|
name = "setuptools-rust-starter"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
description = "An example project to get started using PyO3 with maturin"
|
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
|
|
||||||
[dependencies.pyo3]
|
|
||||||
path = "../../"
|
|
||||||
features = ["extension-module"]
|
|
||||||
|
|
||||||
[workspace]
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "setuptools_rust_starter"
|
name = "setuptools_rust_starter"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
[package.metadata.maturin]
|
[dependencies]
|
||||||
classifier=[
|
pyo3 = { path = "../../", features = ["extension-module"] }
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Development Status :: 3 - Alpha",
|
|
||||||
"Intended Audience :: Developers",
|
|
||||||
"Programming Language :: Python",
|
|
||||||
"Programming Language :: Rust",
|
|
||||||
"Operating System :: POSIX",
|
|
||||||
"Operating System :: MacOS :: MacOS X",
|
|
||||||
]
|
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
|
@ -22,3 +22,14 @@ Alternatively, install tox and run the tests inside an isolated environment:
|
||||||
```shell
|
```shell
|
||||||
tox -e py
|
tox -e py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Copying this example
|
||||||
|
|
||||||
|
Use [`cargo-generate`](https://crates.io/crates/cargo-generate):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo install cargo-generate
|
||||||
|
$ cargo generate --git https://github.com/PyO3/pyo3 examples/setuptools-rust-starter
|
||||||
|
```
|
||||||
|
|
||||||
|
(`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
[template]
|
||||||
|
ignore = [".tox"]
|
||||||
|
|
||||||
|
[hooks]
|
||||||
|
pre = [".template/pre-script.rhai"]
|
|
@ -0,0 +1,2 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"]
|
|
@ -0,0 +1,17 @@
|
||||||
|
[metadata]
|
||||||
|
name = setuptools-rust-starter
|
||||||
|
version = 0.1.0
|
||||||
|
packages =
|
||||||
|
setuptools_rust_starter
|
||||||
|
classifiers =
|
||||||
|
License :: OSI Approved :: MIT License
|
||||||
|
Development Status :: 3 - Alpha
|
||||||
|
Intended Audience :: Developers
|
||||||
|
Programming Language :: Python
|
||||||
|
Programming Language :: Rust
|
||||||
|
Operating System :: POSIX
|
||||||
|
Operating System :: MacOS :: MacOS X
|
||||||
|
|
||||||
|
[options]
|
||||||
|
include_package_data = True
|
||||||
|
zip_safe = False
|
|
@ -1,26 +1,6 @@
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from setuptools_rust import RustExtension
|
from setuptools_rust import RustExtension
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="setuptools-rust-starter",
|
rust_extensions=[RustExtension("setuptools_rust_starter._setuptools_rust_starter")],
|
||||||
version="0.1.0",
|
|
||||||
classifiers=[
|
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Development Status :: 3 - Alpha",
|
|
||||||
"Intended Audience :: Developers",
|
|
||||||
"Programming Language :: Python",
|
|
||||||
"Programming Language :: Rust",
|
|
||||||
"Operating System :: POSIX",
|
|
||||||
"Operating System :: MacOS :: MacOS X",
|
|
||||||
],
|
|
||||||
packages=["setuptools_rust_starter"],
|
|
||||||
rust_extensions=[
|
|
||||||
RustExtension(
|
|
||||||
"setuptools_rust_starter._setuptools_rust_starter",
|
|
||||||
debug=False,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
include_package_data=True,
|
|
||||||
zip_safe=False,
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
[package]
|
||||||
|
authors = ["{{authors}}"]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "word_count"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] }
|
||||||
|
rayon = "1.0.2"
|
|
@ -0,0 +1,4 @@
|
||||||
|
variable::set("PYO3_VERSION", "0.15.1");
|
||||||
|
file::rename(".template/Cargo.toml", "Cargo.toml");
|
||||||
|
file::rename(".template/tox.ini", "tox.ini");
|
||||||
|
file::delete(".template");
|
|
@ -0,0 +1,6 @@
|
||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"]
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "{{project-name}}"
|
||||||
|
version = "0.1.0"
|
|
@ -0,0 +1,9 @@
|
||||||
|
[metadata]
|
||||||
|
name = {{project-name}}
|
||||||
|
version = 0.1.0
|
||||||
|
packages =
|
||||||
|
word_count
|
||||||
|
|
||||||
|
[options]
|
||||||
|
include_package_data = True
|
||||||
|
zip_safe = False
|
|
@ -0,0 +1,7 @@
|
||||||
|
[tox]
|
||||||
|
isolated_build = true
|
||||||
|
|
||||||
|
[testenv]
|
||||||
|
description = Run the unit tests under {basepython}
|
||||||
|
deps = -rrequirements-dev.txt
|
||||||
|
commands = pytest {posargs}
|
|
@ -1,15 +1,14 @@
|
||||||
[package]
|
[package]
|
||||||
authors = ["Messense Lv <messense@icloud.com>"]
|
|
||||||
name = "word-count"
|
name = "word-count"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
rayon = "1.0.2"
|
|
||||||
pyo3 = { path = "../..", features = ["extension-module"] }
|
|
||||||
|
|
||||||
[workspace]
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "word_count"
|
name = "word_count"
|
||||||
crate-type = ["cdylib"]
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
pyo3 = { path = "../..", features = ["extension-module"] }
|
||||||
|
rayon = "1.0.2"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
|
|
@ -40,3 +40,14 @@ To test install tox globally and run
|
||||||
```shell
|
```shell
|
||||||
tox -e py
|
tox -e py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Copying this example
|
||||||
|
|
||||||
|
Use [`cargo-generate`](https://crates.io/crates/cargo-generate):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ cargo install cargo-generate
|
||||||
|
$ cargo generate --git https://github.com/PyO3/pyo3 examples/word-count
|
||||||
|
```
|
||||||
|
|
||||||
|
(`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.)
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
[template]
|
||||||
|
ignore = [".tox"]
|
||||||
|
|
||||||
|
[hooks]
|
||||||
|
pre = [".template/pre-script.rhai"]
|
|
@ -1,2 +1,2 @@
|
||||||
[build-system]
|
[build-system]
|
||||||
requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=0.10.2"]
|
requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"]
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
[metadata]
|
||||||
|
name = word-count
|
||||||
|
version = 0.1.0
|
||||||
|
packages =
|
||||||
|
word_count
|
||||||
|
classifiers =
|
||||||
|
License :: OSI Approved :: MIT License
|
||||||
|
Development Status :: 3 - Alpha
|
||||||
|
Intended Audience :: Developers
|
||||||
|
Programming Language :: Python
|
||||||
|
Programming Language :: Rust
|
||||||
|
Operating System :: POSIX
|
||||||
|
Operating System :: MacOS :: MacOS X
|
||||||
|
|
||||||
|
[options]
|
||||||
|
include_package_data = True
|
||||||
|
zip_safe = False
|
|
@ -1,21 +1,6 @@
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from setuptools_rust import RustExtension
|
from setuptools_rust import RustExtension
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="word-count",
|
rust_extensions=[RustExtension("word_count.word_count", debug=False)],
|
||||||
version="0.1.0",
|
|
||||||
classifiers=[
|
|
||||||
"License :: OSI Approved :: MIT License",
|
|
||||||
"Development Status :: 3 - Alpha",
|
|
||||||
"Intended Audience :: Developers",
|
|
||||||
"Programming Language :: Python",
|
|
||||||
"Programming Language :: Rust",
|
|
||||||
"Operating System :: POSIX",
|
|
||||||
"Operating System :: MacOS :: MacOS X",
|
|
||||||
],
|
|
||||||
packages=["word_count"],
|
|
||||||
rust_extensions=[RustExtension("word_count.word_count", "Cargo.toml", debug=False)],
|
|
||||||
include_package_data=True,
|
|
||||||
zip_safe=False,
|
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue