Skip to content

Commit

Permalink
Run CI on Fedora
Browse files Browse the repository at this point in the history
Signed-off-by: Aurélien Bompard <[email protected]>
  • Loading branch information
abompard authored and sudhirbhoga committed Aug 22, 2023
1 parent ff614db commit bb2d9b6
Show file tree
Hide file tree
Showing 14 changed files with 562 additions and 556 deletions.
56 changes: 22 additions & 34 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@ jobs:
checks:
name: Checks
runs-on: ubuntu-latest
container: fedorapython/fedora-python-tox:latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install pre-commit
run: pip install pre-commit
run: dnf install -y pre-commit git

- name: Mark the working directory as safe for Git
run: git config --global --add safe.directory $PWD

- name: Run pre-commit checks
run: pre-commit run --all-files
Expand All @@ -31,39 +30,27 @@ jobs:
licenses:
name: Licenses
runs-on: ubuntu-latest
container: fedorapython/fedora-python-tox:latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install krb5-devel for python-gssapi
run: sudo apt-get install krb5-config libkrb5-dev

- name: Install tox
run: pip install tox
- name: Install RPM dependencies
run: |
dnf install -y krb5-devel libpq-devel
- name: Check licenses
run: tox -e licenses

docs:
name: Documentation
runs-on: ubuntu-latest
container: fedorapython/fedora-python-tox:latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install krb5-devel for python-gssapi
run: sudo apt-get install krb5-config libkrb5-dev

- name: Install tox
run: pip install tox
- name: Install RPM dependencies
run: |
dnf install -y krb5-devel libpq-devel
- name: Build the docs
run: tox -e docs
Expand All @@ -78,14 +65,16 @@ jobs:
unit_tests:
name: Unit tests
runs-on: ubuntu-latest
container: fedorapython/fedora-python-tox:latest
steps:
- uses: actions/checkout@v3

- name: Run unit tests with Tox
uses: fedora-python/tox-github-action@main
with:
tox_env: ${{ matrix.tox_env }}
dnf_install: krb5-devel libpq-devel
- name: Install RPM dependencies
run: |
dnf install -y krb5-devel libpq-devel
- name: Build the docs
run: tox -e ${{ matrix.tox_env }}

# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v1
Expand All @@ -98,6 +87,5 @@ jobs:
strategy:
matrix:
tox_env:
- py37
- py38
- py39
- py310
- py311
10 changes: 4 additions & 6 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ queue_rules:
- check-success=Checks
- check-success=Licenses
- check-success=Documentation
- check-success=Unit tests (py37)
- check-success=Unit tests (py38)
- check-success=Unit tests (py39)
- check-success=Unit tests (py310)
- check-success=Unit tests (py311)

pull_request_rules:
- name: Merge on approval
Expand All @@ -23,6 +22,5 @@ pull_request_rules:
- check-success=Checks
- check-success=Licenses
- check-success=Documentation
- check-success=Unit tests (py37)
- check-success=Unit tests (py38)
- check-success=Unit tests (py39)
- check-success=Unit tests (py310)
- check-success=Unit tests (py311)
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.6.0
rev: v3.9.0
hooks:
- id: pyupgrade
args:
- --py36-plus
- --py310-plus

- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
language_version: python3
Expand Down
72 changes: 15 additions & 57 deletions datagrepper/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@

import arrow
import datanommer.models as dm
import docutils
import docutils.examples
import flask
import jinja2
import markupsafe
import pygal
import pygments
import pygments.formatters
import pygments.lexers
from bs4 import BeautifulSoup as bs4
from flask import Flask
from flask_healthz import HealthError, healthz
from pkg_resources import get_distribution
from sphinx.cmd.build import main as sphinx_main
from werkzeug.exceptions import BadRequest

from datagrepper.util import (
Expand Down Expand Up @@ -131,74 +130,28 @@ def remove_session(exc):
dm.session.remove()


def modify_rst(rst):
"""Downgrade some of our rst directives if docutils is too old."""

try:
# The rst features we need were introduced in this version
minimum = [0, 9]
version = map(int, docutils.__version__.split("."))

# If we're at or later than that version, no need to downgrade
if version >= minimum:
return rst
except Exception:
# If there was some error parsing or comparing versions, run the
# substitutions just to be safe.
pass

# Otherwise, make code-blocks into just literal blocks.
substitutions = {
".. code-block:: javascript": "::",
}
for old, new in substitutions.items():
rst = rst.replace(old, new)

return rst


def modify_html(html):
"""Perform style substitutions where docutils doesn't do what we want."""

substitutions = {
'<tt class="docutils literal">': "<code>",
"</tt>": "</code>",
}
for old, new in substitutions.items():
html = html.replace(old, new)

return html


def preload_docs(endpoint):
"""Utility to load an RST file and turn it into fancy HTML."""

here = os.path.dirname(os.path.abspath(__file__))
default = os.path.join(here, "docs")
directory = app.config.get("DATAGREPPER_DOC_PATH", default)
fname = os.path.join(directory, endpoint + ".rst")
htmldocs = os.path.join(directory, "_build/html/")
args = ["-b", "html", "-c", default, default, htmldocs]
sphinx_main(args)
fname = os.path.join(htmldocs, endpoint + ".html")
with codecs.open(fname, "r", "utf-8") as f:
rst = f.read()

rst = modify_rst(rst)

api_docs = docutils.examples.html_body(rst)
api_docs = f.read()

api_docs = modify_html(api_docs)
soup = bs4(api_docs, "html.parser")
api_docs = soup.find("body").decode_contents()

api_docs = markupsafe.Markup(api_docs)
return api_docs


htmldocs = dict.fromkeys(["index", "reference", "widget", "charts"])
for key in htmldocs:
htmldocs[key] = preload_docs(key)


def load_docs(request):
URL = app.config.get("DATAGREPPER_BASE_URL", request.url_root)
docs = htmldocs[request.endpoint]
docs = jinja2.Template(docs).render(URL=URL)
docs = preload_docs(request.endpoint)
return markupsafe.Markup(docs)


Expand Down Expand Up @@ -248,6 +201,11 @@ def widget():
return flask.render_template("index.html", docs=load_docs(flask.request))


@app.route("/contributing.html")
def contributing():
return flask.render_template("index.html", docs=load_docs(flask.request))


@app.route("/raw", methods=["GET"], strict_slashes=False)
@app.route("/v2/search", methods=["GET"], strict_slashes=False)
def raw():
Expand Down
3 changes: 3 additions & 0 deletions datagrepper/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@


# -- General configuration ------------------------------------------------
rst_epilog = """
.. |URL| replace:: ``https://apps.fedoraproject.org/datagrepper/``
"""

# If your documentation needs a minimal Sphinx version, state it here.
#
Expand Down
Loading

0 comments on commit bb2d9b6

Please sign in to comment.