From 51882045c08fbb6143e37cb7169629ecc5b13e04 Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Wed, 13 Sep 2023 17:48:01 +0800 Subject: [PATCH 1/5] Enable GitHub Actions CI Drop python 2.6 and python 3.4 because our test dependencies don't support them. ref: https://github.com/python-attrs/attrs/blob/06b1bb414121bd21dd0781016a035ed1388aa136/.github/workflows/ci.yml --- .github/workflows/ci.yml | 129 +++++++++++++++++++++++++++++++++++++++ .python-version-default | 1 + tox.ini | 8 ++- 3 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .python-version-default diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..db4d09d --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,129 @@ +name: CI + +on: + push: + branches: [master] + tags: ["*"] + pull_request: + branches: [master] + workflow_dispatch: + +env: + # https://force-color.org/ + FORCE_COLOR: "1" + # https://pip.pypa.io/en/stable/topics/configuration/#environment-variables + # https://pip.pypa.io/en/stable/cli/pip/#cmdoption-disable-pip-version-check + PIP_DISABLE_PIP_VERSION_CHECK: "1" + # https://pip.pypa.io/en/stable/cli/pip/#cmdoption-no-python-version-warning + PIP_NO_PYTHON_VERSION_WARNING: "1" + +jobs: + tests: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - windows-latest + - macos-latest + python-version: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + - "3.12" + include: + - os: ubuntu-20.04 + python-version: "3.6" + - os: ubuntu-20.04 + python-version: "3.5" + - os: ubuntu-20.04 + container: python:2.7-buster + python-version: "2.7" + + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + allow-prereleases: true + cache: pip + if: '! matrix.container' + + - name: Prepare tox + shell: bash + run: | + V=${{ matrix.python-version }} + V=py$(echo $V | tr -d .) + + echo TOX_PYTHON=$V >>$GITHUB_ENV + + if test ${{ matrix.python-version }} = "2.7"; then + python -m pip install tox + else + python -Im pip install tox + fi + + - name: Run tests + shell: bash + run: | + if test ${{ matrix.python-version }} = "2.7"; then + python -m tox -e ${{ env.TOX_PYTHON }} + else + python -Im tox -e ${{ env.TOX_PYTHON }} + fi + + - name: Rename coverage data + shell: bash + run: | + if test -f .coverage; then + mv .coverage{,.${{ matrix.os }}.${{ env.TOX_PYTHON }}.$(date +"%Y-%m-%d_%H%M%S")} + fi + + - name: Upload coverage data + uses: actions/upload-artifact@v3 + with: + name: coverage-data + path: .coverage.* + if-no-files-found: ignore + + coverage: + name: Combine & check coverage. + runs-on: ubuntu-latest + needs: tests + + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version-file: .python-version-default + cache: pip + + - name: Download coverage data + uses: actions/download-artifact@v3 + with: + name: coverage-data + + - name: Combine coverage & fail if it's <100%. + run: | + python -Im pip install coverage[toml] + + python -Im coverage combine + python -Im coverage html --skip-covered --skip-empty + + # Report and write to summary. + python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY + + # Report again and fail if under 100%. + python -Im coverage report --fail-under=100 + + - name: Upload HTML report if check failed. + uses: actions/upload-artifact@v3 + with: + name: html-report + path: htmlcov + if: ${{ failure() }} diff --git a/.python-version-default b/.python-version-default new file mode 100644 index 0000000..2c07333 --- /dev/null +++ b/.python-version-default @@ -0,0 +1 @@ +3.11 diff --git a/tox.ini b/tox.ini index 8b4a78a..d432b4c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = update, compile, autopep8, docformatter, isort, pylint, flake8, pydocstyle, docs, py{26, 27, 34, 35, 36, 37, 38, 39, 310, 311, 312} +envlist = update, compile, autopep8, docformatter, isort, pylint, flake8, pydocstyle, docs, py{27, 35, 36, 37, 38, 39, 310, 311, 312} skip_missing_interpreters = true # https://tox.wiki/en/4.11.3/faq.html#testing-end-of-life-python-versions requires = virtualenv<20.22.0 @@ -100,6 +100,12 @@ deps = -r requirements-tests37.txt [testenv:py36] deps = -r requirements-tests36.txt +[testenv:py35] +deps = -r requirements-tests37.in + +[testenv:py27] +deps = -r requirements-tests37.in + [testenv:update] basepython = python3.12 usedevelop = true From 8e310a7d5fdc8a2bb514eebfb162fb4ff42e3931 Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Thu, 14 Sep 2023 01:53:40 +0800 Subject: [PATCH 2/5] Fix coverage combine failure ref: https://coverage.readthedocs.io/en/latest/config.html#run-relative-files --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index d432b4c..806ca48 100644 --- a/tox.ini +++ b/tox.ini @@ -53,6 +53,7 @@ ignore = E402,E501,F401,W503,W504 branch = True source = wcwidth parallel = True +relative_files = True [coverage:report] omit = tests/* From f4cd505fc20a5c910fe2952dd64dfe9768dcedea Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Thu, 14 Sep 2023 02:10:51 +0800 Subject: [PATCH 3/5] Improve coverage ignore unreachable code and replace a list-comprehension with map --- wcwidth/wcwidth.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wcwidth/wcwidth.py b/wcwidth/wcwidth.py index 6162cdd..82a86ee 100644 --- a/wcwidth/wcwidth.py +++ b/wcwidth/wcwidth.py @@ -299,7 +299,9 @@ def _wcmatch_version(given_version): _return_str = not _PY3 and isinstance(given_version, str) if _return_str: - unicode_versions = [ucs.encode() for ucs in list_versions()] + # avoid list-comprehension to work around a coverage issue: + # https://github.com/nedbat/coveragepy/issues/753 + unicode_versions = list(map(lambda ucs: ucs.encode(), list_versions())) else: unicode_versions = list_versions() latest_version = unicode_versions[-1] @@ -375,4 +377,4 @@ def _wcmatch_version(given_version): # is, 4.1 is returned for given 4.9.9, where 4.1 and 5.0 are available. if cmp_next_version > cmp_given: return unicode_version - assert False, ("Code path unreachable", given_version, unicode_versions) + assert False, ("Code path unreachable", given_version, unicode_versions) # pragma: no cover From cd2e1af831e8b2d884d1c4f997327bed24446906 Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Thu, 14 Sep 2023 16:54:55 +0800 Subject: [PATCH 4/5] Test on pypy --- .github/workflows/ci.yml | 21 ++++++++++++++++++--- tox.ini | 14 +++++++++++++- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db4d09d..d0bb65c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,7 +33,14 @@ jobs: - "3.10" - "3.11" - "3.12" + - "pypy-2.7" + - "pypy-3.7" + - "pypy-3.8" + - "pypy-3.9" + - "pypy-3.10" include: + - os: ubuntu-22.04 + python-version: "pypy-3.6" - os: ubuntu-20.04 python-version: "3.6" - os: ubuntu-20.04 @@ -58,11 +65,19 @@ jobs: shell: bash run: | V=${{ matrix.python-version }} - V=py$(echo $V | tr -d .) + if [[ "$V" = pypy-* ]]; then + V=$(echo $V | tr -d .-) + IS_PYPY=1 + else + V=py$(echo $V | tr -d .) + IS_PYPY=0 + fi + + echo IS_PYPY=$IS_PYPY >>$GITHUB_ENV echo TOX_PYTHON=$V >>$GITHUB_ENV - if test ${{ matrix.python-version }} = "2.7"; then + if [[ ${{ matrix.python-version }} = *2.7 ]]; then python -m pip install tox else python -Im pip install tox @@ -71,7 +86,7 @@ jobs: - name: Run tests shell: bash run: | - if test ${{ matrix.python-version }} = "2.7"; then + if [[ ${{ matrix.python-version }} = *2.7 ]]; then python -m tox -e ${{ env.TOX_PYTHON }} else python -Im tox -e ${{ env.TOX_PYTHON }} diff --git a/tox.ini b/tox.ini index 806ca48..47bedad 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = update, compile, autopep8, docformatter, isort, pylint, flake8, pydocstyle, docs, py{27, 35, 36, 37, 38, 39, 310, 311, 312} +envlist = update, compile, autopep8, docformatter, isort, pylint, flake8, pydocstyle, docs, py{27, 35, 36, 37, 38, 39, 310, 311, 312}, pypy{27, 36, 37, 38, 39, 310} skip_missing_interpreters = true # https://tox.wiki/en/4.11.3/faq.html#testing-end-of-life-python-versions requires = virtualenv<20.22.0 @@ -95,18 +95,30 @@ commands = {[base]pip_compile_command} requirements-tests37.in -o requirements-t [testenv:py38] deps = -r requirements-tests37.txt +[testenv:pypy38] +deps = -r requirements-tests37.txt + [testenv:py37] deps = -r requirements-tests37.txt +[testenv:pypy37] +deps = -r requirements-tests37.txt + [testenv:py36] deps = -r requirements-tests36.txt +[testenv:pypy36] +deps = -r requirements-tests36.txt + [testenv:py35] deps = -r requirements-tests37.in [testenv:py27] deps = -r requirements-tests37.in +[testenv:pypy27] +deps = -r requirements-tests37.in + [testenv:update] basepython = python3.12 usedevelop = true From 03ea8b7fe0833827f139812be3c4ef5594f1b865 Mon Sep 17 00:00:00 2001 From: GalaxySnail Date: Thu, 14 Sep 2023 17:53:44 +0800 Subject: [PATCH 5/5] Upload coverage to Codecov Co-authored-by: Trim21 --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0bb65c..13639f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,16 +123,22 @@ jobs: with: name: coverage-data - - name: Combine coverage & fail if it's <100%. + - name: Combine coverage data run: | python -Im pip install coverage[toml] python -Im coverage combine python -Im coverage html --skip-covered --skip-empty + python -Im coverage xml # Report and write to summary. python -Im coverage report --format=markdown >> $GITHUB_STEP_SUMMARY + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + + - name: Fail if coverage is <100%. + run: | # Report again and fail if under 100%. python -Im coverage report --fail-under=100