From b8d2033d3096899ac07f32d7df90eb393f64da7b Mon Sep 17 00:00:00 2001 From: hwwu Date: Mon, 19 Aug 2024 14:15:49 -0400 Subject: [PATCH] Setting Poetry as the default --- _internal/_template/README.md | 30 ++++++++++------- _internal/_template/python/README.md | 4 +-- _internal/_template/python/pyproject.toml | 36 ++++++++++---------- basics/generate-text/python/README.md | 4 +-- basics/generate-text/python/pyproject.toml | 38 +++++++++++----------- 5 files changed, 59 insertions(+), 53 deletions(-) diff --git a/_internal/_template/README.md b/_internal/_template/README.md index 6fd4d14..2e5421d 100644 --- a/_internal/_template/README.md +++ b/_internal/_template/README.md @@ -1,7 +1,8 @@ # Title
- How to run this example +How to run this example +
```bash # Set your API key as an environment variable. @@ -12,10 +13,16 @@ cd typescript # Navigate to the typescript example npm install # Install dependencies ts-node example.ts # Run the example -# Run the Python example -# Note: First install dependencies in the root examples directory. +# If using Poetry: cd python # Navigate to the python example -poetry run python example.py # Run the example +poetry install # Install dependencies and build the example +poetry run main # Run the example + +# If using Rye: +# Update pyproject.toml to switch to Rye. +cd python # Navigate to the python example +rye sync # Install dependencies and build the example +rye run main # Run the example ```
@@ -24,13 +31,13 @@ We follow this procedure to create consistent, high volume content. 1. Come up with a short readable slug, e.g. `generate-json` and a title. 2. Create a folder in the [examples repo](https://github.com/SubstrateLabs/examples), copying this folder -3. Write the code in TS or Python, and keep it simple. Ideally it’s just a script with no additional dependencies. - 1. Consider creating illustrative variations of the script (e.g. `ComputeText` and `MultiComputeText` - [example](https://github.com/SubstrateLabs/examples/tree/main/basics/generate-text)) - 2. Translate your script to the other language. (TODO: automated translation with Substrate) - 3. Make sure both examples run and produce simple polished output. - 4. Simplify the code - 1. Wrap lines (multi-line node declarations are easier to read) - 2. Consider inlining variables +3. Write the code in TS or Python, and keep it simple. Ideally it’s just a script with no additional dependencies. + 1. Consider creating illustrative variations of the script (e.g. `ComputeText` and `MultiComputeText` - [example](https://github.com/SubstrateLabs/examples/tree/main/basics/generate-text)) + 2. Translate your script to the other language. (TODO: automated translation with Substrate) + 3. Make sure both examples run and produce simple polished output. + 4. Simplify the code + 1. Wrap lines (multi-line node declarations are easier to read) + 2. Consider inlining variables 4. Fill out this README with walkthrough text and generate new image assets. ![hero](hero.png) @@ -82,7 +89,6 @@ If your example is a graph, create a diagram. ![diagram](diagram.svg) - To edit the diagram, run: ```bash diff --git a/_internal/_template/python/README.md b/_internal/_template/python/README.md index e2a6044..8a1841b 100644 --- a/_internal/_template/python/README.md +++ b/_internal/_template/python/README.md @@ -11,14 +11,14 @@ export SUBSTRATE_API_KEY= cd python ``` -To run the example with Poetry, uncomment the Poetry sections in `pyproject.toml` and run the following. +To run the example with Poetry (default), run the following. ```bash poetry install poetry run main ``` -To run the example with Rye, uncomment the Rye sections in `pyproject.toml` and run the following. +To run the example with Rye, comment out the Poetry sections and uncomment the Rye sections in `pyproject.toml` and run the following. ```bash rye sync diff --git a/_internal/_template/python/pyproject.toml b/_internal/_template/python/pyproject.toml index 3cd7327..18d6a28 100644 --- a/_internal/_template/python/pyproject.toml +++ b/_internal/_template/python/pyproject.toml @@ -24,29 +24,29 @@ venv = ".venv" # Uncomment for Poetry support ############################## -# [build-system] -# requires = ["poetry-core"] -# build-backend = "poetry.core.masonry.api" +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" -# [tool.poetry] -# name = "template" -# version = "0.1.0" -# description = "" -# authors = ["Hanwen Wu "] -# readme = "README.md" +[tool.poetry] +name = "template" +version = "0.1.0" +description = "" +authors = ["Hanwen Wu "] +readme = "README.md" -# packages = [{ include = "python", from = "src" }] +packages = [{ include = "python", from = "src" }] -# [tool.poetry.dependencies] -# python = "^3.9" -# substrate = "220240617.*" +[tool.poetry.dependencies] +python = "^3.9" +substrate = "220240617.*" -# [tool.poetry.group.dev.dependencies] -# ruff = "^0.6.1" -# marimo = "^0.8.0" +[tool.poetry.group.dev.dependencies] +ruff = "^0.6.1" +marimo = "^0.8.0" -# [tool.poetry.scripts] -# main = "python.example:main" +[tool.poetry.scripts] +main = "python.example:main" ########################### diff --git a/basics/generate-text/python/README.md b/basics/generate-text/python/README.md index f69204d..105f0df 100644 --- a/basics/generate-text/python/README.md +++ b/basics/generate-text/python/README.md @@ -11,7 +11,7 @@ export SUBSTRATE_API_KEY= cd python ``` -To run the example with Poetry, uncomment the Poetry sections in `pyproject.toml` and run the following. +To run the example with Poetry (default), ```bash poetry install @@ -19,7 +19,7 @@ poetry run example poetry run example-multi ``` -To run the example with Rye, uncomment the Rye sections in `pyproject.toml` and run the following. +To run the example with Rye, comment out the Poetry sections and uncomment the Rye sections in `pyproject.toml` and run the following. ```bash rye sync diff --git a/basics/generate-text/python/pyproject.toml b/basics/generate-text/python/pyproject.toml index 4edd787..06edbae 100644 --- a/basics/generate-text/python/pyproject.toml +++ b/basics/generate-text/python/pyproject.toml @@ -25,30 +25,30 @@ venv = ".venv" # Uncomment for Poetry support ############################## -# [build-system] -# requires = ["poetry-core"] -# build-backend = "poetry.core.masonry.api" +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" -# [tool.poetry] -# name = "example-generate-text" -# version = "0.1.0" -# description = "" -# authors = ["Ben Guo "] -# readme = "README.md" +[tool.poetry] +name = "example-generate-text" +version = "0.1.0" +description = "" +authors = ["Ben Guo "] +readme = "README.md" -# packages = [{ include = "generatetext", from = "src" }] +packages = [{ include = "generatetext", from = "src" }] -# [tool.poetry.dependencies] -# python = "^3.9" -# substrate = "220240617.*" +[tool.poetry.dependencies] +python = "^3.9" +substrate = "220240617.*" -# [tool.poetry.group.dev.dependencies] -# ruff = "^0.6.1" -# marimo = "^0.8.0" +[tool.poetry.group.dev.dependencies] +ruff = "^0.6.1" +marimo = "^0.8.0" -# [tool.poetry.scripts] -# example = "generatetext.example:main" -# example-multi = "generatetext.example_multi:main" +[tool.poetry.scripts] +example = "generatetext.example:main" +example-multi = "generatetext.example_multi:main" ########################### # Uncomment for Rye support