From ce7e17c0e66fedd7219f189816df0c0a25fedc57 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Tue, 14 Dec 2021 08:29:48 +0000 Subject: [PATCH 1/3] examples: add cargo-generate configuration --- examples/README.md | 11 ++++++++++ examples/decorator/.template/Cargo.toml | 13 +++++++++++ examples/decorator/.template/pre-script.rhai | 5 +++++ examples/decorator/.template/pyproject.toml | 7 ++++++ examples/decorator/.template/tox.ini | 7 ++++++ examples/decorator/cargo-generate.toml | 5 +++++ examples/decorator/pyproject.toml | 13 +++++++++++ examples/maturin-starter/.template/Cargo.toml | 13 +++++++++++ .../maturin-starter/.template/pre-script.rhai | 5 +++++ .../maturin-starter/.template/pyproject.toml | 7 ++++++ examples/maturin-starter/.template/tox.ini | 7 ++++++ examples/maturin-starter/Cargo.toml | 11 ---------- examples/maturin-starter/README.md | 11 ++++++++++ examples/maturin-starter/cargo-generate.toml | 5 +++++ examples/maturin-starter/pyproject.toml | 13 +++++++++++ .../.template/Cargo.toml | 13 +++++++++++ .../.template/pre-script.rhai | 5 +++++ .../.template/setup.cfg | 9 ++++++++ .../setuptools-rust-starter/.template/tox.ini | 7 ++++++ examples/setuptools-rust-starter/Cargo.toml | 12 ---------- .../cargo-generate.toml | 5 +++++ .../setuptools-rust-starter/pyproject.toml | 2 ++ examples/setuptools-rust-starter/setup.cfg | 17 ++++++++++++++ examples/setuptools-rust-starter/setup.py | 22 +------------------ examples/word-count/.template/Cargo.toml | 13 +++++++++++ examples/word-count/.template/pre-script.rhai | 4 ++++ examples/word-count/.template/pyproject.toml | 6 +++++ examples/word-count/.template/setup.cfg | 9 ++++++++ examples/word-count/.template/tox.ini | 7 ++++++ examples/word-count/cargo-generate.toml | 5 +++++ examples/word-count/pyproject.toml | 2 +- examples/word-count/setup.cfg | 17 ++++++++++++++ examples/word-count/setup.py | 17 +------------- 33 files changed, 244 insertions(+), 61 deletions(-) create mode 100644 examples/decorator/.template/Cargo.toml create mode 100644 examples/decorator/.template/pre-script.rhai create mode 100644 examples/decorator/.template/pyproject.toml create mode 100644 examples/decorator/.template/tox.ini create mode 100644 examples/decorator/cargo-generate.toml create mode 100644 examples/maturin-starter/.template/Cargo.toml create mode 100644 examples/maturin-starter/.template/pre-script.rhai create mode 100644 examples/maturin-starter/.template/pyproject.toml create mode 100644 examples/maturin-starter/.template/tox.ini create mode 100644 examples/maturin-starter/cargo-generate.toml create mode 100644 examples/setuptools-rust-starter/.template/Cargo.toml create mode 100644 examples/setuptools-rust-starter/.template/pre-script.rhai create mode 100644 examples/setuptools-rust-starter/.template/setup.cfg create mode 100644 examples/setuptools-rust-starter/.template/tox.ini create mode 100644 examples/setuptools-rust-starter/cargo-generate.toml create mode 100644 examples/setuptools-rust-starter/pyproject.toml create mode 100644 examples/setuptools-rust-starter/setup.cfg create mode 100644 examples/word-count/.template/Cargo.toml create mode 100644 examples/word-count/.template/pre-script.rhai create mode 100644 examples/word-count/.template/pyproject.toml create mode 100644 examples/word-count/.template/setup.cfg create mode 100644 examples/word-count/.template/tox.ini create mode 100644 examples/word-count/cargo-generate.toml create mode 100644 examples/word-count/setup.cfg diff --git a/examples/README.md b/examples/README.md index 6561b4cb..fbfad103 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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. | | `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. | + +## Creating new projects from these examples + +To copy an example, use `cargo-generate`. Follow the commands below, replacing `` with the example to start from: + +```bash +$ cargo install cargo-generate +$ cargo generate --git https://github.com/PyO3/pyo3 examples/ +``` + +(`cargo generate` will take a little while to clone the PyO3 repo first; be patient when waiting for the command to run.) diff --git a/examples/decorator/.template/Cargo.toml b/examples/decorator/.template/Cargo.toml new file mode 100644 index 00000000..9b9a0ca2 --- /dev/null +++ b/examples/decorator/.template/Cargo.toml @@ -0,0 +1,13 @@ +[package] +authors = ["{{authors}}"] +name = "{{project-name}}" +version = "0.1.0" +description = "An example project to get started using PyO3 with maturin" +edition = "2018" + +[dependencies] +pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } + +[lib] +name = "maturin_starter" +crate-type = ["cdylib"] diff --git a/examples/decorator/.template/pre-script.rhai b/examples/decorator/.template/pre-script.rhai new file mode 100644 index 00000000..d8f836a0 --- /dev/null +++ b/examples/decorator/.template/pre-script.rhai @@ -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"); diff --git a/examples/decorator/.template/pyproject.toml b/examples/decorator/.template/pyproject.toml new file mode 100644 index 00000000..007a5574 --- /dev/null +++ b/examples/decorator/.template/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["maturin>=0.12,<0.13"] +build-backend = "maturin" + +[project] +name = "{{project-name}}" +version = "0.1.0" diff --git a/examples/decorator/.template/tox.ini b/examples/decorator/.template/tox.ini new file mode 100644 index 00000000..ca1c347a --- /dev/null +++ b/examples/decorator/.template/tox.ini @@ -0,0 +1,7 @@ +[tox] +isolated_build = true + +[testenv] +description = Run the unit tests under {basepython} +deps = -rrequirements-dev.txt +commands = pytest {posargs} diff --git a/examples/decorator/cargo-generate.toml b/examples/decorator/cargo-generate.toml new file mode 100644 index 00000000..ffa474e1 --- /dev/null +++ b/examples/decorator/cargo-generate.toml @@ -0,0 +1,5 @@ +[template] +ignore = [".tox"] + +[hooks] +pre = [".template/pre-script.rhai"] diff --git a/examples/decorator/pyproject.toml b/examples/decorator/pyproject.toml index 256b3705..3a8fd7e4 100644 --- a/examples/decorator/pyproject.toml +++ b/examples/decorator/pyproject.toml @@ -1,3 +1,16 @@ [build-system] requires = ["maturin>=0.12,<0.13"] 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", +] diff --git a/examples/maturin-starter/.template/Cargo.toml b/examples/maturin-starter/.template/Cargo.toml new file mode 100644 index 00000000..9b9a0ca2 --- /dev/null +++ b/examples/maturin-starter/.template/Cargo.toml @@ -0,0 +1,13 @@ +[package] +authors = ["{{authors}}"] +name = "{{project-name}}" +version = "0.1.0" +description = "An example project to get started using PyO3 with maturin" +edition = "2018" + +[dependencies] +pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } + +[lib] +name = "maturin_starter" +crate-type = ["cdylib"] diff --git a/examples/maturin-starter/.template/pre-script.rhai b/examples/maturin-starter/.template/pre-script.rhai new file mode 100644 index 00000000..d8f836a0 --- /dev/null +++ b/examples/maturin-starter/.template/pre-script.rhai @@ -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"); diff --git a/examples/maturin-starter/.template/pyproject.toml b/examples/maturin-starter/.template/pyproject.toml new file mode 100644 index 00000000..007a5574 --- /dev/null +++ b/examples/maturin-starter/.template/pyproject.toml @@ -0,0 +1,7 @@ +[build-system] +requires = ["maturin>=0.12,<0.13"] +build-backend = "maturin" + +[project] +name = "{{project-name}}" +version = "0.1.0" diff --git a/examples/maturin-starter/.template/tox.ini b/examples/maturin-starter/.template/tox.ini new file mode 100644 index 00000000..ca1c347a --- /dev/null +++ b/examples/maturin-starter/.template/tox.ini @@ -0,0 +1,7 @@ +[tox] +isolated_build = true + +[testenv] +description = Run the unit tests under {basepython} +deps = -rrequirements-dev.txt +commands = pytest {posargs} diff --git a/examples/maturin-starter/Cargo.toml b/examples/maturin-starter/Cargo.toml index 5718d3b4..fb299a9d 100644 --- a/examples/maturin-starter/Cargo.toml +++ b/examples/maturin-starter/Cargo.toml @@ -16,14 +16,3 @@ features = ["extension-module"] [lib] name = "maturin_starter" crate-type = ["cdylib"] - -[package.metadata.maturin] -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", -] diff --git a/examples/maturin-starter/README.md b/examples/maturin-starter/README.md index a9296515..0b1633b7 100644 --- a/examples/maturin-starter/README.md +++ b/examples/maturin-starter/README.md @@ -22,3 +22,14 @@ Alternatively, install tox and run the tests inside an isolated environment: ```shell tox -e py ``` + +## Copying this example + +Use `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.) diff --git a/examples/maturin-starter/cargo-generate.toml b/examples/maturin-starter/cargo-generate.toml new file mode 100644 index 00000000..ffa474e1 --- /dev/null +++ b/examples/maturin-starter/cargo-generate.toml @@ -0,0 +1,5 @@ +[template] +ignore = [".tox"] + +[hooks] +pre = [".template/pre-script.rhai"] diff --git a/examples/maturin-starter/pyproject.toml b/examples/maturin-starter/pyproject.toml index 256b3705..274cda13 100644 --- a/examples/maturin-starter/pyproject.toml +++ b/examples/maturin-starter/pyproject.toml @@ -1,3 +1,16 @@ [build-system] requires = ["maturin>=0.12,<0.13"] 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", +] diff --git a/examples/setuptools-rust-starter/.template/Cargo.toml b/examples/setuptools-rust-starter/.template/Cargo.toml new file mode 100644 index 00000000..1c720d8f --- /dev/null +++ b/examples/setuptools-rust-starter/.template/Cargo.toml @@ -0,0 +1,13 @@ +[package] +authors = ["{{authors}}"] +name = "{{project-name}}" +version = "0.1.0" +description = "An example project to get started using PyO3 with setuptools_rust" +edition = "2018" + +[dependencies] +pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } + +[lib] +name = "setuptools_rust_starter" +crate-type = ["cdylib"] diff --git a/examples/setuptools-rust-starter/.template/pre-script.rhai b/examples/setuptools-rust-starter/.template/pre-script.rhai new file mode 100644 index 00000000..2f8d2ee3 --- /dev/null +++ b/examples/setuptools-rust-starter/.template/pre-script.rhai @@ -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"); diff --git a/examples/setuptools-rust-starter/.template/setup.cfg b/examples/setuptools-rust-starter/.template/setup.cfg new file mode 100644 index 00000000..90f44aba --- /dev/null +++ b/examples/setuptools-rust-starter/.template/setup.cfg @@ -0,0 +1,9 @@ +[metadata] +name = {{project-name}} +version = 0.1.0 +packages = + setuptools_rust_starter + +[options] +include_package_data = True +zip_safe = False diff --git a/examples/setuptools-rust-starter/.template/tox.ini b/examples/setuptools-rust-starter/.template/tox.ini new file mode 100644 index 00000000..ca1c347a --- /dev/null +++ b/examples/setuptools-rust-starter/.template/tox.ini @@ -0,0 +1,7 @@ +[tox] +isolated_build = true + +[testenv] +description = Run the unit tests under {basepython} +deps = -rrequirements-dev.txt +commands = pytest {posargs} diff --git a/examples/setuptools-rust-starter/Cargo.toml b/examples/setuptools-rust-starter/Cargo.toml index cf34db65..ad6ba2f1 100644 --- a/examples/setuptools-rust-starter/Cargo.toml +++ b/examples/setuptools-rust-starter/Cargo.toml @@ -16,15 +16,3 @@ features = ["extension-module"] [lib] name = "setuptools_rust_starter" crate-type = ["cdylib"] - -[package.metadata.maturin] -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", -] - diff --git a/examples/setuptools-rust-starter/cargo-generate.toml b/examples/setuptools-rust-starter/cargo-generate.toml new file mode 100644 index 00000000..ffa474e1 --- /dev/null +++ b/examples/setuptools-rust-starter/cargo-generate.toml @@ -0,0 +1,5 @@ +[template] +ignore = [".tox"] + +[hooks] +pre = [".template/pre-script.rhai"] diff --git a/examples/setuptools-rust-starter/pyproject.toml b/examples/setuptools-rust-starter/pyproject.toml new file mode 100644 index 00000000..d82653c1 --- /dev/null +++ b/examples/setuptools-rust-starter/pyproject.toml @@ -0,0 +1,2 @@ +[build-system] +requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"] diff --git a/examples/setuptools-rust-starter/setup.cfg b/examples/setuptools-rust-starter/setup.cfg new file mode 100644 index 00000000..cd9882bc --- /dev/null +++ b/examples/setuptools-rust-starter/setup.cfg @@ -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 diff --git a/examples/setuptools-rust-starter/setup.py b/examples/setuptools-rust-starter/setup.py index 0c8a9658..3725444b 100644 --- a/examples/setuptools-rust-starter/setup.py +++ b/examples/setuptools-rust-starter/setup.py @@ -1,26 +1,6 @@ from setuptools import setup from setuptools_rust import RustExtension - setup( - name="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, + rust_extensions=[RustExtension("setuptools_rust_starter._setuptools_rust_starter")], ) diff --git a/examples/word-count/.template/Cargo.toml b/examples/word-count/.template/Cargo.toml new file mode 100644 index 00000000..dcc78d1d --- /dev/null +++ b/examples/word-count/.template/Cargo.toml @@ -0,0 +1,13 @@ +[package] +authors = ["{{authors}}"] +name = "{{project-name}}" +version = "0.1.0" +edition = "2018" + +[dependencies] +rayon = "1.0.2" +pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } + +[lib] +name = "word_count" +crate-type = ["cdylib"] diff --git a/examples/word-count/.template/pre-script.rhai b/examples/word-count/.template/pre-script.rhai new file mode 100644 index 00000000..3f0ab336 --- /dev/null +++ b/examples/word-count/.template/pre-script.rhai @@ -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"); diff --git a/examples/word-count/.template/pyproject.toml b/examples/word-count/.template/pyproject.toml new file mode 100644 index 00000000..c25d7dc5 --- /dev/null +++ b/examples/word-count/.template/pyproject.toml @@ -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" diff --git a/examples/word-count/.template/setup.cfg b/examples/word-count/.template/setup.cfg new file mode 100644 index 00000000..7b861826 --- /dev/null +++ b/examples/word-count/.template/setup.cfg @@ -0,0 +1,9 @@ +[metadata] +name = {{project-name}} +version = 0.1.0 +packages = + word_count + +[options] +include_package_data = True +zip_safe = False diff --git a/examples/word-count/.template/tox.ini b/examples/word-count/.template/tox.ini new file mode 100644 index 00000000..ca1c347a --- /dev/null +++ b/examples/word-count/.template/tox.ini @@ -0,0 +1,7 @@ +[tox] +isolated_build = true + +[testenv] +description = Run the unit tests under {basepython} +deps = -rrequirements-dev.txt +commands = pytest {posargs} diff --git a/examples/word-count/cargo-generate.toml b/examples/word-count/cargo-generate.toml new file mode 100644 index 00000000..ffa474e1 --- /dev/null +++ b/examples/word-count/cargo-generate.toml @@ -0,0 +1,5 @@ +[template] +ignore = [".tox"] + +[hooks] +pre = [".template/pre-script.rhai"] diff --git a/examples/word-count/pyproject.toml b/examples/word-count/pyproject.toml index 650da5fa..d82653c1 100644 --- a/examples/word-count/pyproject.toml +++ b/examples/word-count/pyproject.toml @@ -1,2 +1,2 @@ [build-system] -requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=0.10.2"] +requires = ["setuptools>=41.0.0", "wheel", "setuptools_rust>=1.0.0"] diff --git a/examples/word-count/setup.cfg b/examples/word-count/setup.cfg new file mode 100644 index 00000000..d8f501ba --- /dev/null +++ b/examples/word-count/setup.cfg @@ -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 diff --git a/examples/word-count/setup.py b/examples/word-count/setup.py index 05eb2651..df702806 100644 --- a/examples/word-count/setup.py +++ b/examples/word-count/setup.py @@ -1,21 +1,6 @@ from setuptools import setup from setuptools_rust import RustExtension - setup( - name="word-count", - 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, + rust_extensions=[RustExtension("word_count.word_count", debug=False)], ) From 888b10c373f816469434450045d66a0b7adb6118 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Tue, 14 Dec 2021 22:26:52 +0000 Subject: [PATCH 2/3] examples: add links to cargo-generate Co-authored-by: Adam Reichold --- examples/README.md | 2 +- examples/decorator/README.md | 11 +++++++++++ examples/maturin-starter/README.md | 2 +- examples/setuptools-rust-starter/README.md | 11 +++++++++++ examples/word-count/README.md | 11 +++++++++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/examples/README.md b/examples/README.md index fbfad103..1e135bf5 100644 --- a/examples/README.md +++ b/examples/README.md @@ -13,7 +13,7 @@ Below is a brief description of each of these: ## Creating new projects from these examples -To copy an example, use `cargo-generate`. Follow the commands below, replacing `` with the example to start from: +To copy an example, use [`cargo-generate`](https://crates.io/crates/cargo-generate). Follow the commands below, replacing `` with the example to start from: ```bash $ cargo install cargo-generate diff --git a/examples/decorator/README.md b/examples/decorator/README.md index 4e5f3bdf..22c75cde 100644 --- a/examples/decorator/README.md +++ b/examples/decorator/README.md @@ -23,3 +23,14 @@ Alternatively, install tox and run the tests inside an isolated environment: ```shell 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.) diff --git a/examples/maturin-starter/README.md b/examples/maturin-starter/README.md index 0b1633b7..0959f60e 100644 --- a/examples/maturin-starter/README.md +++ b/examples/maturin-starter/README.md @@ -25,7 +25,7 @@ tox -e py ## Copying this example -Use `cargo-generate`: +Use [`cargo-generate`](https://crates.io/crates/cargo-generate): ```bash $ cargo install cargo-generate diff --git a/examples/setuptools-rust-starter/README.md b/examples/setuptools-rust-starter/README.md index 12913457..4e0276f4 100644 --- a/examples/setuptools-rust-starter/README.md +++ b/examples/setuptools-rust-starter/README.md @@ -22,3 +22,14 @@ Alternatively, install tox and run the tests inside an isolated environment: ```shell 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.) diff --git a/examples/word-count/README.md b/examples/word-count/README.md index 02e81e4a..2ff90910 100644 --- a/examples/word-count/README.md +++ b/examples/word-count/README.md @@ -40,3 +40,14 @@ To test install tox globally and run ```shell 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.) From bd3c3adf46b32d70f8875a582f847bbf867d42cc Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Wed, 15 Dec 2021 08:28:25 +0000 Subject: [PATCH 3/3] examples: make Cargo.toml files more uniform --- examples/decorator/.template/Cargo.toml | 9 ++++----- examples/decorator/Cargo.toml | 10 ++-------- examples/maturin-starter/.template/Cargo.toml | 7 +++---- examples/maturin-starter/Cargo.toml | 15 +++++---------- .../setuptools-rust-starter/.template/Cargo.toml | 7 +++---- examples/setuptools-rust-starter/Cargo.toml | 15 +++++---------- examples/word-count/.template/Cargo.toml | 8 ++++---- examples/word-count/Cargo.toml | 13 ++++++------- 8 files changed, 32 insertions(+), 52 deletions(-) diff --git a/examples/decorator/.template/Cargo.toml b/examples/decorator/.template/Cargo.toml index 9b9a0ca2..4ff81390 100644 --- a/examples/decorator/.template/Cargo.toml +++ b/examples/decorator/.template/Cargo.toml @@ -2,12 +2,11 @@ authors = ["{{authors}}"] name = "{{project-name}}" version = "0.1.0" -description = "An example project to get started using PyO3 with maturin" edition = "2018" +[lib] +name = "decorator" +crate-type = ["cdylib"] + [dependencies] pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } - -[lib] -name = "maturin_starter" -crate-type = ["cdylib"] diff --git a/examples/decorator/Cargo.toml b/examples/decorator/Cargo.toml index 32545733..702f6a1f 100644 --- a/examples/decorator/Cargo.toml +++ b/examples/decorator/Cargo.toml @@ -3,17 +3,11 @@ name = "decorator" version = "0.1.0" edition = "2018" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] name = "decorator" crate-type = ["cdylib"] -[dependencies.pyo3] -# If you copy this example, you should uncomment this... -# version = "0.15.1" - -# ...and delete this path -path = "../.." -features = ["extension-module"] +[dependencies] +pyo3 = { path = "../../", features = ["extension-module"] } [workspace] diff --git a/examples/maturin-starter/.template/Cargo.toml b/examples/maturin-starter/.template/Cargo.toml index 9b9a0ca2..37695d29 100644 --- a/examples/maturin-starter/.template/Cargo.toml +++ b/examples/maturin-starter/.template/Cargo.toml @@ -2,12 +2,11 @@ authors = ["{{authors}}"] name = "{{project-name}}" version = "0.1.0" -description = "An example project to get started using PyO3 with maturin" edition = "2018" -[dependencies] -pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } - [lib] name = "maturin_starter" crate-type = ["cdylib"] + +[dependencies] +pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } diff --git a/examples/maturin-starter/Cargo.toml b/examples/maturin-starter/Cargo.toml index fb299a9d..94045488 100644 --- a/examples/maturin-starter/Cargo.toml +++ b/examples/maturin-starter/Cargo.toml @@ -1,18 +1,13 @@ [package] -authors = ["PyO3 Authors"] name = "maturin-starter" version = "0.1.0" -description = "An example project to get started using PyO3 with maturin" edition = "2018" -[dependencies] - -[dependencies.pyo3] -path = "../../" -features = ["extension-module"] - -[workspace] - [lib] name = "maturin_starter" crate-type = ["cdylib"] + +[dependencies] +pyo3 = { path = "../../", features = ["extension-module"] } + +[workspace] diff --git a/examples/setuptools-rust-starter/.template/Cargo.toml b/examples/setuptools-rust-starter/.template/Cargo.toml index 1c720d8f..6f77ff80 100644 --- a/examples/setuptools-rust-starter/.template/Cargo.toml +++ b/examples/setuptools-rust-starter/.template/Cargo.toml @@ -2,12 +2,11 @@ authors = ["{{authors}}"] name = "{{project-name}}" version = "0.1.0" -description = "An example project to get started using PyO3 with setuptools_rust" edition = "2018" -[dependencies] -pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } - [lib] name = "setuptools_rust_starter" crate-type = ["cdylib"] + +[dependencies] +pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } diff --git a/examples/setuptools-rust-starter/Cargo.toml b/examples/setuptools-rust-starter/Cargo.toml index ad6ba2f1..d07c29d7 100644 --- a/examples/setuptools-rust-starter/Cargo.toml +++ b/examples/setuptools-rust-starter/Cargo.toml @@ -1,18 +1,13 @@ [package] -authors = ["PyO3 Authors"] name = "setuptools-rust-starter" version = "0.1.0" -description = "An example project to get started using PyO3 with maturin" edition = "2018" -[dependencies] - -[dependencies.pyo3] -path = "../../" -features = ["extension-module"] - -[workspace] - [lib] name = "setuptools_rust_starter" crate-type = ["cdylib"] + +[dependencies] +pyo3 = { path = "../../", features = ["extension-module"] } + +[workspace] diff --git a/examples/word-count/.template/Cargo.toml b/examples/word-count/.template/Cargo.toml index dcc78d1d..14db5476 100644 --- a/examples/word-count/.template/Cargo.toml +++ b/examples/word-count/.template/Cargo.toml @@ -4,10 +4,10 @@ name = "{{project-name}}" version = "0.1.0" edition = "2018" -[dependencies] -rayon = "1.0.2" -pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } - [lib] name = "word_count" crate-type = ["cdylib"] + +[dependencies] +pyo3 = { version = "{{PYO3_VERSION}}", features = ["extension-module"] } +rayon = "1.0.2" diff --git a/examples/word-count/Cargo.toml b/examples/word-count/Cargo.toml index 42aee9e2..a351cf75 100644 --- a/examples/word-count/Cargo.toml +++ b/examples/word-count/Cargo.toml @@ -1,15 +1,14 @@ [package] -authors = ["Messense Lv "] name = "word-count" version = "0.1.0" edition = "2018" -[dependencies] -rayon = "1.0.2" -pyo3 = { path = "../..", features = ["extension-module"] } - -[workspace] - [lib] name = "word_count" crate-type = ["cdylib"] + +[dependencies] +pyo3 = { path = "../..", features = ["extension-module"] } +rayon = "1.0.2" + +[workspace]