Skip to content

Commit

Permalink
Pixi (#164)
Browse files Browse the repository at this point in the history
<!-- ⚠️ This is an open-source repository. Do not share sensitive
information. -->
  • Loading branch information
kklein authored Nov 4, 2024
1 parent 5f55ca5 commit 653486f
Show file tree
Hide file tree
Showing 17 changed files with 14,587 additions and 219 deletions.
10 changes: 0 additions & 10 deletions .flake8

This file was deleted.

2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
12 changes: 8 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
- package-ecosystem: github-actions
directory: /
schedule:
interval: "weekly"
interval: monthly
reviewers:
- "quantco/ci"
- quantco/ci
groups:
gh-actions:
patterns:
- "*"
90 changes: 47 additions & 43 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,73 @@ name: CI
on: [push]

jobs:

pre-commit-checks:
name: "Linux - pre-commit checks - Python 3.8"
name: "Pre-commit checks"
runs-on: ubuntu-latest
steps:
- name: Checkout branch
uses: actions/checkout@v4
- name: Set up pixi
uses: prefix-dev/[email protected]
with:
ref: ${{ github.head_ref }}
- name: Install Python 3.8
uses: actions/setup-python@v5
with:
python-version: 3.8
- name: Run pre-commit checks
uses: pre-commit/[email protected]

environments: default lint
- name: pre-commit
run: pixi run pre-commit-run --color=always --show-diff-on-failure

unit-tests:
name: "Unit tests - ${{ matrix.OS }} - Python ${{ matrix.PYTHON_VERSION }}"
runs-on: ubuntu-latest
name: "Unit tests"
runs-on: ${{ matrix.os }}
env:
CI: True
strategy:
fail-fast: true
matrix:
PYTHON_VERSION: ['3.9', '3.10', '3.11', '3.12', '3.13']
OS: ['ubuntu-latest', 'windows-latest']
env:
- py39
- py310
- py311
- py312
- py313
- antlr410
- antlr411
- antlr412
- antlr413
os: ['ubuntu-latest', 'windows-latest', 'macos-latest']
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: conda-incubator/setup-miniconda@v3
fetch-depth: 0
- name: Set up pixi
uses: prefix-dev/[email protected]
with:
python-version: ${{ matrix.PYTHON_VERSION }}
miniforge-variant: Mambaforge
miniforge-version: 4.11.0-2
use-mamba: true
environment-file: environment.yml
activate-environment: pytsql
- name: Run Unit Tests
shell: bash -l {0}
environments: ${{ matrix.env }}
- name: Run unit tests
run: |
pip install . --no-build-isolation --no-deps --disable-pip-version-check
pytest tests/unit
pixi run -e ${{ matrix.env }} postinstall
pixi run -e ${{ matrix.env }} pytest tests/unit
linux-integration_tests-sqlserver:
name: "Linux - integration tests - Python ${{ matrix.PYTHON_VERSION }} - mssql"
name: "Integration tests"
runs-on: ubuntu-latest
env:
CI: True
strategy:
fail-fast: false
matrix:
PYTHON_VERSION: ['3.9', '3.10', '3.11', '3.12', '3.13']
env:
- py39
- py310
- py311
- py312
- py313
- antlr410
- antlr411
- antlr412
- antlr413
- sa1
- sa2
services:
DB:
image: mcr.microsoft.com/mssql/server:2019-latest
Expand All @@ -69,27 +81,19 @@ jobs:
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Fetch full git history
run: git fetch --prune --unshallow
- uses: conda-incubator/setup-miniconda@v3
fetch-depth: 0
- name: Set up pixi
uses: prefix-dev/[email protected]
with:
python-version: ${{ matrix.PYTHON_VERSION }}
miniforge-variant: Mambaforge
miniforge-version: 4.11.0-2
use-mamba: true
environment-file: environment.yml
activate-environment: pytsql
environments: ${{ matrix.env }}
- name: Install msodbcsql17 driver
shell: bash -l {0}
run: |
wget https://packages.microsoft.com/ubuntu/20.04/prod/pool/main/m/msodbcsql17/msodbcsql17_17.10.1.1-1_amd64.deb
ACCEPT_EULA=Y sudo apt install ./msodbcsql17_17.10.1.1-1_amd64.deb --allow-downgrades
- name: Wait for SQL Server
timeout-minutes: 1
run: until docker logs "${{ job.services.db.id }}" 2>&1 | grep -q "SQL Server is now ready"; do sleep 10; done
- name: Run Unit Tests
shell: bash -l {0}
- name: Run integration tests
run: |
pip install . --no-build-isolation --no-deps --disable-pip-version-check
pytest --backend=mssql tests/integration
pixi run -e ${{ matrix.env }} postinstall
pixi run -e ${{ matrix.env }} pytest --backend=mssql tests/integration
24 changes: 8 additions & 16 deletions .github/workflows/update_grammar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,23 @@ jobs:
update-grammar:
name: Update TSQL grammar based on antlr4's grammar
runs-on: ubuntu-latest
defaults:
run:
shell: bash -el {0}
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
fetch-depth: 0
- name: Set up pixi
uses: prefix-dev/setup-[email protected]
with:
python-version: 3.11
miniforge-variant: Mambaforge
miniforge-version: 4.11.0-2
use-mamba: true
environment-file: environment.yml
environments: grammar
- name: Download ANTLR
working-directory: src/pytsql/grammar
run: wget https://repo1.maven.org/maven2/org/antlr/antlr4/4.13.1/antlr4-4.13.1-complete.jar
- name: Download latest grammar definition and re-generate grammar targets
working-directory: src/pytsql/grammar
run: |
bash helper_generate_grammar_targets.sh antlr4-4.13.1-complete.jar -d
- name: Install package
run: pip install .
run: pixi run update-grammar
- name: Install package (test compilation)
run:
pixi run -e grammar pip install .
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# pixi environments
.pixi
*.egg-info
79 changes: 60 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,61 @@
exclude: (^\.pixi)|(^src\/pytsql\/grammar\/)
repos:
- repo: https://github.com/Quantco/pre-commit-mirrors-black
rev: 24.4.2
hooks:
- id: black-conda
args:
- --safe
- --target-version=py38
exclude: ^src/pytsql/grammar/
- repo: https://github.com/Quantco/pre-commit-mirrors-ruff
rev: 0.6.2
hooks:
- id: ruff-conda
exclude: ^src/pytsql/grammar/
- repo: https://github.com/Quantco/pre-commit-mirrors-mypy
rev: "1.10.1"
hooks:
- id: mypy-conda
additional_dependencies: [ -c, conda-forge, types-setuptools ]
exclude: ^src/pytsql/grammar/
- repo: local
hooks:
# ensure pixi environments are up to date
# workaround for https://github.com/prefix-dev/pixi/issues/1482
- id: pixi-install
name: pixi-install
entry: pixi install -e default -e lint
language: system
always_run: true
require_serial: true
pass_filenames: false
- id: ruff
name: ruff
entry: pixi run -e lint ruff check --fix --exit-non-zero-on-fix --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
- id: ruff-format
name: ruff-format
entry: pixi run -e lint ruff format --force-exclude
language: system
types_or: [python, pyi]
require_serial: true
- id: mypy
name: mypy
entry: pixi run -e default mypy
language: system
types: [python]
args: ["--ignore-missing-imports", "--scripts-are-modules"]
require_serial: true
# taplo
- id: taplo
name: taplo
entry: pixi run -e lint taplo format
language: system
types: [toml]
# pre-commit-hooks
- id: trailing-whitespace-fixer
name: trailing-whitespace-fixer
entry: pixi run -e lint trailing-whitespace-fixer
language: system
types: [text]
- id: end-of-file-fixer
name: end-of-file-fixer
entry: pixi run -e lint end-of-file-fixer
language: system
types: [text]
- id: check-merge-conflict
name: check-merge-conflict
entry: pixi run -e lint check-merge-conflict --assume-in-merge
language: system
types: [text]
# typos
- id: typos
name: typos
entry: pixi run -e lint typos --force-exclude
language: system
types: [text]
require_serial: true
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ Redistribution and use in source and binary forms, with or without modification,

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ Please also have a look at our documentation sections on [usage](https://pytsql.
## Credits

Grammar is based on [antlr4/grammars-v4](https://github.com/antlr/grammars-v4/tree/master/sql/tsql).

38 changes: 15 additions & 23 deletions docs/source/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,21 @@ Development
===========


The repository comes with a development environment file. We suggest to use ``conda``
and ``mamba``.
The repository relies on ``pixi`` to manage dependencies. Please make sure you have a running version of `pixi <https://pixi.sh/latest/>`_.

In order to get going, you can run
In order to get going, you can run the following

::
.. code-block:: bash
# Clone the repository
git clone [email protected]:Quantco/pytsql.git
cd pytsql

# Set up a conda environment with name "pytsql" and activate it.
mamba env create
conda activate pytsql
$ git clone [email protected]:Quantco/pytsql.git
$ cd pytsql
# Set up our pre-commit hooks for black, mypy, isort and flake8.
pre-commit install
# Set up our pre-commit hooks for e.g. black, mypy and ruff.
$ pixi run pre-commit-install
# Install this package in editable mode.
pip install --no-build-isolation -e .
$ pixi run postinstall
Unit tests
Expand All @@ -30,11 +25,9 @@ Unit tests
``pytsql`` comes with some unit tests. Provided that the environment has been set
up as illustrated in the previous step, they can be run as such:

::
.. code-block:: bash
conda activate pytsql
cd pytsql
pytest tests/unit/
$ pixi run pytest tests/unit/
Integration tests
Expand All @@ -46,18 +39,17 @@ just execute the ``start_mssql.sql`` script provided.

Once the docker container is up and running, you can run the tests:

::
.. code-block:: bash
$ pixi run pytest tests/integration/
conda activate pytsql
cd pytsql
pytest tests/integration/
Add the option ``--backend=mssql-freetds`` to the test command to run the tests using
the ``freetds`` driver.


Grammar
------------------
-------

``pytsql`` relies on parsing the sql script at hand. In order to do so, it uses
`antlr <https://www.antlr.org>`_, a parser generator. ``antlr`` expects grammar files
Expand All @@ -71,7 +63,7 @@ To keep the package structure lean, ``pytql`` aims to be in sync with the refere
Therefore, if you want to extend or modify the grammar please consider contributing to the external repository instead.

Update targets
^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^

All files in ``pytsql/src/pytsql/grammar/cpp_src/antlr4-cpp-runtime`` are taken directly from
the `ANTLR repository release 4.11.1
Expand Down
Loading

0 comments on commit 653486f

Please sign in to comment.