Skip to content

Commit

Permalink
feat: Fix Broken Documentation build (#22)
Browse files Browse the repository at this point in the history
Fix errors at building the Documentaiton
Add an -V flag to get the current tfutility version
Improve the pyproject.toml
Try to Build the Documentation also at development commits
  • Loading branch information
eieste authored Nov 15, 2024
2 parents fce0c28 + c853f5e commit 370afb3
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/release.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ echo $1
echo $2

echo "Replace Version inside tfutility"
echo "__version__=\"$2\"" > src/tfutility/__init__.py
echo "__version__= \"$2\"" > src/tfutility/__init__.py

echo "Replace Docker image Reference inside README.md"
sed -i "s/tfutility:$1/tfutility:$1/" README.md
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ jobs:
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
pip install -r requirements-dev.txt
pip install .
pip3 install '.[dev]'
pip3 install .
- name: Sphinx build
run: |
cd docs
make html
make html SPHINXOPTS="-W"
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
Expand Down
25 changes: 22 additions & 3 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ on: [push]

jobs:


docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip3 install '.[dev]'
pip3 install .
- name: Sphinx build
run: |
cd docs
sphinx-build --version
make html SPHINXOPTS="-W"

pre-commit:
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -40,8 +58,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install -e .
pip3 install '.[dev]'
pip3 install .
- name: Test with pytest
run: |
pip install pytest pytest-cov
Expand All @@ -66,5 +84,6 @@ jobs:
# You can test your matrix by printing the current Python version
- name: Test Install
run: |
pip3 install .;
pip3 install '.[dev]'
pip3 install .
tfutility --help
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ ENV PS1="\[\e[0;33m\]|> tfutility <| \[\e[1;35m\]\W\[\e[0m\] \[\e[0m\]# "

WORKDIR /src
COPY . /src
RUN pip install --no-cache-dir -r requirements.txt \
&& python setup.py install
RUN pip install --no-cache-dir .
WORKDIR /
ENTRYPOINT ["tfutility"]
Empty file added docs/source/_static/.gitkeep
Empty file.
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'TF-Utils'
project = 'TfUtility'
copyright = '2024, Stefan Eiermann'
author = 'Stefan Eiermann'

Expand All @@ -16,6 +16,7 @@
extensions = [
'sphinxarg.ext',
'sphinx.ext.autodoc',
'sphinx_toolbox.pre_commit'

]

Expand Down
43 changes: 40 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,48 @@ dynamic = ["version"]
readme = { file = 'README.md', content-type = 'text/markdown' }
license = { file = 'LICENSE' }
authors = [{ name = "Stefan Eiermann", email = "stefan.eiermann@eneka.de" }]
dependencies = ["python-hcl2"]
dependencies = [
"python-hcl2==4.3.5"
]
classifiers = [
"Development Status :: 4 - Beta",
# Indicate who your project is intended for
"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Topic :: Software Development :: Build Tools",

# Pick your license as you wish (see also "license" above)
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",

# Specify the Python versions you support here
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]

[tool.setuptools]
packages = ["tfutility"]
package-dir = {"" = "src"}

[tool.setuptools.dynamic]
version = {attr = "tfutility.__version__"}


[project.optional-dependencies]
dev = ["pre-commit", "sphinx-autobuild", "coverage", "pytest", "pytest-mock", "pre-commit", "sphinx-argparse"]
docs = ["sphinx", "sphinx-rtd-theme"]
dev = [
"pytest==8.3.3",
"pytest-mock==3.14.0",
"pytest-cov==6.0.0",
"coverage==7.6.6",
"pre_commit==4.0.1",
"sphinx==8.1.3",
"sphinx-argparse==0.5.2",
"sphinx-autobuild==2024.10.3",
"sphinx-toolbox==3.8.1",
"sphinx-rtd-theme==3.0.2",
"setuptools>=70.0.0"
]

[tool.black]
line-length = 88
Expand Down Expand Up @@ -62,3 +91,11 @@ source = ["."]

[project.scripts]
tfutility = "tfutility.main:main"



[project.urls]
Homepage = "https://github.com/eieste/tfutility/"
Documentation = "https://eieste.github.io/tfutility/"
Repo = "https://github.com/eieste/tfutility"
Issues = "https://github.com/eieste/tfutility/issues"
14 changes: 0 additions & 14 deletions requirements-dev.txt

This file was deleted.

2 changes: 0 additions & 2 deletions requirements.txt

This file was deleted.

3 changes: 0 additions & 3 deletions setup.cfg

This file was deleted.

22 changes: 0 additions & 22 deletions setup.py

This file was deleted.

7 changes: 7 additions & 0 deletions src/tfutility/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import argparse
import logging
import sys
from collections import namedtuple

import tfutility
from tfutility.controllers.blockdate import ImportDateHandler, MovedDateHandler
from tfutility.controllers.forcedremotesource import ForcedRemoteSourceHandler
from tfutility.controllers.sourceswap import SourceSwapHandler
Expand Down Expand Up @@ -64,6 +66,7 @@ def add_arguments(self, parser: argparse.ArgumentParser) -> argparse.ArgumentPar
:return: the main argparser with attached global arguments
"""
parser.add_argument("--verbose", "-v", action="count", default=1)
parser.add_argument("-V", "--version", action="store_true")
return parser

def _handle(self, options: argparse.Namespace):
Expand All @@ -82,6 +85,10 @@ def _handle(self, options: argparse.Namespace):
datefmt="%Y-%m-%d %H:%M:%S",
)

if options.version:
print(tfutility.__version__)
sys.exit(0)

# find command which is used by user
for name, handler in self.commands.items():
if handler.handler_obj.itsme(options):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import re

from tfutility.main import main

VESION_REGEX = re.compile(r"^(\d+\.)?(\d+\.)?(\*|\d+)$")


def test_empty(capsys, mocker):
mocker.patch("sys.argv", ["tfutility"])
tfdo = mocker.patch("tfutility.main.TfUtility.do")
main()
captured = capsys.readouterr()
assert captured.out == ""
assert tfdo.call_count == 1


def test_version(capsys, mocker):
mocker.patch("sys.argv", ["tfutility", "-V"])
sysexit = mocker.patch("sys.exit")
main()
captured = capsys.readouterr()
assert VESION_REGEX.match(captured.out) is not None
assert sysexit.call_count == 1

0 comments on commit 370afb3

Please sign in to comment.