From fce3b4634322986438c9d4a0ee033b717ce9a7d3 Mon Sep 17 00:00:00 2001 From: kjaymiller Date: Sun, 10 Dec 2023 16:28:16 -0500 Subject: [PATCH 1/7] initial commit --- .github/workflows/lint.yml | 56 +++++++++++++++ .github/workflows/publish.yml | 33 +++++++++ .github/workflows/test.yml | 46 ++++++++++++ CODE_OF_CONDUCT.md | 131 ++++++++++++++++++++++++++++++++++ pyproject.toml | 44 ++++++++++++ 5 files changed, 310 insertions(+) create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/test.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 pyproject.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..199ac0a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,56 @@ +name: Format and Lint with Ruff and MarkdownLint +on: + pull_request: + branches: [main] + workflow_dispatch: +permissions: + contents: write + pull-requests: write +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: "3.12" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + # Update output format to enable automatic inline annotations. + - name: Run Ruff + run: | + ruff check --fix --output-format=github src + ruff format src + + - name: Markdown Lint base-files + uses: DavidAnson/markdownlint-cli2-action@v14 + with: + fix: true + globs: | + *.md + .github/**/*.md + continue-on-error: true + - name: Markdown Lint Docs + uses: DavidAnson/markdownlint-cli2-action@v14 + with: + fix: true + globs: docs/**/*.md + config: docs/.markdownlint.json + continue-on-error: true + - name: Commit changes + run: | + if [ -n "$(git status --porcelain)" ]; then + git config --global user.name "Ruff" + git config --global user.email "ruff-action@users.noreply.github.com" + git add -A + git commit -m "Format and lint with Ruff" + git push origin HEAD:${{ github.event.pull_request.head.ref }} + fi + + + diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..6ff1539 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Build distribution + +on: + release: + types: [created] + +jobs: + test: + uses: ./.github/workflows/test.yml + deploy: + needs: test + name: Deploy to PyPI + runs-on: ubuntu-latest + steps: + - name: Checkout source + uses: actions/checkout@v4 + + - name: Set up Python 3.11 + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Install build dependencies + run: python -m pip install build twine + + - name: Build distributions + run: python -m build + + - name: Publish package to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.TWINE_PASSWORD}} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..51dde5f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,46 @@ +name: PyTest +on: + workflow_call: + workflow_dispatch: + push: + branches: + - main + pull_request: + paths: + - 'src/**' + +jobs: + test-against-matrix: + # Only test all the supported versions when a pull request is made or the workflow is called + if: ${{github.event_name == 'workflow_call'}} || ${{github.event_name == 'pull_request'}} + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ['3.10', '3.11'] + fail-fast: true + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install requirements + run: | + python -m pip install -e .[dev] + - name: Run tests + run: | + python -m pytest + + test-against-latest: + # Always run against the latest version + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.12' + - name: Install requirements + run: | + python -m pip install -e .[dev] + - name: Run tests + run: | + python -m pytest diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..ea66489 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,131 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at kjaymiller@gmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. + +[homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..d3f84f1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,44 @@ +[build-system] +requires = ["setuptools", "setuptools_scm", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "render_engine_parsers" +dynamic = ["version"] +description = "Parser System for Render Engine" +readme = "README.md" +requires-python = ">=3.10" +dependencies = [ + "python-frontmatter", +] + +[project.optional-dependencies] +dev = [ + "pytest", + "pytest-cov", + "ruff", + ] + + +[tool.setuptools_scm] +local_scheme = "no-local-version" +# version_scheme = "python-simplified-semver" + +[project.urls] +homepage = "https://github.com/kjaymiller/render_engine/" +repository = "https://github.com/kjaymiller/render_engine/" +documentation = "https://render-engine.readthedocs.io/en/latest/" + +[tool.pytest.ini_options] +addopts = "-ra -q --cov" + +[tool.semantic_release] +version_toml = "pyproject.toml:project.version" +branch = "main" + +[tool.ruff] +select = ["E", "F", "I", "UP"] +target-version = "py311" +line-length = 120 +src = ["src"] +ignore-init-module-imports = true \ No newline at end of file From 92d52be47e61c20701e39975cfc8c5d29be8483b Mon Sep 17 00:00:00 2001 From: kjaymiller Date: Sun, 10 Dec 2023 16:30:43 -0500 Subject: [PATCH 2/7] add base parsers --- README.md | 9 +++- render-engine-parser/README.md | 5 +++ render-engine-parser/__init__.py | 3 ++ render-engine-parser/base_parsers.py | 61 ++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 render-engine-parser/README.md create mode 100644 render-engine-parser/__init__.py create mode 100644 render-engine-parser/base_parsers.py diff --git a/README.md b/README.md index 019c259..408ab2e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,9 @@ -# render-engine-parsers +# Render Engine Parsers + The page parser system used for making content for Render Engine + +## Parsers + +Parsers are used to parse the content of a page and convert it to HTML. The parser is specified in the page attributes as `Parser`. + +The default parser is the `BasePageParser` which processes markdown and passes the content thru as plain text. diff --git a/render-engine-parser/README.md b/render-engine-parser/README.md new file mode 100644 index 0000000..dc443be --- /dev/null +++ b/render-engine-parser/README.md @@ -0,0 +1,5 @@ +# Parsers + +Parsers are used to parse the content of a page and convert it to HTML. The parser is specified in the page attributes as `Parser`. + +The default parser is [`markdown`](markdown/README.md). diff --git a/render-engine-parser/__init__.py b/render-engine-parser/__init__.py new file mode 100644 index 0000000..f31c936 --- /dev/null +++ b/render-engine-parser/__init__.py @@ -0,0 +1,3 @@ +from .base_parsers import BasePageParser + +__all__ = ["BasePageParser"] diff --git a/render-engine-parser/base_parsers.py b/render-engine-parser/base_parsers.py new file mode 100644 index 0000000..4f11976 --- /dev/null +++ b/render-engine-parser/base_parsers.py @@ -0,0 +1,61 @@ +# ruff: noqa: F821 + +import pathlib + +import frontmatter + + +def parse_content(content: str) -> tuple[dict, str]: + """Fetching content and atttributes from a content_path""" + p = frontmatter.parse(content) + return p + + +class BasePageParser: + """ + The default Parser for Page objects. + This yields attributes and content using frontmatter. + The content is not modified. + """ + + @staticmethod + def parse_content_path(content_path: str) -> tuple[dict, str]: + """ + Fetches content from `Page.content_path` and sets attributes. + + This is a separate method so that it can be overridden by subclasses. + + params: + content_path: + The path to the file that will be used to generate the Page's `content`. + Should be a valid path to a file or a url. + """ + return parse_content(pathlib.Path(content_path).read_text()) + + @staticmethod + def parse_content(content: str) -> tuple[dict, str]: + """ + Fetches content from `Page.content` and returns attributes and content. + + This is a separate method so that it can be overridden by subclasses. + + params: + content: + The path to the file that will be used to generate the Page's `content`. + Should be a valid path to a file or a url. + """ + + return parse_content(content) + + @staticmethod + def parse(content: str, page: "Page" = None): + """ + Parses content to be rendered into HTML + + In the base parser, this returns the content as is. + + params: + content: content to be rendered into HTML + page: Page object to gain access to attributes + """ + return content From a8b201d974b54647bec0fbf7157e064d74fa2b94 Mon Sep 17 00:00:00 2001 From: kjaymiller Date: Sun, 10 Dec 2023 16:32:48 -0500 Subject: [PATCH 3/7] update base_parsers --- render-engine-parser/base_parsers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render-engine-parser/base_parsers.py b/render-engine-parser/base_parsers.py index 4f11976..f923fde 100644 --- a/render-engine-parser/base_parsers.py +++ b/render-engine-parser/base_parsers.py @@ -48,7 +48,7 @@ def parse_content(content: str) -> tuple[dict, str]: return parse_content(content) @staticmethod - def parse(content: str, page: "Page" = None): + def parse(content: str, page = None): """ Parses content to be rendered into HTML @@ -56,6 +56,6 @@ def parse(content: str, page: "Page" = None): params: content: content to be rendered into HTML - page: Page object to gain access to attributes + page: Render Engine Page Content object to gain access to attributes """ return content From 86f04c59eaf7b03a8b2328dabc3f6494ef665d6a Mon Sep 17 00:00:00 2001 From: kjaymiller Date: Sun, 10 Dec 2023 16:34:36 -0500 Subject: [PATCH 4/7] fixes lint update --- .github/workflows/lint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 199ac0a..f1139bc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,7 +24,8 @@ jobs: # Update output format to enable automatic inline annotations. - name: Run Ruff run: | - ruff check --fix --output-format=github src + ruff check --fix --output-format=github render-engine-parser + ruff format src - name: Markdown Lint base-files From cf20a23d4872f4d8388ef3f84eb852cf06e1272e Mon Sep 17 00:00:00 2001 From: kjaymiller Date: Sun, 10 Dec 2023 16:39:31 -0500 Subject: [PATCH 5/7] updates names for files --- .github/workflows/lint.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index f1139bc..4874ed3 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,9 +24,9 @@ jobs: # Update output format to enable automatic inline annotations. - name: Run Ruff run: | - ruff check --fix --output-format=github render-engine-parser - - ruff format src + ruff check --fix --output-format=github render_engine_parser + + ruff format render_engine_parser - name: Markdown Lint base-files uses: DavidAnson/markdownlint-cli2-action@v14 From a18f8b5df4f72023a7588f87d5a9c3ea8e07b5ec Mon Sep 17 00:00:00 2001 From: kjaymiller Date: Sun, 10 Dec 2023 16:39:42 -0500 Subject: [PATCH 6/7] move files --- {render-engine-parser => render_engine_parser}/README.md | 0 {render-engine-parser => render_engine_parser}/__init__.py | 0 {render-engine-parser => render_engine_parser}/base_parsers.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {render-engine-parser => render_engine_parser}/README.md (100%) rename {render-engine-parser => render_engine_parser}/__init__.py (100%) rename {render-engine-parser => render_engine_parser}/base_parsers.py (100%) diff --git a/render-engine-parser/README.md b/render_engine_parser/README.md similarity index 100% rename from render-engine-parser/README.md rename to render_engine_parser/README.md diff --git a/render-engine-parser/__init__.py b/render_engine_parser/__init__.py similarity index 100% rename from render-engine-parser/__init__.py rename to render_engine_parser/__init__.py diff --git a/render-engine-parser/base_parsers.py b/render_engine_parser/base_parsers.py similarity index 100% rename from render-engine-parser/base_parsers.py rename to render_engine_parser/base_parsers.py From 95ea6718fbdaa54292cf33685a723adbb6c4c91f Mon Sep 17 00:00:00 2001 From: Ruff Date: Sun, 10 Dec 2023 21:40:01 +0000 Subject: [PATCH 7/7] Format and lint with Ruff --- CODE_OF_CONDUCT.md | 4 ++-- render_engine_parser/base_parsers.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index ea66489..a687633 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -59,7 +59,7 @@ representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at kjaymiller@gmail.com. +reported to the community leaders responsible for enforcement at . All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the @@ -128,4 +128,4 @@ For answers to common questions about this code of conduct, see the FAQ at [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html [Mozilla CoC]: https://github.com/mozilla/diversity [FAQ]: https://www.contributor-covenant.org/faq -[translations]: https://www.contributor-covenant.org/translations \ No newline at end of file +[translations]: https://www.contributor-covenant.org/translations diff --git a/render_engine_parser/base_parsers.py b/render_engine_parser/base_parsers.py index f923fde..54b00a5 100644 --- a/render_engine_parser/base_parsers.py +++ b/render_engine_parser/base_parsers.py @@ -48,7 +48,7 @@ def parse_content(content: str) -> tuple[dict, str]: return parse_content(content) @staticmethod - def parse(content: str, page = None): + def parse(content: str, page=None): """ Parses content to be rendered into HTML