From 86992281b58626f30f000e4aefdd6e56a955bd36 Mon Sep 17 00:00:00 2001 From: Seth Morton Date: Mon, 21 Oct 2024 21:55:42 -0700 Subject: [PATCH] Update CI configuration --- .github/workflows/code-quality.yml | 46 +++++++++++++++++++++++------- .github/workflows/deploy.yml | 2 +- .github/workflows/tests.yml | 24 ++++++++-------- setup.py | 14 +++++---- src/cpp/parser.cpp | 3 ++ tox.ini | 2 ++ 6 files changed, 63 insertions(+), 28 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 1cc7ba94..2e92e89a 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -23,8 +23,7 @@ jobs: python-version: 3.8 - name: Install deps - run: | - pip install black clang-format + run: python -m pip install ruff clang-format - name: Run formatting checks run: python dev/formatting.py --check @@ -41,11 +40,11 @@ jobs: with: python-version: 3.8 - - name: Install Flake8 - run: pip install flake8 flake8-import-order flake8-bugbear pep8-naming + - name: Install ruff + run: python -m pip install ruff - - name: Run Flake8 - run: flake8 + - name: Run ruff + run: ruff check type-checking: name: Type Checking @@ -64,7 +63,7 @@ jobs: - name: Run MyPy run: | - python setup.py install + python -m pip install --editable . mypy --strict tests package-validation: @@ -80,10 +79,37 @@ jobs: python-version: 3.8 - name: Install Validators - run: pip install twine check-manifest + run: python -m pip install twine build - name: Run Validation run: | - check-manifest --ignore ".github*,*.md,.coveragerc" - python setup.py sdist + python -m build twine check dist/* + + warning-free-compilation: + name: Warning-free Compilation + runs-on: ${{ matrix.os }} + strategy: + matrix: + # Note, clang is used on macos, even though it says gcc + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set up Python 3.12 + uses: actions/setup-python@v4 + with: + python-version: "3.12" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + python -m pip install build + + - name: Set Environment + run: echo FN_WARNINGS_AS_ERRORS=1 >> $GITHUB_ENV + + - name: Compile + run: python -m build --wheel diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e96b47a3..a50c7ac9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -40,7 +40,7 @@ jobs: - name: Build Source Distribution if: matrix.os == 'ubuntu-latest' && matrix.arch != 'aarch64' - run: python setup.py sdist --format=gztar + run: python -m build --sdist - name: Build Wheel run: python -m cibuildwheel --output-dir dist diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bb004f11..48ebf191 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"] + python-version: [3.8, 3.9, "3.10", "3.11", "3.12"] # Note, clang is used on macos, even though it says gcc os: [ubuntu-latest, windows-latest, macos-latest] @@ -31,26 +31,26 @@ jobs: - name: Install Dependencies run: | python -m pip install --upgrade pip - python -m pip install setuptools + python -m pip install build setuptools setuptools_scm python -m pip install pytest pytest-faulthandler hypothesis typing_extensions numpy - name: Patch Doctests - run: python dev/patch_doctest.py + run: python dev/patch-doctest.py - - name: Set CFLAGS + - name: Set Environment for Coverage if: matrix.os == 'ubuntu-latest' - # Need no optimization for code coverage - run: echo CFLAGS="--coverage -Og" >> $GITHUB_ENV + # Set flags for coverage + run: echo FN_COV=1 >> $GITHUB_ENV - - name: Build and Install Using pip + - name: Build and Install if: matrix.os != 'ubuntu-latest' run: | - python setup.py build # to see compilation output python -m pip install --editable . - - name: Build and Install Using setuptools + - name: Build and Install With Coverage if: matrix.os == 'ubuntu-latest' - run: python setup.py install # to see the compilation output and get coverage + # We'll use this legacy method till coverage is supported with pip + run: python setup.py install - name: Run Doctests run: python -m doctest fastnumbers @@ -69,7 +69,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12"] + python-version: [3.8, 3.9, "3.10", "3.11", "3.12"] steps: - name: Checkout Code @@ -92,7 +92,7 @@ jobs: name: Tests on aarch64 strategy: matrix: - pyver: [cp37-cp37m, cp38-cp38, cp39-cp39, cp310-cp310, cp311-cp311, cp312-cp312] + pyver: [cp38-cp38, cp39-cp39, cp310-cp310, cp311-cp311, cp312-cp312] runs-on: ubuntu-latest env: py: /opt/python/${{ matrix.pyver }}/bin/python diff --git a/setup.py b/setup.py index 86f28291..4cfdf978 100644 --- a/setup.py +++ b/setup.py @@ -9,6 +9,7 @@ from setuptools import Extension, setup # Compilation arguments are platform-dependent +link_args = ["-lm"] if sys.platform == "win32": compile_args = [ "/std:c++17", @@ -19,7 +20,7 @@ if "FN_DEBUG" in os.environ or "FN_COV" in os.environ: compile_args.append("/Od") compile_args.append("/Z7") - if "FN_WARNINGS_AS_ERRORS": + if "FN_WARNINGS_AS_ERRORS" in os.environ: compile_args.append("/WX") else: compile_args = [ @@ -33,17 +34,20 @@ if "FN_DEBUG" in os.environ or "FN_COV" in os.environ: compile_args.append("-Og") compile_args.append("-g") - if "FN_WARNINGS_AS_ERRORS": + if "FN_COV" in os.environ: + compile_args.append("--coverage") + link_args.append("--coverage") + if "FN_WARNINGS_AS_ERRORS" in os.environ: compile_args.append("-Werror") ext = [ Extension( "fastnumbers.fastnumbers", - sorted(pathlib.Path("src/cpp").glob("*.cpp")), - include_dirs=[pathlib.Path("include").resolve()], + sorted(map(str, pathlib.Path("src/cpp").glob("*.cpp"))), + include_dirs=[str(pathlib.Path("include").resolve())], extra_compile_args=compile_args, - extra_link_args=["-lm"], + extra_link_args=link_args, ) ] diff --git a/src/cpp/parser.cpp b/src/cpp/parser.cpp index 5c703764..07e0c8bc 100644 --- a/src/cpp/parser.cpp +++ b/src/cpp/parser.cpp @@ -460,4 +460,7 @@ NumberFlags CharacterParser::get_number_type() const noexcept case StringType::INTLIKE_FLOAT: return flag_wrap(NumberType::Float | NumberType::IntLike); } + + /* Is not reachable, but silences compiler warnings. */ + return NumberType::INVALID; } diff --git a/tox.ini b/tox.ini index e8041a71..af7c6514 100644 --- a/tox.ini +++ b/tox.ini @@ -47,6 +47,8 @@ commands = # Check code quality. [testenv:lint] +setenv = + FN_WARNINGS_AS_ERRORS=1 deps = ruff clang-format