diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..bd01afcf --- /dev/null +++ b/.flake8 @@ -0,0 +1,8 @@ +[flake8] +exclude = + tests, + docs, + dist +max-complexity = 10 +statistics = True +show-source = True \ No newline at end of file diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 96c76bca..31b900bd 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -39,11 +39,11 @@ jobs: check-latest: true - name: Install dependencies run: | - python -m pip install --upgrade pip flit + python -m pip install --upgrade pip hatch flit install --deps=develop - name: Lint with flake8 - run: flake8 sqlparse --count --max-complexity=31 --show-source --statistics - - name: Test with pytest - run: pytest --cov=sqlparse + run: hatch run flake8 + - name: Test with pytest and coverage + run: hatch run cov - name: Publish to codecov uses: codecov/codecov-action@v4 diff --git a/.gitignore b/.gitignore index cc2ec16b..77479f17 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,7 @@ dist/ build/ MANIFEST .coverage -.tox/ .cache/ *.egg-info/ htmlcov/ -coverage.xml .pytest_cache \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 83cb93ed..c2d7fe4f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] -requires = ["flit_core >=3.2,<4"] -build-backend = "flit_core.buildapi" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "sqlparse" @@ -40,34 +40,63 @@ sqlformat = "sqlparse.__main__:main" [project.optional-dependencies] dev = [ - "flake8", + "hatch", "build", ] -test = [ - "pytest", - "pytest-cov", -] doc = [ "sphinx", ] -tox = [ - "virtualenv", - "tox", + +[tool.hatch.version] +path = "sqlparse/__init__.py" + +[tool.hatch.envs.default] +dependencies = [ + "coverage[toml]>=6.5", + "pytest", + # switch to ruff, but fix problems first + # but check defaults! + # https://hatch.pypa.io/1.9/config/static-analysis/#default-settings + "flake8", +] +[tool.hatch.envs.default.scripts] +test = "pytest {args:tests}" +test-cov = "coverage run -m pytest {args:tests}" +cov-report = [ + "- coverage combine", + "coverage report", +] +cov = [ + "test-cov", + "cov-report", ] +check = "flake8 sqlparse/" -[tool.flit.sdist] -include = [ - "docs/source/", - "docs/sqlformat.1", - "docs/Makefile", - "tests/*.py", "tests/files/*.sql", - "LICENSE", - "TODO", - "AUTHORS", - "CHANGELOG", - "Makefile", - "tox.ini", +[[tool.hatch.envs.all.matrix]] +python = ["3.8", "3.9", "3.10", "3.11", "3.12"] + +[tool.hatch.envs.types] +dependencies = [ + "mypy>=1.0.0", ] +[tool.hatch.envs.types.scripts] +check = "mypy --install-types --non-interactive {args:sqlparse tests}" [tool.coverage.run] -omit = ["sqlparse/__main__.py"] +source_pkgs = ["sqlparse", "tests"] +branch = true +parallel = true +omit = [ + "sqlparse/__main__.py", +] + +[tool.coverage.paths] +sqlparse = ["sqlparse"] +tests = ["tests"] + +[tool.coverage.report] +exclude_lines = [ + "no cov", + "if __name__ == .__main__.:", + "if TYPE_CHECKING:", +] diff --git a/tests/test_cli.py b/tests/test_cli.py index b681a60b..a0c1f2b0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -69,8 +69,8 @@ def test_stdout(filepath, load_file, capsys): def test_script(): # Call with the --help option as a basic sanity check. - cmd = "{:s} -m sqlparse.cli --help".format(sys.executable) - assert subprocess.call(cmd.split()) == 0 + cmd = [sys.executable, '-m', 'sqlparse.cli', '--help'] + assert subprocess.call(cmd) == 0 @pytest.mark.parametrize('fpath, encoding', (