Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump actions/upload-artifact, fix wheel builds #123

Merged
merged 8 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ 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
with:
fetch-depth: 0

- name: Build wheels
uses: pypa/[email protected]
uses: pypa/cibuildwheel@7940a4c0e76eb2030e473a5f864f291f63ee879b # v2.21.3
env:
CIBW_SKIP: pp*

- 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
Expand All @@ -37,22 +42,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/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- nodefaults
dependencies:
- python>=3.8
- python>=3.9
- setuptools_scm
- pre-commit
- pytest
Expand All @@ -20,3 +20,4 @@ dependencies:
- antlr4-python3-runtime==4.13.1 # keep `.github/workflows/update_grammar.yml` in sync
- click
- openjdk
- compilers
14 changes: 9 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand All @@ -25,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",
Expand All @@ -34,7 +37,7 @@ classifiers = [
readme = "README.md"
dynamic = ["version"]

requires-python = ">=3.8.0"
requires-python = ">=3.9"

dependencies = [
"sqlalchemy >=1.4",
Expand Down Expand Up @@ -70,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",
Expand All @@ -84,8 +89,7 @@ select = [
# pyupgrade
"UP",
]
target-version = "py38"
exclude=["src/pytsql/grammar/**/*.py"]

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["pytsql"]
19 changes: 0 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import glob
import platform
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:
Expand Down Expand Up @@ -61,10 +46,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",
},
)


Expand Down
24 changes: 12 additions & 12 deletions src/pytsql/tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <replace> statement."""
new_line = line.format(**parameters)
if None in parameters.values():
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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


Expand All @@ -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."
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_py_vs_cpp.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import inspect
import re
from typing import List
from unittest import mock

import pytest
Expand Down Expand Up @@ -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
Expand Down
Loading