From 016facc067165b306091b0993788ac058a475813 Mon Sep 17 00:00:00 2001 From: jgrogan Date: Mon, 26 Aug 2024 16:37:57 +0100 Subject: [PATCH 1/5] Some initial project boilerplate --- README.md | 5 ++ pyproject.toml | 104 ++++++++++++++++++++++++++++++++++++++++ src/dialann/main_cli.py | 23 +++++++++ 3 files changed, 132 insertions(+) create mode 100644 pyproject.toml create mode 100644 src/dialann/main_cli.py diff --git a/README.md b/README.md index 4987ca0..06fe32a 100644 --- a/README.md +++ b/README.md @@ -2,5 +2,10 @@ This is a basic static site generator for my personal website. +To generate a site to: + +``` shell +dialann --build_dir $BUILD_DIR +``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ac97a31 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,104 @@ +[project] +name = "dialann" +version = "0.0.0" +authors = [ + { name="James Grogan", email="james@jmsgrogan.com" }, +] +description = "Simple static site generator." +readme = "README.md" +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 3 - Alpha", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + "Operating System :: OS Independent", + "Topic :: System :: Distributed Computing" +] +keywords = ["Publishing", "Technical Reports"] + +dependencies = ["markdown-it-py", + "mdit_py_plugins", + "mdformat", + "beautifulsoup4", + "pyspelling"] + +[project.urls] +Repository = "https://git.jmsgrogan.com/jgrogan/dialann" +Homepage = "https://git.jmsgrogan.com/jgrogan/dialann" + +[project.optional-dependencies] +test = [ + "pytest", + "pytest-cov", + "pytest-sugar", + "black", + "mypy", + "flake8", + "pylint" +] + +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[project.scripts] +dialann = "dialann.main_cli:main_cli" + +[tool.setuptools.package-data] +"dialann" = ["py.typed"] + +[tool.setuptools.packages.find] +where = ["src"] + +[tool.pytest.ini_options] +testpaths = ["test",] +log_cli = 1 +log_cli_level = "debug" +addopts = "--cov=dialann --cov-report term --cov-report xml:coverage.xml --cov-report html" + +[tool.mypy] +ignore_missing_imports = true + +[tool.tox] +legacy_tox_ini = """ +[tox] +requires = + tox>=4 +env_list = lint, type, style, py{311}, docs +skip_missing_interpreters = true + +[testenv] +description = run unit tests +deps = + pytest>=7 + pytest-cov + pytest-sugar +commands = + pytest {posargs:test} + +[testenv:lint] +description = run linters +skip_install = true +deps = + black +commands = black {posargs:src} + +[testenv:style] +description = run style check +skip_install = true +deps = + flake8 +commands = flake8 {posargs:src} + +[testenv:type] +description = run type checks +deps = + mypy>=0.991 +commands = + mypy {posargs:src test} + +[testenv:docs] +changedir = docs +deps = sphinx +commands = sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html +""" \ No newline at end of file diff --git a/src/dialann/main_cli.py b/src/dialann/main_cli.py new file mode 100644 index 0000000..62f39cd --- /dev/null +++ b/src/dialann/main_cli.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import argparse +import logging +from pathlib import Path + +logger = logging.getLogger(__name__) + +def generate(build_dir: Path): + + pass + +def main_cli(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--build_dir", + type=Path, + help="Path to the build output", + ) + args = parser.parse_args() + generate(args.build_dir) + +if __name__ == "__main__": + main_cli() From 3f341a054bdff3bfa61ab9faaca4d1494eea6552 Mon Sep 17 00:00:00 2001 From: jgrogan Date: Mon, 26 Aug 2024 16:40:00 +0100 Subject: [PATCH 2/5] Update gitignore --- .gitignore | 163 +---------------------------------------------------- 1 file changed, 1 insertion(+), 162 deletions(-) diff --git a/.gitignore b/.gitignore index 5d381cc..b694934 100644 --- a/.gitignore +++ b/.gitignore @@ -1,162 +1 @@ -# ---> Python -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - +.venv \ No newline at end of file From ed18ceb6a596f06956d51c390050dd7502a7b7e4 Mon Sep 17 00:00:00 2001 From: jgrogan Date: Mon, 26 Aug 2024 16:41:10 +0100 Subject: [PATCH 3/5] Add python ignore content --- .gitignore | 4 +++- src/dialann/site_generator.py | 0 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 src/dialann/site_generator.py diff --git a/.gitignore b/.gitignore index b694934..7a90478 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -.venv \ No newline at end of file +.venv +build/ +*.egg-info \ No newline at end of file diff --git a/src/dialann/site_generator.py b/src/dialann/site_generator.py new file mode 100644 index 0000000..e69de29 From 89ea1f6062570016bb6b56219112d4c88d338994 Mon Sep 17 00:00:00 2001 From: jgrogan Date: Mon, 26 Aug 2024 17:12:57 +0100 Subject: [PATCH 4/5] Simple site generation --- .gitignore | 3 ++- src/dialann/main_cli.py | 13 ++++++++++--- src/dialann/site_generator.py | 27 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 7a90478..d7c89e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .venv build/ -*.egg-info \ No newline at end of file +*.egg-info +__pycache__/ \ No newline at end of file diff --git a/src/dialann/main_cli.py b/src/dialann/main_cli.py index 62f39cd..1210337 100644 --- a/src/dialann/main_cli.py +++ b/src/dialann/main_cli.py @@ -3,11 +3,14 @@ import argparse import logging from pathlib import Path +from .site_generator import SiteGenerator + logger = logging.getLogger(__name__) -def generate(build_dir: Path): +def generate(source_dir:Path, build_dir: Path): - pass + generator = SiteGenerator(source_dir, build_dir) + generator.run() def main_cli(): parser = argparse.ArgumentParser() @@ -16,8 +19,12 @@ def main_cli(): type=Path, help="Path to the build output", ) + parser.add_argument( + "--source_dir", type=Path, default=Path(), + help="Site source directory") + args = parser.parse_args() - generate(args.build_dir) + generate(args.source_dir, args.build_dir) if __name__ == "__main__": main_cli() diff --git a/src/dialann/site_generator.py b/src/dialann/site_generator.py index e69de29..d509ffa 100644 --- a/src/dialann/site_generator.py +++ b/src/dialann/site_generator.py @@ -0,0 +1,27 @@ +from pathlib import Path +import os + +from markdown_it import MarkdownIt + +class SiteGenerator(): + + def __init__(self, source_dir: Path, + build_dir: Path): + self.source_dir = source_dir + self.build_dir = build_dir + self.parser = MarkdownIt() + + def run(self): + + for md_file in self.source_dir.glob('**/*.md'): + with open(md_file, 'r', encoding='utf-8') as f: + md_src = f.read() + + html_path = self.build_dir / (str(md_file.stem) + ".html") + os.makedirs(html_path.parent, exist_ok=True) + + html_src = self.parser.render(md_src) + with open(html_path, 'w', encoding='utf-8') as f: + f.write(html_src) + + From 2524601616449e662e44e492b17040fd19c7734d Mon Sep 17 00:00:00 2001 From: jgrogan Date: Mon, 26 Aug 2024 17:26:45 +0100 Subject: [PATCH 5/5] Small gitignore change --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d7c89e0..26e87e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ .venv build/ *.egg-info -__pycache__/ \ No newline at end of file +__pycache__ \ No newline at end of file