diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..104b53c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.mypy_cache/ +/.ruff_cache/ diff --git a/Makefile b/Makefile index 09a787a..e907fe7 100644 --- a/Makefile +++ b/Makefile @@ -4,3 +4,8 @@ build: run: build @cd dist && pipenv run python -m http.server + +lint: + @pipenv run black . + @pipenv run ruff . + @pipenv run mypy . diff --git a/Pipfile b/Pipfile index 00450c6..9b39f91 100644 --- a/Pipfile +++ b/Pipfile @@ -9,6 +9,7 @@ loguru = "*" [dev-packages] black = {extras = ["d"], version = "*"} +mypy = "*" ruff = "*" [requires] diff --git a/Pipfile.lock b/Pipfile.lock index d81d590..77d2c4d 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "b822c04b3fa63fe6c790438fd4e4506758278651094042a9bf6422eb1d11584e" + "sha256": "2290bdb941d004646f7ffb189cbbb929683b1045bff3a0ca1a35575f2acac230" }, "pipfile-spec": 6, "requires": { @@ -497,6 +497,38 @@ "markers": "python_version >= '3.7'", "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": { "hashes": [ "sha256:4392f6c0eb8a5668a69e23d168ffa70f0be9ccfd32b5cc2d26a34ae5b844552d", @@ -552,6 +584,14 @@ "index": "pypi", "version": "==0.0.270" }, + "typing-extensions": { + "hashes": [ + "sha256:06006244c70ac8ee83fa8282cb188f697b8db25bc8b4df07be1873c43897060c", + "sha256:3a8b36f13dd5fdc5d1b16fe317f5668545de77fa0b8e02006381fd49d731ab98" + ], + "markers": "python_version >= '3.7'", + "version": "==4.6.2" + }, "yarl": { "hashes": [ "sha256:04ab9d4b9f587c06d801c2abfe9317b77cdf996c65a90d5e84ecc45010823571", diff --git a/config.json b/config.json index 09a1c76..4b57783 100644 --- a/config.json +++ b/config.json @@ -4,5 +4,6 @@ "t2-corail.html", "t3-azur.html", "contact.html" - ] + ], + "outDir": "dist" } \ No newline at end of file diff --git a/lib/config.py b/lib/config.py index 827fc4f..a2d6a5a 100644 --- a/lib/config.py +++ b/lib/config.py @@ -1,7 +1,12 @@ 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: - res = json.loads(f.read()) - return res["templates"] + return json.loads(f.read()) diff --git a/lib/engine.py b/lib/engine.py index 941c125..dc65976 100644 --- a/lib/engine.py +++ b/lib/engine.py @@ -1,9 +1,6 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape -engine = Environment( - loader=FileSystemLoader("templates"), - autoescape=select_autoescape(), -) +engine = Environment(loader=FileSystemLoader("templates"), autoescape=select_autoescape()) def render(template: str) -> str: diff --git a/lib/main.py b/lib/main.py index 0c39dd1..d571b9f 100644 --- a/lib/main.py +++ b/lib/main.py @@ -2,15 +2,16 @@ from os import path from loguru import logger -from lib.config import load_templates +from lib.config import load from lib.engine import render def main(): + config = load() logger.info("🏁 Start building site") - for template in load_templates(): + for template in config["templates"]: 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)) logger.info("🎉 Done…") diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..55d1681 --- /dev/null +++ b/pyproject.toml @@ -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"]