Skip to content

Commit

Permalink
Setting Poetry as the default
Browse files Browse the repository at this point in the history
  • Loading branch information
steinwaywhw committed Aug 19, 2024
1 parent 18272a4 commit b8d2033
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 53 deletions.
30 changes: 18 additions & 12 deletions _internal/_template/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Title

<details>
<summary>How to run this example</summary>
<summary>How to run this example</summary>
<br/>

```bash
# Set your API key as an environment variable.
Expand All @@ -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
```

</details>
Expand All @@ -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)
Expand Down Expand Up @@ -82,7 +89,6 @@ If your example is a graph, create a diagram.

![diagram](diagram.svg)


To edit the diagram, run:

```bash
Expand Down
4 changes: 2 additions & 2 deletions _internal/_template/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ export SUBSTRATE_API_KEY=<your 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
Expand Down
36 changes: 18 additions & 18 deletions _internal/_template/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
# readme = "README.md"
[tool.poetry]
name = "template"
version = "0.1.0"
description = ""
authors = ["Hanwen Wu <[email protected]>"]
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"


###########################
Expand Down
4 changes: 2 additions & 2 deletions basics/generate-text/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export SUBSTRATE_API_KEY=<your 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
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
Expand Down
38 changes: 19 additions & 19 deletions basics/generate-text/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
# readme = "README.md"
[tool.poetry]
name = "example-generate-text"
version = "0.1.0"
description = ""
authors = ["Ben Guo <[email protected]>"]
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
Expand Down

0 comments on commit b8d2033

Please sign in to comment.