Skip to content

Commit

Permalink
fix badges build
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelloPerathoner committed Sep 24, 2023
1 parent 599ffff commit aadea9a
Show file tree
Hide file tree
Showing 22 changed files with 89 additions and 88 deletions.
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

ENV=.venv
BIN=$(ENV)/bin/
DIRS=src/ tests/unit/ tests/performance/ scripts/ docs/
DIRS=src/ tests/ scripts/ docs/
BROWSER=firefox
PYTEST=pytest --doctest-modules --doctest-glob="*.rst" --doctest-ignore-import-errors

Expand Down Expand Up @@ -38,23 +38,20 @@ coverage:
$(BIN)coverage erase
$(BIN)coverage run --branch --source=src -m $(PYTEST) tests/
$(BIN)coverage run --append --branch --source=src -m $(PYTEST) --debug-mode tests/
$(BIN)coverage report
$(BIN)coverage html
$(BROWSER) htmlcov/index.html
$(BIN)coverage json -o - | $(BIN)python tests/make_coverage_badge.py > docs/_images/badge-coverage.svg

profile:
$(BIN)python -O -m scripts.profile

docs:
cd docs; make html

badges: test coverage
$(BIN)python docs/make_badges.py

tox:
$(BIN)tox

dist: clean test coverage badges
dist: clean tox coverage docs
$(BIN)python -m build
$(BIN)twine check dist/*

Expand All @@ -72,5 +69,6 @@ uninstall:

clean:
-rm -rf dist build *.egg-info
-rm docs/_images/badge*.svg
-rm *~ .*~ pylintgraph.dot
-find . -name __pycache__ -type d -exec rm -r "{}" \;
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
A Generalized Suffix Tree
===========================

.. |py39| image:: docs/_images/tox-py39.svg
.. |py39| image:: docs/_images/badge-py39.svg

.. |py310| image:: docs/_images/tox-py310.svg
.. |py310| image:: docs/_images/badge-py310.svg

.. |py311| image:: docs/_images/tox-py311.svg
.. |py311| image:: docs/_images/badge-py311.svg

.. |py312| image:: docs/_images/tox-py312.svg
.. |py312| image:: docs/_images/badge-py312.svg

.. |pypy39| image:: docs/_images/tox-pypy39.svg
.. |pypy39| image:: docs/_images/badge-pypy39.svg

.. |coverage| image:: docs/_images/coverage.svg
.. |coverage| image:: docs/_images/badge-coverage.svg

|py39| |py310| |py311| |py312| |pypy39| |coverage|

Expand Down
1 change: 1 addition & 0 deletions docs/_build/_images/badge-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file modified docs/_build/doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/_build/searchindex.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/_images/badge-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_images/badge-py310.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_images/badge-py311.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_images/badge-py312.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/_images/badge-py39.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion docs/_images/tox-py.svg

This file was deleted.

64 changes: 0 additions & 64 deletions docs/make_badges.py

This file was deleted.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ skip_missing_interpreters = True
[testenv]
allowlist_externals = make
deps = pytest
deps =
pytest
requests
commands = make BIN= test
"""
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ blackdoc
build
coverage[toml]
mypy
lxml
pydocstyle
pylint
pytest
requests
sphinx
sphinx-rtd-theme
toml
tox
types-requests
twine
49 changes: 42 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys

import pytest
import requests

from suffix_tree import Tree, util

Expand All @@ -19,6 +20,7 @@ def tree():
}
)


@pytest.fixture()
def debug_dot_mode():
"""This fixture turns on debug dot mode."""
Expand All @@ -27,33 +29,66 @@ def debug_dot_mode():
util.DEBUG_DOT = False


if sys.version_info >= (3,9):
if sys.version_info >= (3, 9):

class DebugAction(argparse.BooleanOptionalAction):
"""This action turns on the DEBUG flags so we get coverage of the debug code."""

def __call__(self, parser, namespace, values, option_string=None):
if option_string in self.option_strings:
util.DEBUG = True
util.DEBUG_LABELS = True
# do not turn on DEBUG_DOT, it would run too slow. we test it in test_dot
# do not turn on DEBUG_DOT, it would run too slow.
# we test it in test_dot

else:

class DebugAction(argparse.Action):
"""This action turns on the DEBUG flags so we get coverage of the debug code."""

def __init__(self, option_strings, dest, nargs=None, **kwargs):
if nargs is not None:
raise ValueError("nargs not allowed")
super().__init__(option_strings, dest, **kwargs)

def __call__(self, parser, namespace, values, option_string=None):
if option_string in self.option_strings:
util.DEBUG = True
util.DEBUG_LABELS = True
# do not turn on DEBUG_DOT, it would run too slow. we test it in test_dot

# do not turn on DEBUG_DOT, it would run too slow.
# we test it in test_dot


def pytest_addoption(parser):
parser.addoption(
"--performance", action="store_true", help="run performance tests"
)
parser.addoption("--performance", action="store_true", help="run performance tests")
parser.addoption(
"--debug-mode", action=DebugAction, help="turn on DEBUG mode while testing"
)


def pytest_sessionfinish(session, exitstatus):
"""Hook called after whole test run finished, right before returning
the exit status to the system."""

DESTDIR = "docs/" # physical

if sys.implementation.name == "pypy":
py = "pypy"
else:
py = "py"
if exitstatus == 0:
status = "passing"
color = "success"
else:
status = "failed"
color = "critical"
name = f"{py}{sys.version_info.major}{sys.version_info.minor}"

badge = requests.get(
f"https://img.shields.io/badge/{name}-{status}-{color}"
).text

filename = f"_images/badge-{name}.svg"
with open(f"{DESTDIR}{filename}", "w") as dest:
dest.write(badge)
print(f"{filename}")
24 changes: 24 additions & 0 deletions tests/make_coverage_badge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!python3

import json
import sys

import requests

# shields_io_colors = ["success", "important", "critical", "informational", "inactive"]

if __name__ == "__main__":
j = json.load(sys.stdin)
coverage = j["totals"]["percent_covered_display"]

cov = int(coverage)
if cov > 95:
color = "success"
elif cov > 75:
color = "important"
else:
color = "critical"

print(requests.get(
f"https://img.shields.io/badge/coverage-{cov}%-{color}"
).text)

0 comments on commit aadea9a

Please sign in to comment.