From 4cf96638b81b03e4ac171cab3314f79767bdadd6 Mon Sep 17 00:00:00 2001 From: Maximilien Rigaut Date: Tue, 25 Jan 2022 02:41:03 +0100 Subject: [PATCH] Refactored the code for testing and packaging --- .github/workflows/python-app.yml | 15 +++---- pyproject.toml | 23 ++++++++++ requirements.txt | 3 +- requirements_dev.txt | 7 +++ setup.cfg | 45 +++++++++++++++++++ bparse.py => src/bootstraparse/bparse.py | 3 ++ .../bootstraparse/configs}/parser_config.yml | 0 .../bootstraparse/modules/__init__.py | 0 .../bootstraparse/modules}/config.py | 2 +- .../bootstraparse/modules}/context_mngr.py | 0 .../bootstraparse/modules}/error_mngr.py | 0 .../bootstraparse/modules}/export.py | 0 .../bootstraparse/modules}/parser.py | 0 .../bootstraparse/modules}/preparser.py | 0 .../bootstraparse/modules}/sitecrawler.py | 0 .../bootstraparse/modules}/sitecreator.py | 3 +- .../bootstraparse/modules}/template_mngr.py | 0 src/bootstraparse/templates/bootstrap.yml | 0 src/bootstraparse/testrun.py | 10 +++++ testrun.py | 5 --- tests/test_bparse.py | 7 +++ tox.ini | 29 ++++++++++++ 22 files changed, 136 insertions(+), 16 deletions(-) create mode 100644 pyproject.toml create mode 100644 requirements_dev.txt create mode 100644 setup.cfg rename bparse.py => src/bootstraparse/bparse.py (50%) rename {configs => src/bootstraparse/configs}/parser_config.yml (100%) rename templates/bootstrap.yml => src/bootstraparse/modules/__init__.py (100%) rename {modules => src/bootstraparse/modules}/config.py (91%) rename {modules => src/bootstraparse/modules}/context_mngr.py (100%) rename {modules => src/bootstraparse/modules}/error_mngr.py (100%) rename {modules => src/bootstraparse/modules}/export.py (100%) rename {modules => src/bootstraparse/modules}/parser.py (100%) rename {modules => src/bootstraparse/modules}/preparser.py (100%) rename {modules => src/bootstraparse/modules}/sitecrawler.py (100%) rename {modules => src/bootstraparse/modules}/sitecreator.py (97%) rename {modules => src/bootstraparse/modules}/template_mngr.py (100%) create mode 100644 src/bootstraparse/templates/bootstrap.yml create mode 100644 src/bootstraparse/testrun.py delete mode 100644 testrun.py create mode 100644 tests/test_bparse.py create mode 100644 tox.ini diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 4475a6c..36b4190 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -5,9 +5,9 @@ name: Python application on: push: - branches: [ main ] + branches: [ main, test ] pull_request: - branches: [ main ] + branches: [ main, test ] schedule: - cron: '0 6 * * *' @@ -16,8 +16,6 @@ jobs: build: runs-on: ubuntu-latest - env: - FIB_INPUT: 10 steps: - uses: actions/checkout@v2 @@ -29,13 +27,14 @@ jobs: run: | python -m pip install --upgrade pip pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + pip install -r requirements_dev.txt - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics -# - name: Test with pytest -# run: | -# pytest fibtest.py + - name: Test with pytest + run: | + pip install . + pytest . diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0fc3c6f --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,23 @@ +[build-system] +requires = ["setuptools>=42.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.pytest.ini_options] +addopts = "--cov=bootstraparse" +testpaths = [ + "tests", +] + +[tool.mypy] +mypy_path = "src" +check_untyped_defs = true +disallow_any_generics = true +ignore_missing_imports = true +no_implicit_optional = true +show_error_codes = true +strict_equality = true +warn_redundant_casts = true +warn_return_any = true +warn_unreachable = true +warn_unused_configs = true +no_implicit_reexport = true \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index ef9e486..988f73f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -pyyaml==6.0 \ No newline at end of file +pyyaml==6.0 +rich~=11.0.0 \ No newline at end of file diff --git a/requirements_dev.txt b/requirements_dev.txt new file mode 100644 index 0000000..ccf3513 --- /dev/null +++ b/requirements_dev.txt @@ -0,0 +1,7 @@ +flake8==4.0.1 +tox==3.24.3 +pytest==6.2.5 +pytest-cov==2.12.1 +mypy===0.910 +pyyaml==6.0 +rich~=11.0.0 \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..f3087f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,45 @@ +[metadata] +name = bootstraparse +description = A custom markdown parser for Bootstrap & Python +author = Vkyfox +license = Mozilla Public License Version 2.0 +license_file = LICENSE +platforms = unix, linux, osx, cygwin, win32 +classifiers = + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only + Programming Language :: Python :: 3.7 + Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 + +[options] +packages = + bootstraparse + bootstraparse.modules +install_requires = + pyyaml>=6.0 +python_requires = >=3.6 +package_dir = + =src + +zip_safe = no + +[options.packages.find] +where = + = src + = src/bootstraparse + +[options.extras_require] +testing = + flake8>=4.0.1 + tox>=3.24.3 + pytest>=6.2.5 + pytest-cov>=2.12.1 + mypy>==0.910 + pyyaml>=6.0 + +[options.package_data] +slapping = py.typed + +[flake8] +max-line-length = 160 \ No newline at end of file diff --git a/bparse.py b/src/bootstraparse/bparse.py similarity index 50% rename from bparse.py rename to src/bootstraparse/bparse.py index 28d80b8..a1385d8 100644 --- a/bparse.py +++ b/src/bootstraparse/bparse.py @@ -1 +1,4 @@ # Main program, use this to start parsing + +def totest(): + print("This is a test") \ No newline at end of file diff --git a/configs/parser_config.yml b/src/bootstraparse/configs/parser_config.yml similarity index 100% rename from configs/parser_config.yml rename to src/bootstraparse/configs/parser_config.yml diff --git a/templates/bootstrap.yml b/src/bootstraparse/modules/__init__.py similarity index 100% rename from templates/bootstrap.yml rename to src/bootstraparse/modules/__init__.py diff --git a/modules/config.py b/src/bootstraparse/modules/config.py similarity index 91% rename from modules/config.py rename to src/bootstraparse/modules/config.py index 1325a15..599a0b4 100644 --- a/modules/config.py +++ b/src/bootstraparse/modules/config.py @@ -32,4 +32,4 @@ class GlobalConfig(ConfigLoader): super().__init__(configfile) -conf = ConfigLoader("./example_userfiles/config/aliases.yml") +# conf = ConfigLoader("./example_userfiles/config/aliases.yml") diff --git a/modules/context_mngr.py b/src/bootstraparse/modules/context_mngr.py similarity index 100% rename from modules/context_mngr.py rename to src/bootstraparse/modules/context_mngr.py diff --git a/modules/error_mngr.py b/src/bootstraparse/modules/error_mngr.py similarity index 100% rename from modules/error_mngr.py rename to src/bootstraparse/modules/error_mngr.py diff --git a/modules/export.py b/src/bootstraparse/modules/export.py similarity index 100% rename from modules/export.py rename to src/bootstraparse/modules/export.py diff --git a/modules/parser.py b/src/bootstraparse/modules/parser.py similarity index 100% rename from modules/parser.py rename to src/bootstraparse/modules/parser.py diff --git a/modules/preparser.py b/src/bootstraparse/modules/preparser.py similarity index 100% rename from modules/preparser.py rename to src/bootstraparse/modules/preparser.py diff --git a/modules/sitecrawler.py b/src/bootstraparse/modules/sitecrawler.py similarity index 100% rename from modules/sitecrawler.py rename to src/bootstraparse/modules/sitecrawler.py diff --git a/modules/sitecreator.py b/src/bootstraparse/modules/sitecreator.py similarity index 97% rename from modules/sitecreator.py rename to src/bootstraparse/modules/sitecreator.py index 1044716..2296957 100644 --- a/modules/sitecreator.py +++ b/src/bootstraparse/modules/sitecreator.py @@ -1,6 +1,7 @@ # Module sequencing the successive actions necessary for website building -import modules.config as config +import bootstraparse.modules.config as config + def create_website(): diff --git a/modules/template_mngr.py b/src/bootstraparse/modules/template_mngr.py similarity index 100% rename from modules/template_mngr.py rename to src/bootstraparse/modules/template_mngr.py diff --git a/src/bootstraparse/templates/bootstrap.yml b/src/bootstraparse/templates/bootstrap.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/bootstraparse/testrun.py b/src/bootstraparse/testrun.py new file mode 100644 index 0000000..f68940e --- /dev/null +++ b/src/bootstraparse/testrun.py @@ -0,0 +1,10 @@ +import modules.sitecreator as sitecreator +from rich import print, pretty, inspect + + +pretty.install() + + +conf = sitecreator.create_config() +print("[red]test",conf) +inspect(conf) \ No newline at end of file diff --git a/testrun.py b/testrun.py deleted file mode 100644 index 3c6b08a..0000000 --- a/testrun.py +++ /dev/null @@ -1,5 +0,0 @@ -import modules.sitecreator as sitecreator - - -conf = sitecreator.create_config() -print(conf) diff --git a/tests/test_bparse.py b/tests/test_bparse.py new file mode 100644 index 0000000..54f4eb9 --- /dev/null +++ b/tests/test_bparse.py @@ -0,0 +1,7 @@ +# Test the base parser +from bootstraparse import bparse + + +def test_totest(): + assert bparse.totest() is None + diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..a8a2a7a --- /dev/null +++ b/tox.ini @@ -0,0 +1,29 @@ +[tox] +minversion = 3.8.0 +envlist = py37, py38, py39, flake8, mypy +isolated_build = true + +[gh-actions] +python = + 3.7: py36, mypy, flake8 + 3.8: py38 + 3.9: py39 + +[testenv] +setenv = + PYTHONPATH = {toxinidir} +deps = + -r{toxinidir}/requirements_dev.txt +commands = + pytest --basetemp={envtmpdir} + +[testenv:flake8] +basepython = python3.7 +deps = flake8 +commands = flake8 src tests + +[testenv:mypy] +basepython = python3.7 +deps = + -r{toxinidir}/requirements_dev.txt +commands = mypy src