Skip to content

Commit

Permalink
Merge pull request #70 from eseglem/develop
Browse files Browse the repository at this point in the history
Cleanup and Updates
  • Loading branch information
eseglem authored Feb 9, 2024
2 parents 07b2d60 + 857804a commit 8bea64d
Show file tree
Hide file tree
Showing 85 changed files with 1,833 additions and 1,171 deletions.
10 changes: 4 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
[*]
end_of_line = lf
insert_final_newline = true

[*.py]
charset = utf-8
insert_final_newline = true
end_of_line = lf
indent_style = space
trim_trailing_whitespace = true
indent_size = 4

[*.json]
indent_style = space
[*.json,*.yaml,*.yml]
indent_size = 2
51 changes: 51 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Release

on:
workflow_dispatch:

jobs:
run-tests:
uses: ./.github/workflows/tests.yaml

release:
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
id-token: write

steps:
- name: Checkout the repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: poetry

- name: Install dependencies
run: poetry install --no-dev

- name: Get release version
id: release-version
run: echo "RELEASE_VERSION=v$(poetry version --short)" >> "$GITHUB_OUTPUT"

- name: Build package
run: poetry build

- name: Upload the files to the release
uses: ncipollo/release-action@v1
with:
artifacts: ${{ github.workspace }}/dist/*
tag: ${{ steps.release-version.outputs.RELEASE_VERSION }}
commit: ${{ github.sha }}
omitBody: true

- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
50 changes: 21 additions & 29 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,42 @@ name: Tests

on:
push:
branches: [main]
tags: ["v*"]
branches:
- main
- develop
pull_request:
branches: [main]
branches:
- main
- develop
workflow_call:

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"

steps:
- uses: actions/checkout@v4
- name: Checkout the repository
uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"
cache: poetry

- name: Install dependencies
run: poetry install -E test
- name: Run tests with coverage
run: poetry run pytest --ignore=tests/test_pycql2_hypothesis.py --cov=pycql2 --cov-report=xml tests/

publish:
needs: [tests]
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
cache: "poetry"
- name: Install dependencies
run: poetry install --no-dev
- name: Build package
run: poetry build
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Run tests with coverage
run: poetry run pytest --ignore=tests/test_pycql2_hypothesis.py --cov=pycql2 --cov-report=term-missing tests/
121 changes: 119 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,direnv,python,windows,visualstudiocode
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,direnv,python,windows,visualstudiocode

### direnv ###
.direnv
.envrc

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -152,5 +208,66 @@ dmypy.json
# Cython debug symbols
cython_debug/

# VSCode
.vscode/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# 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/

### Python Patch ###
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
poetry.toml

# ruff
.ruff_cache/

# LSP config files
pyrightconfig.json

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix

### VisualStudioCode Patch ###
# Ignore all local history of files
.history
.ionide

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,direnv,python,windows,visualstudiocode
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,11 @@ repos:
- id: pyupgrade
args: ["--py38-plus", "--keep-runtime-typing"]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
rev: v0.2.0
hooks:
- id: ruff
args: ["--fix"]
- repo: https://github.com/psf/black
rev: 23.12.1
hooks:
- id: black
language_version: python
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
Expand Down
12 changes: 12 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"recommendations": [
"charliermarsh.ruff",
"DavidAnson.vscode-markdownlint",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode",
"ms-python.debugpy",
"ms-python.python",
"ms-python.vscode-pylance",
"tamasfe.even-better-toml"
]
}
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": "always",
"source.organizeImports": "always"
},
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.inlineSuggest.enabled": true
},
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"markdownlint.config": {
"ul-indent": {
"indent": 4
}
}
}
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,36 @@ When parsing cql2-text to cql2-json.
- `... NOT IN ...` become `NOT ... IN ...`
- `... IS NOT NULL` becomes `NOT ... IS NULL`
- Negative arithmetic operands become a multiply by -1: `{"op": "*", "params": [-1, <arithmetic_operand>]}`
- Within a Character Literal, the character (`'` or `\`) used to escape a single quote is not preserved.
- Any `''` will become `\'`

The cql2-text output from the pydantic models is opinionated and explicit. These choices have been made to keep the logic simple while ensuring the correctness of the output.

- All property names are double quoted `"`.
- Character Literals escape single quotes with a backslash `\'`.
- Parenthesis `()` are placed around all comparison and arithmetic operations.
- This means that many outputs include a set of parentheses around the whole string. While this is not ideal, it is also not incorrect. When more tests are in place, they can be used to determine if a safe and easy way exists to remove them.
- This means that many outputs include a set of parentheses around the whole string.
- This may not be not ideal, but it is also not incorrect.
- Additional testing may be done in the future to determine if a safe and easy way exists to remove them.
- Timestamps always contain decimal seconds out to 6 decimal places even when 0: `.000000`. It uses `strftime` with `%f` currently. Logic may be added later to adjust this.
- Floats ending in `.0` will include the `.0` in the text. Where other libraries such as `shapely` will not include them in WKT.

The cql2-text spec was not strictly followed for WKT. Some tweaks were made to increase it is compatible with `geojson-pydantic`, as well as accept the WKT output.

- Added optional `Z` to each geometry. It doesn't enforce 2d / 3d, just allows the character to be there.
- Added optional `Z` to each geometry.
- This does not enforce 2d / 3d, just allows the character to be there.
- LineString coordinates require a minimum of 2 coordinates.
- Added 'Linear Ring' for use in Polygons with a minimum of 4 coordinates. It doesn't enforce the ring being closed, just that it has enough coordinates to be one.
- Added 'Linear Ring' for use in Polygons with a minimum of 4 coordinates.
- This does not enforce the ring being closed, just that it contains enough coordinates to be one.
- Moved BBOX so it cannot be included in GeometryCollection.
- Moved GeometryCollection to not allow nesting, until support is added to `geojson-pydantic`.
- Added alternative MultiPoint syntax to maintain compatibility with other spatial tools and libraries.
- Allows reading of `MUTLIPOINT(0 0, 1 1)` without the inner parenthesis.
- This may be removed in the future if it is no longer necessary for compatibility. Removal will be considered a breaking change and be versioned as such.
- Note: Output will always include the inner parenthesis (via `geojson-pydantic`).

There are a few things which **may** be issues with the spec but have not been fully addressed yet.

- (Partially addressed) `spatial_literal` includes `geometry_collection` and `bbox`, and `geometry_collection` allows for all `spatial_literal` within it. But `bbox` does not seem to be a part of WKT. And at least within GeoJSON, nested `GeometryCollection` "SHOULD be avoided". This would mean the `cql2-text -> cql2-json` conversion would break where `geojson-pydantic` doesn't accept these cases.
- `spatial_literal` includes `bbox`, and `geometry_collection` allows for all `spatial_literal` within it. But `bbox` does not seem to be a part of WKT. This would mean the `cql2-text -> cql2-json` conversion would break where `geojson-pydantic` doesn't accept these cases.
- The spec does not allow for `EMPTY` geometries.

## Testing
Expand All @@ -45,7 +55,6 @@ Each file in `tests/data/json/` is a standalone cql2-json example. There will be
While 100% of the lines of code are covered, more complex examples with more nested logic will be added in the future. As well as more variety to various inputs, the current examples are mostly PropertyRef and numbers. Such as:

- More complex identifiers with `_`, `.`, `:`, and non ascii letters.
- Character literals with escaped quote.
- Deeply nested logic.
- Each type of `scalar_expression` on each side of a `binary_comparison_predicate`, etc.

Expand Down
Loading

0 comments on commit 8bea64d

Please sign in to comment.