-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix typo Signed-off-by: GitHub <[email protected]> * Install as editable by default Signed-off-by: GitHub <[email protected]> * Move stories to text files Signed-off-by: GitHub <[email protected]> * Add entrypoint, pin dependencies Signed-off-by: GitHub <[email protected]> * Update name Signed-off-by: GitHub <[email protected]> * Bump version Signed-off-by: GitHub <[email protected]> --------- Signed-off-by: GitHub <[email protected]>
- Loading branch information
1 parent
38198ed
commit 8b4b0a8
Showing
8 changed files
with
124 additions
and
83 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 |
---|---|---|
@@ -1,24 +1,42 @@ | ||
[project] | ||
name = "crazylibs" | ||
version = "0.1.2" | ||
version = "0.2.0" | ||
description = "crazylibs" | ||
readme = "README.md" | ||
authors = [{ name = "Bradley Reynolds", email = "[email protected]" }] | ||
license = { text = "MIT" } | ||
requires-python = ">=3.10" | ||
dependencies = ["typer"] | ||
|
||
[project.optional-dependencies] | ||
dev = ["nox", "pre-commit", "ruff", "mypy"] | ||
docs = ["sphinx", "furo", "sphinx-autoapi", "releases"] | ||
tests = ["pytest", "pytest-randomly"] | ||
dependencies = [ | ||
"typer==0.12.5" | ||
] | ||
|
||
[project.urls] | ||
repository = "https://github.com/letsbuilda/crazylibs" | ||
documentation = "https://docs.letsbuilda.dev/crazylibs/" | ||
|
||
[project.scripts] | ||
crazylibs = "crazylibs.cli:app" | ||
|
||
[project.optional-dependencies] | ||
dev = [ | ||
"nox==2024.10.9", | ||
"pre-commit==4.0.1", | ||
"ruff==0.7.1", | ||
"mypy==1.13.0", | ||
] | ||
tests = [ | ||
"pytest==8.3.3", | ||
"pytest-randomly==3.15.0", | ||
] | ||
docs = [ | ||
"sphinx==8.1.3", | ||
"furo==2024.8.6", | ||
"sphinx-autoapi==3.3.2", | ||
"releases==2.1.1", | ||
] | ||
|
||
[build-system] | ||
requires = ["setuptools", "wheel"] | ||
requires = ["setuptools>=61.0"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools.package-data] | ||
|
@@ -29,7 +47,9 @@ target-version = "py310" | |
line-length = 120 | ||
|
||
[tool.ruff.lint] | ||
select = ["ALL"] | ||
select = [ | ||
"ALL", | ||
] | ||
ignore = [ | ||
"CPY001", # (Missing copyright notice at top of file) - No license | ||
] | ||
|
@@ -47,4 +67,6 @@ ignore = [ | |
convention = "numpy" | ||
|
||
[tool.coverage.run] | ||
source = ["crazylibs"] | ||
source = [ | ||
"crazylibs", | ||
] |
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 |
---|---|---|
@@ -1,34 +1,37 @@ | ||
"""CLI app definition.""" | ||
|
||
from random import choice | ||
import random | ||
from pathlib import Path | ||
from typing import Annotated | ||
|
||
import typer | ||
|
||
app = typer.Typer() | ||
|
||
|
||
@app.command() | ||
def run_story() -> None: | ||
"""Fun!""" # noqa: D400 | ||
from crazylibs.stories import stories | ||
|
||
story = choice(stories) # noqa: S311 | ||
from .stories import run_story | ||
|
||
typer.echo(f'Welcome to "{story.title}"') | ||
typer.echo("") | ||
typer.echo("Please fill in the following words:") | ||
|
||
context = {} | ||
for index, question in story.questions.items(): | ||
context[index] = typer.prompt(question) | ||
|
||
text = story.template | ||
for index, item in context.items(): | ||
text = text.replace(f"({index})", item) | ||
app = typer.Typer() | ||
|
||
typer.echo("") | ||
typer.echo("Wow, what a good selection of words!") | ||
typer.echo("Here is your story:") | ||
typer.echo("") | ||
|
||
typer.echo(text) | ||
@app.command(help="A variation of the 'Mad Libs' games.") | ||
def run_story_command( | ||
story_file_name: Annotated[ | ||
str | None, | ||
typer.Argument( | ||
help="The name of the story to run, without the .txt extension", | ||
), | ||
] = None, | ||
) -> None: | ||
"""Run a story.""" | ||
stories_folder = Path("stories") | ||
if not stories_folder.exists(): | ||
typer.echo("No stories folder found. Exiting.") | ||
raise typer.Exit(code=1) | ||
|
||
if story_file_name: | ||
story_path = stories_folder.joinpath(f"{story_file_name}.txt") | ||
if not story_path.exists(): | ||
typer.echo(f"Story file {story_file_name} not found. Exiting.") | ||
raise typer.Exit(code=1) | ||
else: | ||
story_path = random.choice(list(stories_folder.glob("*.txt"))) # noqa: S311 | ||
|
||
run_story(story_path) |
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,38 @@ | ||
"""Story functions.""" | ||
|
||
from pathlib import Path | ||
|
||
import typer | ||
|
||
|
||
def run_story(story_file: Path) -> None: | ||
"""Run a story.""" | ||
story_text = Path(story_file).read_text() | ||
raw_title, questions_block, template = story_text.split("---") | ||
|
||
title = raw_title.strip() | ||
|
||
question_rows = questions_block.strip().split("\n") | ||
questions = {} | ||
for row in question_rows: | ||
index, question = row.split(":") | ||
questions[index] = question.strip() | ||
|
||
typer.echo(f'Welcome to "{title}"') | ||
typer.echo("") | ||
typer.echo("Please fill in the following words:") | ||
|
||
context = {} | ||
for index, question in questions.items(): | ||
context[index] = typer.prompt(question) | ||
|
||
text = template | ||
for index, item in context.items(): | ||
text = text.replace(f"({index})", item) | ||
|
||
typer.echo("") | ||
typer.echo("Wow, what a good selection of words!") | ||
typer.echo("Here is your story:") | ||
typer.echo("") | ||
|
||
typer.echo(text) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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