diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..eb4f0c6 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,33 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/zope-product +name: pre-commit + +on: + pull_request: + push: + branches: + - master + # Allow to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + FORCE_COLOR: 1 + +jobs: + pre-commit: + name: linting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files --show-diff-on-failure + env: + PRE_COMMIT_COLOR: always + - uses: pre-commit-ci/lite-action@v1.0.2 + if: always() + with: + msg: Apply pre-commit code formatting diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7058512..a9d1e48 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -22,7 +22,6 @@ jobs: config: # [Python version, tox env] - ["3.11", "release-check"] - - ["3.11", "lint"] - ["3.8", "py38"] - ["3.9", "py39"] - ["3.10", "py310"] @@ -33,7 +32,6 @@ jobs: - ["3.11", "coverage"] exclude: - { os: ["windows", "windows-latest"], config: ["3.11", "release-check"] } - - { os: ["windows", "windows-latest"], config: ["3.11", "lint"] } - { os: ["windows", "windows-latest"], config: ["3.11", "coverage"] } runs-on: ${{ matrix.os[1] }} diff --git a/.meta.toml b/.meta.toml index b23dd73..1d8e039 100644 --- a/.meta.toml +++ b/.meta.toml @@ -2,7 +2,7 @@ # https://github.com/zopefoundation/meta/tree/master/config/zope-product [meta] template = "zope-product" -commit-id = "b1221c3c" +commit-id = "acd39fc2" [python] with-pypy = true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8d0156c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/zope-product +minimum_pre_commit_version: '3.6' +repos: + - repo: https://github.com/pycqa/isort + rev: "5.13.2" + hooks: + - id: isort + - repo: https://github.com/hhatto/autopep8 + rev: "v2.3.1" + hooks: + - id: autopep8 + args: [--in-place, --aggressive, --aggressive] + - repo: https://github.com/asottile/pyupgrade + rev: v3.17.0 + hooks: + - id: pyupgrade + args: [--py38-plus] + - repo: https://github.com/isidentical/teyit + rev: 0.4.3 + hooks: + - id: teyit + - repo: https://github.com/PyCQA/flake8 + rev: "7.1.1" + hooks: + - id: flake8 + additional_dependencies: + - flake8-debugger == 4.1.2 diff --git a/MANIFEST.in b/MANIFEST.in index 91dbcb1..63fd213 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,6 +5,7 @@ include *.rst include *.txt include buildout.cfg include tox.ini +include .pre-commit-config.yaml recursive-include src *.py recursive-include src *.txt diff --git a/src/DateTime/tests/test_datetime.py b/src/DateTime/tests/test_datetime.py index f4c2644..5b3f07d 100644 --- a/src/DateTime/tests/test_datetime.py +++ b/src/DateTime/tests/test_datetime.py @@ -77,7 +77,7 @@ def _compare(self, dt1, dt2): def testBug1203(self): # 01:59:60 occurred in old DateTime dt = DateTime(7200, 'GMT') - self.assertTrue(str(dt).find('60') < 0, dt) + self.assertNotIn('60', str(dt)) def testDSTInEffect(self): # Checks GMT offset for a DST date in the US/Eastern time zone @@ -172,7 +172,7 @@ def testOldDate(self): # Fails when an 1800 date is displayed with negative signs dt = DateTime('1830/5/6 12:31:46.213 pm') dt1 = dt.toZone('GMT+6') - self.assertTrue(str(dt1).find('-') < 0, (dt, dt1)) + self.assertNotIn('-', str(dt1)) def testSubtraction(self): # Reconstruction of a DateTime from its parts, with subtraction @@ -219,8 +219,10 @@ def test_compare_methods(self): self.assertFalse(dt.equalTo(dt1)) # Compare a date to float dt = DateTime(1.0) - self.assertTrue(dt == DateTime(1.0)) # testing __eq__ - self.assertFalse(dt != DateTime(1.0)) # testing __ne__ + is_eq = dt == DateTime(1.0) # testing __eq__ + self.assertTrue(is_eq) + is_neq = dt != DateTime(1.0) # testing __ne__ + self.assertFalse(is_neq) self.assertFalse(dt.greaterThan(1.0)) self.assertTrue(dt.greaterThanEqualTo(1.0)) self.assertFalse(dt.lessThan(1.0)) @@ -230,8 +232,10 @@ def test_compare_methods(self): # Compare a date to int dt = DateTime(1) self.assertEqual(dt, DateTime(1.0)) - self.assertTrue(dt == DateTime(1)) # testing __eq__ - self.assertFalse(dt != DateTime(1)) # testing __ne__ + is_eq = dt == DateTime(1) # testing __eq__ + self.assertTrue(is_eq) + is_neq = dt != DateTime(1) # testing __ne__ + self.assertFalse(is_neq) self.assertFalse(dt.greaterThan(1)) self.assertTrue(dt.greaterThanEqualTo(1)) self.assertFalse(dt.lessThan(1)) @@ -242,8 +246,10 @@ def test_compare_methods(self): # but behavior if consistent as when comparing, for example, an int # and a string. dt = DateTime("2023") - self.assertFalse(dt == "2023") # testing __eq__ - self.assertTrue(dt != "2023") # testing __ne__ + is_eq = dt == "2023" # testing __eq__ + self.assertFalse(is_eq) + is_neq = dt != "2023" # testing __ne__ + self.assertTrue(is_neq) self.assertRaises(TypeError, dt.greaterThan, "2023") self.assertRaises(TypeError, dt.greaterThanEqualTo, "2023") self.assertRaises(TypeError, dt.lessThan, "2023") diff --git a/tox.ini b/tox.ini index 26e66ed..26c961b 100644 --- a/tox.ini +++ b/tox.ini @@ -17,8 +17,8 @@ envlist = [testenv] skip_install = true deps = - setuptools < 69 - zc.buildout >= 3.0.1 + setuptools <74 + zc.buildout >= 3.1 wheel > 0.37 setenv = py312: VIRTUALENV_PIP=23.1.2 @@ -28,6 +28,7 @@ commands_pre = commands = {envbindir}/test {posargs:-cv} + [testenv:release-check] description = ensure that the distribution is ready to release basepython = python3 @@ -46,29 +47,14 @@ commands = twine check dist/* [testenv:lint] +description = This env runs all linters configured in .pre-commit-config.yaml basepython = python3 -commands_pre = - mkdir -p {toxinidir}/parts/flake8 -allowlist_externals = - mkdir -commands = - isort --check-only --diff {toxinidir}/src {toxinidir}/setup.py - flake8 {toxinidir}/src {toxinidir}/setup.py +skip_install = true deps = - flake8 - isort - # Useful flake8 plugins that are Python and Plone specific: - flake8-coding - flake8-debugger - mccabe - -[testenv:isort-apply] -basepython = python3 + pre-commit commands_pre = -deps = - isort commands = - isort {toxinidir}/src {toxinidir}/setup.py [] + pre-commit run --all-files --show-diff-on-failure [testenv:coverage] basepython = python3