black format
This commit is contained in:
parent
247fd37560
commit
238319b9e1
5 changed files with 23 additions and 4 deletions
|
@ -1,2 +1,3 @@
|
||||||
import comfyrecipes.cli
|
import comfyrecipes.cli
|
||||||
|
|
||||||
comfyrecipes.cli.main()
|
comfyrecipes.cli.main()
|
||||||
|
|
|
@ -12,6 +12,7 @@ import comfyrecipes.parsing as parsing
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
|
|
||||||
class Builder:
|
class Builder:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.jinjaenv = jinja2.Environment(
|
self.jinjaenv = jinja2.Environment(
|
||||||
|
@ -140,6 +141,7 @@ class Builder:
|
||||||
for ing in rec.ingredients:
|
for ing in rec.ingredients:
|
||||||
results.append(ing.unit.name)
|
results.append(ing.unit.name)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
unitnamelists = self.foreach_recipe(collect_unitnames)
|
unitnamelists = self.foreach_recipe(collect_unitnames)
|
||||||
unitnamesset: Set[str] = set()
|
unitnamesset: Set[str] = set()
|
||||||
for unitnamelst in unitnamelists:
|
for unitnamelst in unitnamelists:
|
||||||
|
@ -163,6 +165,7 @@ class Builder:
|
||||||
for ing in rec.ingredients:
|
for ing in rec.ingredients:
|
||||||
results.append(ing.name)
|
results.append(ing.name)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
ingredientnamelists = self.foreach_recipe(collect_ingnames)
|
ingredientnamelists = self.foreach_recipe(collect_ingnames)
|
||||||
ingredientnamesset: Set[str] = set()
|
ingredientnamesset: Set[str] = set()
|
||||||
for ingredientnamelst in ingredientnamelists:
|
for ingredientnamelst in ingredientnamelists:
|
||||||
|
|
|
@ -27,7 +27,9 @@ def main() -> None:
|
||||||
|
|
||||||
parser_generate_ingredients = subparsers.add_parser("generate-ingredients")
|
parser_generate_ingredients = subparsers.add_parser("generate-ingredients")
|
||||||
parser_generate_ingredients.add_argument("directory", type=str)
|
parser_generate_ingredients.add_argument("directory", type=str)
|
||||||
parser_generate_ingredients.add_argument("--force", dest="force", action="store_true")
|
parser_generate_ingredients.add_argument(
|
||||||
|
"--force", dest="force", action="store_true"
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -48,13 +50,19 @@ def main() -> None:
|
||||||
pass
|
pass
|
||||||
elif args.subcommand == "generate-units":
|
elif args.subcommand == "generate-units":
|
||||||
if not args.force and os.path.isfile(args.directory + "/units.yaml"):
|
if not args.force and os.path.isfile(args.directory + "/units.yaml"):
|
||||||
print("units.yaml already exists, pass --force if you want to overwrite it", file=sys.stderr)
|
print(
|
||||||
|
"units.yaml already exists, pass --force if you want to overwrite it",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
ret = 1
|
ret = 1
|
||||||
else:
|
else:
|
||||||
builder.generate_units()
|
builder.generate_units()
|
||||||
elif args.subcommand == "generate-ingredients":
|
elif args.subcommand == "generate-ingredients":
|
||||||
if not args.force and os.path.isfile(args.directory + "/ingredients.yaml"):
|
if not args.force and os.path.isfile(args.directory + "/ingredients.yaml"):
|
||||||
print("ingredients.yaml already exists, pass --force if you want to overwrite it", file=sys.stderr)
|
print(
|
||||||
|
"ingredients.yaml already exists, pass --force if you want to overwrite it",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
ret = 1
|
ret = 1
|
||||||
else:
|
else:
|
||||||
builder.generate_ingredients()
|
builder.generate_ingredients()
|
||||||
|
|
|
@ -6,6 +6,7 @@ ISSUE_DUPLICATE_UNITS = "duplicate-units"
|
||||||
ISSUE_KNOWN_PRICE_UNKNOWN_CONVERSION = "known-price-unknown-conversion"
|
ISSUE_KNOWN_PRICE_UNKNOWN_CONVERSION = "known-price-unknown-conversion"
|
||||||
ISSUE_UNKNOWN_UNIT = "unknown-unit"
|
ISSUE_UNKNOWN_UNIT = "unknown-unit"
|
||||||
|
|
||||||
|
|
||||||
class Issue:
|
class Issue:
|
||||||
def __init__(self, id: str, msg: str) -> None:
|
def __init__(self, id: str, msg: str) -> None:
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|
|
@ -68,6 +68,7 @@ class Context:
|
||||||
jsonschema.validate(instance=settingsdct, schema=settingsschema)
|
jsonschema.validate(instance=settingsdct, schema=settingsschema)
|
||||||
self.settings.load(settingsdct)
|
self.settings.load(settingsdct)
|
||||||
|
|
||||||
|
|
||||||
class Element:
|
class Element:
|
||||||
def __init__(self, ctx: Context) -> None:
|
def __init__(self, ctx: Context) -> None:
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
|
@ -76,6 +77,7 @@ class Element:
|
||||||
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
||||||
return cls(ctx)
|
return cls(ctx)
|
||||||
|
|
||||||
|
|
||||||
class Unit(Element):
|
class Unit(Element):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -119,7 +121,6 @@ class Unit(Element):
|
||||||
self.conversions = conversions
|
self.conversions = conversions
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AUnits:
|
class AUnits:
|
||||||
def __init__(self, ctx: Context) -> None:
|
def __init__(self, ctx: Context) -> None:
|
||||||
self.ctx = ctx
|
self.ctx = ctx
|
||||||
|
@ -171,6 +172,7 @@ class Units(AUnits):
|
||||||
f"units.yaml: {unitname} should only have one entry, found {num}",
|
f"units.yaml: {unitname} should only have one entry, found {num}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class IngredientInstance(Element):
|
class IngredientInstance(Element):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -236,6 +238,7 @@ class IngredientInstance(Element):
|
||||||
price=price,
|
price=price,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class StepSection(Element):
|
class StepSection(Element):
|
||||||
def __init__(self, ctx: Context, title: str, steps: List[str]) -> None:
|
def __init__(self, ctx: Context, title: str, steps: List[str]) -> None:
|
||||||
self.title = title
|
self.title = title
|
||||||
|
@ -245,6 +248,7 @@ class StepSection(Element):
|
||||||
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
||||||
return cls(ctx, dct["section"], dct["steps"])
|
return cls(ctx, dct["section"], dct["steps"])
|
||||||
|
|
||||||
|
|
||||||
class Recipe(Element):
|
class Recipe(Element):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -334,6 +338,7 @@ class Recipe(Element):
|
||||||
stepsections=stepsections,
|
stepsections=stepsections,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Conversion(Element):
|
class Conversion(Element):
|
||||||
def __init__(
|
def __init__(
|
||||||
self, ctx: Context, fromunit: Unit, tounit: Unit, ratio: float
|
self, ctx: Context, fromunit: Unit, tounit: Unit, ratio: float
|
||||||
|
@ -354,6 +359,7 @@ class Conversion(Element):
|
||||||
raise RuntimeError(f"unit {dct['to']} doesn't exist")
|
raise RuntimeError(f"unit {dct['to']} doesn't exist")
|
||||||
return cls(ctx, fromunit, tounit, dct["ratio"])
|
return cls(ctx, fromunit, tounit, dct["ratio"])
|
||||||
|
|
||||||
|
|
||||||
class Ingredient(Element):
|
class Ingredient(Element):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue