Skip to content

Commit 3d06580

Browse files
Change build system to setuptools and automate publishing to PyPI
#27 Update msodbcsql version used in integration test CI Replace flit with setuptools as the build system Disable mypy following imports in src/pytsql/grammar and remove some type ignore statements Add a workflow for building the package and publishing it to PyPI Remove the step for building wheels and rename the PyPI workflow Add a missing newline Clean up setup.cfg and add extra pip install flags to ci workflow Add a job for uploading the package to TestPyPI Update config to make local distribution version names compatible with TestPyPI Create a custom setuptools_scm version scheme to enable non-duplicate TestPyPI release versions Change git clone depth in build_and_publish workflow to get all tags Update custom version scheme naming and add a dosctring to it Fix a syntax error in build_and_publish.yml Bring package metadata back to pyproject.toml Change docstring mood to imperative Co-authored-by: Kevin Klein <[email protected]> Update a docstring to be more concise and informative Co-authored-by: Kevin Klein <[email protected]>
1 parent 3b1ae03 commit 3d06580

11 files changed

+108
-26
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Build and upload to PyPI
2+
3+
on:
4+
pull_request:
5+
release:
6+
types:
7+
- published
8+
9+
jobs:
10+
build_sdist:
11+
name: Build source distribution
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Build sdist
19+
run: pipx run build --sdist
20+
21+
- uses: actions/upload-artifact@v3
22+
with:
23+
path: dist/*.tar.gz
24+
25+
upload_testpypi:
26+
name: Upload to TestPyPI
27+
needs: [build_sdist]
28+
runs-on: ubuntu-latest
29+
steps:
30+
- uses: actions/download-artifact@v3
31+
with:
32+
name: artifact
33+
path: dist
34+
35+
- uses: pypa/[email protected]
36+
with:
37+
user: __token__
38+
password: ${{ secrets.TESTPYPI_TOKEN }}
39+
repository_url: https://test.pypi.org/legacy/
40+
41+
upload_pypi:
42+
name: Upload to PyPI
43+
needs: [build_sdist, upload_testpypi]
44+
runs-on: ubuntu-latest
45+
if: github.event_name == 'release' && github.event.action == 'published'
46+
steps:
47+
- uses: actions/download-artifact@v3
48+
with:
49+
name: artifact
50+
path: dist
51+
52+
- uses: pypa/[email protected]
53+
with:
54+
user: __token__
55+
password: ${{ secrets.PYPI_TOKEN }}

.github/workflows/ci.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ jobs:
4444
- name: Run Unit Tests
4545
shell: bash -l {0}
4646
run: |
47-
flit install -s
47+
pip install . --no-build-isolation --no-deps --disable-pip-version-check
4848
pytest tests/unit
4949
5050
linux-integration_tests-sqlserver:
5151
name: "Linux - integration tests - Python ${{ matrix.PYTHON_VERSION }} - mssql"
52-
runs-on: ubuntu-20.04
52+
runs-on: ubuntu-latest
5353
env:
5454
CI: True
5555
strategy:
@@ -82,13 +82,13 @@ jobs:
8282
- name: Install msodbcsql17 driver
8383
shell: bash -l {0}
8484
run: |
85-
wget https://packages.microsoft.com/ubuntu/20.04/prod/pool/main/m/msodbcsql17/msodbcsql17_17.9.1.1-1_amd64.deb
86-
ACCEPT_EULA=Y sudo apt install ./msodbcsql17_17.9.1.1-1_amd64.deb
85+
wget https://packages.microsoft.com/ubuntu/20.04/prod/pool/main/m/msodbcsql17/msodbcsql17_17.10.1.1-1_amd64.deb
86+
ACCEPT_EULA=Y sudo apt install ./msodbcsql17_17.10.1.1-1_amd64.deb --allow-downgrades
8787
- name: Wait for SQL Server
8888
timeout-minutes: 1
8989
run: until docker logs "${{ job.services.db.id }}" 2>&1 | grep -q "SQL Server is now ready"; do sleep 10; done
9090
- name: Run Unit Tests
9191
shell: bash -l {0}
9292
run: |
93-
flit install -s
93+
pip install . --no-build-isolation --no-deps --disable-pip-version-check
9494
pytest --backend=mssql tests/integration

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ repos:
1919
additional_dependencies: [toml]
2020
exclude: ^src/pytsql/grammar/
2121
- repo: https://github.com/Quantco/pre-commit-mirrors-mypy
22-
rev: "0.790"
22+
rev: "0.961"
2323
hooks:
2424
- id: mypy-conda
25-
additional_dependencies: [ mypy=0.800, python=3.7.9 ]
25+
additional_dependencies: [ -c, conda-forge, types-setuptools ]
2626
exclude: ^src/pytsql/grammar/
2727
- repo: https://github.com/Quantco/pre-commit-mirrors-pyupgrade
2828
rev: 2.7.2

environment.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- flit-core
7-
- flit
6+
- setuptools_scm
87
- pre-commit
98
- pytest
109
- pytest-mock
@@ -15,5 +14,5 @@ dependencies:
1514
- sphinx_rtd_theme
1615
- sphinxcontrib-apidoc
1716
- sqlalchemy
18-
- antlr4-python3-runtime =4.9.2
17+
- antlr-python-runtime==4.9.2
1918
- pyodbc

pyproject.toml

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
[build-system]
2-
requires = ["flit_core >=3.2,<4"]
3-
build-backend = "flit_core.buildapi"
2+
requires = ['setuptools', 'setuptools-scm', 'wheel']
3+
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "pytsql"
7+
description = "`Pytsql` allows to run mssql sripts, typically run via GUIs, via CLI."
78
authors = [
89
{name = "Alex Gonopolskiy", email = "[email protected]"},
910
{name = "Kevin Klein", email = "[email protected]"},
@@ -24,10 +25,13 @@ classifiers = [
2425
"Operating System :: OS Independent",
2526
"Programming Language :: Python :: 3",
2627
"Programming Language :: Python :: 3.7",
28+
"Programming Language :: Python :: 3.8",
29+
"Programming Language :: Python :: 3.9",
30+
"Programming Language :: Python :: 3.10",
2731
"Topic :: Database"
2832
]
2933
readme = "README.md"
30-
dynamic = ["version", "description"]
34+
dynamic = ["version"]
3135

3236
requires-python = ">=3.7.0"
3337

@@ -40,7 +44,6 @@ dependencies = [
4044
[project.urls]
4145
Source = "https://github.com/quantco/pytsql"
4246

43-
4447
[tool.black]
4548
exclude = '''
4649
/(
@@ -60,3 +63,7 @@ line_length = 88
6063
known_first_party = "pytsql"
6164
skip_glob = '\.eggs/*,\.git/*,\.venv/*,build/*,dist/*'
6265
default_section = 'THIRDPARTY'
66+
67+
[[tool.mypy.overrides]]
68+
module = "pytsql.grammar.*"
69+
follow_imports = "silent"

setup.py

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from time import time
2+
3+
from setuptools import setup
4+
from setuptools_scm.version import ScmVersion
5+
6+
7+
def get_dev_timestamp(version: ScmVersion) -> str:
8+
"""Return a new distribution version string.
9+
10+
Returns the version found in the git tag if currently checked out commit has a tag.
11+
Otherwise, returns the version found in the most recent git tag, appended with
12+
`dev` and the current timestamp in seconds.
13+
"""
14+
15+
if version.exact:
16+
return version.format_with("{tag}")
17+
return version.format_with(f"{{tag}}.dev{int(time())}")
18+
19+
20+
setup(
21+
use_scm_version={
22+
"version_scheme": get_dev_timestamp,
23+
"local_scheme": "dirty-tag",
24+
},
25+
)

src/pytsql/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
"""`Pytsql` allows to run mssql sripts, typically run via GUIs, via CLI."""
22

3+
import pkg_resources
34

45
from .tsql import execute, executes
56

6-
__version__ = "1.0.0"
7+
try:
8+
__version__ = pkg_resources.get_distribution(__name__).version
9+
except Exception:
10+
__version__ = "unknown"
711

812
__all__ = ["execute", "executes"]

src/pytsql/grammar/__init__.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# flake8: noqa
2-
3-
from .tsqlLexer import tsqlLexer # type: ignore
4-
from .tsqlListener import tsqlListener # type: ignore
5-
from .tsqlParser import tsqlParser # type: ignore
1+
from .tsqlLexer import tsqlLexer
2+
from .tsqlListener import tsqlListener
3+
from .tsqlParser import tsqlParser

src/pytsql/grammar/tsqlLexer.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#type: ignore
2-
31
# Generated from tsql.g4 by ANTLR 4.9.2
42
from antlr4 import *
53
from io import StringIO

src/pytsql/grammar/tsqlListener.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#type: ignore
2-
31
# Generated from tsql.g4 by ANTLR 4.9.2
42
from antlr4 import *
53
if __name__ is not None and "." in __name__:

src/pytsql/grammar/tsqlParser.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#type: ignore
2-
31
# Generated from tsql.g4 by ANTLR 4.9.2
42
# encoding: utf-8
53
from antlr4 import *

0 commit comments

Comments
 (0)