From acfa6930de005b2b6cb42408fe8b3522e336ff5f Mon Sep 17 00:00:00 2001 From: kklein Date: Thu, 24 Oct 2024 15:51:03 +0200 Subject: [PATCH 1/8] Adapt building process. --- .github/workflows/build_and_publish.yml | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index b9f4c40..411658a 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -12,7 +12,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-20.04, windows-2019, macos-11 ] + # macos-13 is pre-ARM + os: [ ubuntu-24.04, windows-2019, macos-13, macos-latest ] steps: - uses: actions/checkout@v4 @@ -22,9 +23,11 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@v2.21.1 - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: + name: pytsql-wheel-${{ matrix.os }} path: ./wheelhouse/*.whl + if-no-files-found: error build_sdist: name: Build source distribution @@ -37,22 +40,23 @@ jobs: - name: Build sdist run: pipx run build --sdist - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: + name: pytsql-sdist path: dist/*.tar.gz + if-no-files-found: error upload_pypi: name: Upload to PyPI needs: [build_wheels, build_sdist] + environment: pypi runs-on: ubuntu-latest if: github.event_name == 'release' && github.event.action == 'published' steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: - name: artifact + pattern: pytsql-* + merge-multiple: true path: dist - uses: pypa/gh-action-pypi-publish@v1.10.2 - with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} From 842cf90ba5ab3c7ff50049af38a558a2ebc96c4e Mon Sep 17 00:00:00 2001 From: kklein Date: Thu, 24 Oct 2024 16:03:01 +0200 Subject: [PATCH 2/8] Adapt scm build. --- pyproject.toml | 4 ++++ setup.py | 18 ------------------ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 9121f8c..aa5cfe4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,6 +2,10 @@ requires = ['setuptools', 'setuptools-scm', 'wheel'] build-backend = "setuptools.build_meta" +[tool.setuptools_scm] +version_scheme = "post-release" + + [project] name = "pytsql" description = "`Pytsql` allows to run mssql sripts, typically run via GUIs, via CLI." diff --git a/setup.py b/setup.py index 95e46ea..bf8cd6a 100644 --- a/setup.py +++ b/setup.py @@ -3,20 +3,6 @@ from time import time import setuptools -from setuptools_scm.version import ScmVersion - - -def get_dev_timestamp(version: ScmVersion) -> str: - """Return a new distribution version string. - - Returns the version found in the git tag if currently checked out commit has a tag. - Otherwise, returns the version found in the most recent git tag, appended with - `dev` and the current timestamp in seconds. - """ - - if version.exact: - return version.format_with("{tag}") - return version.format_with(f"{{tag}}.dev{int(time())}") def get_platform() -> str: @@ -61,10 +47,6 @@ def create_extension() -> setuptools.Extension: def run_setup(): setuptools.setup( ext_modules=[create_extension()], - use_scm_version={ - "version_scheme": get_dev_timestamp, - "local_scheme": "dirty-tag", - }, ) From df10e2b678be21c066b87ae3d70b6689ac5dff46 Mon Sep 17 00:00:00 2001 From: kklein Date: Thu, 24 Oct 2024 16:06:38 +0200 Subject: [PATCH 3/8] Remove redundant import. --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index bf8cd6a..090bbf4 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,5 @@ import glob import platform -from time import time import setuptools From b5bc23b793876580999f1dca886551dcffe1476f Mon Sep 17 00:00:00 2001 From: kklein Date: Thu, 24 Oct 2024 16:37:40 +0200 Subject: [PATCH 4/8] Add compilers dependency. --- environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/environment.yml b/environment.yml index 1709da9..1da740e 100644 --- a/environment.yml +++ b/environment.yml @@ -20,3 +20,4 @@ dependencies: - antlr4-python3-runtime==4.13.1 # keep `.github/workflows/update_grammar.yml` in sync - click - openjdk + - compilers From 4574f0318e3bca602a294d89ef8215a2c504ba49 Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Thu, 24 Oct 2024 17:11:34 +0200 Subject: [PATCH 5/8] Require python 3.9 --- .github/workflows/ci.yaml | 4 ++-- environment.yml | 2 +- pyproject.toml | 4 +--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7f5269f..03b0adf 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: strategy: fail-fast: true matrix: - PYTHON_VERSION: ['3.8', '3.9', '3.10', '3.11'] + PYTHON_VERSION: ['3.9', '3.10', '3.11'] OS: ['ubuntu-latest', 'windows-latest'] steps: - name: Checkout branch @@ -56,7 +56,7 @@ jobs: strategy: fail-fast: false matrix: - PYTHON_VERSION: ['3.8', '3.9', '3.10', '3.11'] + PYTHON_VERSION: ['3.9', '3.10', '3.11'] services: DB: image: mcr.microsoft.com/mssql/server:2019-latest diff --git a/environment.yml b/environment.yml index 1da740e..703648f 100644 --- a/environment.yml +++ b/environment.yml @@ -3,7 +3,7 @@ channels: - conda-forge - nodefaults dependencies: - - python>=3.8 + - python>=3.9 - setuptools_scm - pre-commit - pytest diff --git a/pyproject.toml b/pyproject.toml index aa5cfe4..cf35ba0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ classifiers = [ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", @@ -38,7 +37,7 @@ classifiers = [ readme = "README.md" dynamic = ["version"] -requires-python = ">=3.8.0" +requires-python = ">=3.9" dependencies = [ "sqlalchemy >=1.4", @@ -88,7 +87,6 @@ select = [ # pyupgrade "UP", ] -target-version = "py38" exclude=["src/pytsql/grammar/**/*.py"] [tool.ruff.isort] From 95477916545059d34302a268e3893b519133815b Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Thu, 24 Oct 2024 17:14:35 +0200 Subject: [PATCH 6/8] ruff --- pyproject.toml | 6 ++++-- src/pytsql/tsql.py | 24 ++++++++++++------------ tests/unit/test_py_vs_cpp.py | 3 +-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index cf35ba0..733d60d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,8 +73,10 @@ module = "pytsql.grammar.*" follow_imports = "silent" [tool.ruff] -ignore = ["E501", "N803", "N806"] line-length = 88 + +[tool.ruff.lint] +ignore = ["E501", "N803", "N806"] select = [ # pyflakes "F", @@ -89,5 +91,5 @@ select = [ ] exclude=["src/pytsql/grammar/**/*.py"] -[tool.ruff.isort] +[tool.ruff.lint.isort] known-first-party = ["pytsql"] diff --git a/src/pytsql/tsql.py b/src/pytsql/tsql.py index f69b379..46169cf 100644 --- a/src/pytsql/tsql.py +++ b/src/pytsql/tsql.py @@ -3,7 +3,7 @@ import warnings from pathlib import Path from re import Match -from typing import Any, Dict, List, Optional, Union +from typing import Any, Optional, Union import antlr4.tree.Tree import sqlalchemy @@ -28,7 +28,7 @@ def _code(path: Union[str, Path], encoding: str) -> str: return "\n".join(fh.readlines()) -def _process_replacement(line: str, parameters: Dict[str, Any]) -> str: +def _process_replacement(line: str, parameters: dict[str, Any]) -> str: """Appropriately replace a single statement.""" new_line = line.format(**parameters) if None in parameters.values(): @@ -42,7 +42,7 @@ def _process_replacement(line: str, parameters: Dict[str, Any]) -> str: def _parametrize( source: str, - parameters: Dict[str, Any], + parameters: dict[str, Any], start: str = _REPLACE_START, end: str = _REPLACE_END, ) -> str: @@ -93,7 +93,7 @@ def __init__(self): # session information is lost after the execution of a batch. # We therefore need to manually prepend it to all following # batches. - self.dynamics: List[str] = [] + self.dynamics: list[str] = [] def visit( self, tree: TSqlParser.Sql_clausesContext, prepend_dynamics: bool = True @@ -112,7 +112,7 @@ def visit( return " ".join(dynamics + chunks) - def visitChildren(self, node: antlr4.ParserRuleContext) -> List[str]: # noqa: N802 + def visitChildren(self, node: antlr4.ParserRuleContext) -> list[str]: # noqa: N802 if isinstance(node, TSqlParser.Print_statementContext): # Print statements are replaced by inserts into a temporary table so that they can be evaluated # at the right time and fetched afterwards. @@ -129,15 +129,15 @@ def visitChildren(self, node: antlr4.ParserRuleContext) -> List[str]: # noqa: N return result - def visitTerminal(self, node: antlr4.TerminalNode) -> List[str]: # noqa: N802 + def visitTerminal(self, node: antlr4.TerminalNode) -> list[str]: # noqa: N802 return [str(node)] - def defaultResult(self) -> List[str]: # noqa: N802 + def defaultResult(self) -> list[str]: # noqa: N802 return [] def aggregateResult( # noqa: N802 - self, aggregate: List[str], next_result: List[str] - ) -> List[str]: + self, aggregate: list[str], next_result: list[str] + ) -> list[str]: return aggregate + next_result @@ -158,7 +158,7 @@ def syntaxError( # noqa: N802 raise ValueError(f"Error parsing SQL script: {error_message}") -def _split(code: str, isolate_top_level_statements: bool = True) -> List[str]: +def _split(code: str, isolate_top_level_statements: bool = True) -> list[str]: if not USE_CPP_IMPLEMENTATION: warnings.warn( "Can not find C++ version of the parser, Python version will be used instead." @@ -215,7 +215,7 @@ def _fetch_and_clear_prints(conn: Connection): def executes( code: str, engine: sqlalchemy.engine.Engine, - parameters: Optional[Dict[str, Any]] = None, + parameters: Optional[dict[str, Any]] = None, isolate_top_level_statements=True, ) -> None: """Execute a given sql string through a sqlalchemy.engine.Engine connection. @@ -250,7 +250,7 @@ def executes( def execute( path: Union[str, Path], engine: sqlalchemy.engine.Engine, - parameters: Optional[Dict[str, Any]] = None, + parameters: Optional[dict[str, Any]] = None, isolate_top_level_statements=True, encoding: str = "utf-8", ) -> None: diff --git a/tests/unit/test_py_vs_cpp.py b/tests/unit/test_py_vs_cpp.py index eb117c7..1f2b283 100644 --- a/tests/unit/test_py_vs_cpp.py +++ b/tests/unit/test_py_vs_cpp.py @@ -1,6 +1,5 @@ import inspect import re -from typing import List from unittest import mock import pytest @@ -36,7 +35,7 @@ def seed(): GROUP BY nr, short_nr;""" -def get_rule_labels(context_cls: ParserRuleContext) -> List[str]: +def get_rule_labels(context_cls: ParserRuleContext) -> list[str]: init_func = context_cls.__init__ # Detect any context/token labels from the init function's assignments From fadc815d2577d83bbbba68094fb233e3c96e546f Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Thu, 24 Oct 2024 17:26:21 +0200 Subject: [PATCH 7/8] bump cibuildwheel --- .github/workflows/build_and_publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 411658a..71d63c9 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -21,7 +21,7 @@ jobs: fetch-depth: 0 - name: Build wheels - uses: pypa/cibuildwheel@v2.21.1 + uses: pypa/cibuildwheel@7940a4c0e76eb2030e473a5f864f291f63ee879b # v2.21.3 - uses: actions/upload-artifact@v4 with: From 416b29a0b17e6c8c516c9228aa338edf9b86cb09 Mon Sep 17 00:00:00 2001 From: Pavel Zwerschke Date: Thu, 24 Oct 2024 17:41:23 +0200 Subject: [PATCH 8/8] Skip pypy --- .github/workflows/build_and_publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 71d63c9..940bb5a 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -22,6 +22,8 @@ jobs: - name: Build wheels uses: pypa/cibuildwheel@7940a4c0e76eb2030e473a5f864f291f63ee879b # v2.21.3 + env: + CIBW_SKIP: pp* - uses: actions/upload-artifact@v4 with: