use config

This commit is contained in:
Ruidy 2023-05-28 12:49:03 +02:00
parent 0d4a7b43ec
commit 6974c67aee
9 changed files with 96 additions and 12 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/.mypy_cache/
/.ruff_cache/

View file

@ -4,3 +4,8 @@ build:
run: build run: build
@cd dist && pipenv run python -m http.server @cd dist && pipenv run python -m http.server
lint:
@pipenv run black .
@pipenv run ruff .
@pipenv run mypy .

View file

@ -9,6 +9,7 @@ loguru = "*"
[dev-packages] [dev-packages]
black = {extras = ["d"], version = "*"} black = {extras = ["d"], version = "*"}
mypy = "*"
ruff = "*" ruff = "*"
[requires] [requires]

42
Pipfile.lock generated
View file

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "b822c04b3fa63fe6c790438fd4e4506758278651094042a9bf6422eb1d11584e" "sha256": "2290bdb941d004646f7ffb189cbbb929683b1045bff3a0ca1a35575f2acac230"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -497,6 +497,38 @@
"markers": "python_version >= '3.7'", "markers": "python_version >= '3.7'",
"version": "==6.0.4" "version": "==6.0.4"
}, },
"mypy": {
"hashes": [
"sha256:1c4c42c60a8103ead4c1c060ac3cdd3ff01e18fddce6f1016e08939647a0e703",
"sha256:44797d031a41516fcf5cbfa652265bb994e53e51994c1bd649ffcd0c3a7eccbf",
"sha256:473117e310febe632ddf10e745a355714e771ffe534f06db40702775056614c4",
"sha256:4c99c3ecf223cf2952638da9cd82793d8f3c0c5fa8b6ae2b2d9ed1e1ff51ba85",
"sha256:550a8b3a19bb6589679a7c3c31f64312e7ff482a816c96e0cecec9ad3a7564dd",
"sha256:658fe7b674769a0770d4b26cb4d6f005e88a442fe82446f020be8e5f5efb2fae",
"sha256:6e33bb8b2613614a33dff70565f4c803f889ebd2f859466e42b46e1df76018dd",
"sha256:6e42d29e324cdda61daaec2336c42512e59c7c375340bd202efa1fe0f7b8f8ca",
"sha256:74bc9b6e0e79808bf8678d7678b2ae3736ea72d56eede3820bd3849823e7f305",
"sha256:76ec771e2342f1b558c36d49900dfe81d140361dd0d2df6cd71b3db1be155409",
"sha256:7d23370d2a6b7a71dc65d1266f9a34e4cde9e8e21511322415db4b26f46f6b8c",
"sha256:87df44954c31d86df96c8bd6e80dfcd773473e877ac6176a8e29898bfb3501cb",
"sha256:8c5979d0deb27e0f4479bee18ea0f83732a893e81b78e62e2dda3e7e518c92ee",
"sha256:95d8d31a7713510685b05fbb18d6ac287a56c8f6554d88c19e73f724a445448a",
"sha256:a22435632710a4fcf8acf86cbd0d69f68ac389a3892cb23fbad176d1cddaf228",
"sha256:a8763e72d5d9574d45ce5881962bc8e9046bf7b375b0abf031f3e6811732a897",
"sha256:c1eb485cea53f4f5284e5baf92902cd0088b24984f4209e25981cc359d64448d",
"sha256:c5d2cc54175bab47011b09688b418db71403aefad07cbcd62d44010543fc143f",
"sha256:cbc07246253b9e3d7d74c9ff948cd0fd7a71afcc2b77c7f0a59c26e9395cb152",
"sha256:d0b6c62206e04061e27009481cb0ec966f7d6172b5b936f3ead3d74f29fe3dcf",
"sha256:ddae0f39ca146972ff6bb4399f3b2943884a774b8771ea0a8f50e971f5ea5ba8",
"sha256:e1f4d16e296f5135624b34e8fb741eb0eadedca90862405b1f1fde2040b9bd11",
"sha256:e86c2c6852f62f8f2b24cb7a613ebe8e0c7dc1402c61d36a609174f63e0ff017",
"sha256:ebc95f8386314272bbc817026f8ce8f4f0d2ef7ae44f947c4664efac9adec929",
"sha256:f9dca1e257d4cc129517779226753dbefb4f2266c4eaad610fc15c6a7e14283e",
"sha256:faff86aa10c1aa4a10e1a301de160f3d8fc8703b88c7e98de46b531ff1276a9a"
],
"index": "pypi",
"version": "==1.3.0"
},
"mypy-extensions": { "mypy-extensions": {
"hashes": [ "hashes": [
"sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d", "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d",
@ -552,6 +584,14 @@
"index": "pypi", "index": "pypi",
"version": "==0.0.270" "version": "==0.0.270"
}, },
"typing-extensions": {
"hashes": [
"sha256:06006244c70ac8ee83fa8282cb188f697b8db25bc8b4df07be1873c43897060c",
"sha256:3a8b36f13dd5fdc5d1b16fe317f5668545de77fa0b8e02006381fd49d731ab98"
],
"markers": "python_version >= '3.7'",
"version": "==4.6.2"
},
"yarl": { "yarl": {
"hashes": [ "hashes": [
"sha256:04ab9d4b9f587c06d801c2abfe9317b77cdf996c65a90d5e84ecc45010823571", "sha256:04ab9d4b9f587c06d801c2abfe9317b77cdf996c65a90d5e84ecc45010823571",

View file

@ -4,5 +4,6 @@
"t2-corail.html", "t2-corail.html",
"t3-azur.html", "t3-azur.html",
"contact.html" "contact.html"
] ],
"outDir": "dist"
} }

View file

@ -1,7 +1,12 @@
import json import json
from typing import TypedDict
def load_templates(): class Config(TypedDict):
templates: list[str]
outDir: str
def load() -> Config:
with open("config.json", "r") as f: with open("config.json", "r") as f:
res = json.loads(f.read()) return json.loads(f.read())
return res["templates"]

View file

@ -1,9 +1,6 @@
from jinja2 import Environment, FileSystemLoader, select_autoescape from jinja2 import Environment, FileSystemLoader, select_autoescape
engine = Environment( engine = Environment(loader=FileSystemLoader("templates"), autoescape=select_autoescape())
loader=FileSystemLoader("templates"),
autoescape=select_autoescape(),
)
def render(template: str) -> str: def render(template: str) -> str:

View file

@ -2,15 +2,16 @@ from os import path
from loguru import logger from loguru import logger
from lib.config import load_templates from lib.config import load
from lib.engine import render from lib.engine import render
def main(): def main():
config = load()
logger.info("🏁 Start building site") logger.info("🏁 Start building site")
for template in load_templates(): for template in config["templates"]:
logger.info(f"📃Render '{template}'") logger.info(f"📃Render '{template}'")
with open(path.join("dist", template), "w") as f: with open(path.join(config["outDir"], template), "w") as f:
f.write(render(template)) f.write(render(template))
logger.info("🎉 Done…") logger.info("🎉 Done…")

32
pyproject.toml Normal file
View file

@ -0,0 +1,32 @@
[tool.black]
line-length = 120
[tool.isort]
profile = "black"
ignore_missing_imports = true
warn_unused_configs = true
no_implicit_optional = true
warn_unused_ignores = true
warn_unreachable = true
warn_redundant_casts = true
disallow_untyped_defs = true
[tool.ruff]
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"C", # flake8-comprehensions
"B", # flake8-bugbear
"T",
"I",
]
ignore = [
"E501", # line too long, handled by black
"B008", # do not perform function calls in argument defaults
"C901", # too complex
]
[tool.ruff.per-file-ignores]
#"__init__.py" = ["F401"]