-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support Pydantic V2 #179
Merged
Merged
Support Pydantic V2 #179
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3bfbe29
Update project with pydantic v2
Peter-van-Tol 126403b
Support pydantic v1 and v2
Peter-van-Tol 1dd4b13
Instruct user how to use Pydantic V2
Peter-van-Tol 4fdae28
Modify test to allow pydantic v2
Peter-van-Tol 0deb51b
Update CI.yml
Peter-van-Tol ee7e4d6
Fix reause of validator on Python >3.11
Peter-van-Tol 2d052be
Merge branch 'master' of https://github.com/Peter-van-Tol/GEOLib
Peter-van-Tol c9a7061
Add tests for pydatnic v1
Peter-van-Tol 2bef191
Minor fix for GitHub actions
Peter-van-Tol c4729c5
Use separate caching for v1
Peter-van-Tol 1d5cf10
Don't use lock-file
Peter-van-Tol 1cf2745
Remove v2 packages for v1 testing
Peter-van-Tol 26be53b
Add python-multipart
Peter-van-Tol 5286627
Modify field_type in test (support v1 and v2)
Peter-van-Tol 02b04c7
Fix test
Peter-van-Tol 574100f
Bump pydantic v1 version
Peter-van-Tol ac7b081
Change name to reflect pydantic version
Peter-van-Tol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# This workflow is aimed at testing GEOLib with Pydantic v1 | ||
name: ci-pydantic-v1 | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
CI: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
python-version: [3.9, "3.10", "3.11", "3.12"] | ||
os: [ubuntu-22.04, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/[email protected] | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Run image | ||
uses: abatilo/[email protected] | ||
with: | ||
poetry-version: 1.6.1 | ||
- name: Cache Poetry virtualenv | ||
uses: actions/cache@v3 | ||
id: cache | ||
with: | ||
path: ~/.virtualenvs | ||
key: venv--${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}-v1 | ||
restore-keys: | | ||
venv--${{ matrix.os }}-${{ matrix.python-version }}-v1 | ||
|
||
- name: Set Poetry config | ||
run: | | ||
poetry config virtualenvs.in-project false | ||
poetry config virtualenvs.path ~/.virtualenvs | ||
|
||
# To force Pydantic v1, we install the package before the dependencies. This | ||
# simulates a user who has Pydantic v1 required from another package. | ||
- name: Install Pydantic v1 | ||
run: | | ||
poetry remove pydantic-settings pydantic-extra-types | ||
poetry add pydantic==1.10.7 | ||
|
||
# Install dependencies. This function will take the already installed Pydantic v1 | ||
- name: Install Dependencies | ||
run: poetry install -E server | ||
|
||
- name: Test with pytest | ||
run: poetry run pytest --cov=geolib --cov-report xml:coverage-reports/coverage-hydrolib-core.xml --junitxml=xunit-reports/xunit-result-hydrolib-core.xml -m "unittest and not workinprogress" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""This module contaiuns the logic to support both pydantic v1 and v2 | ||
""" | ||
from pydantic import VERSION as PYDANTIC_VERSION | ||
|
||
IS_PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.") | ||
|
||
if IS_PYDANTIC_V2: | ||
try: | ||
from pydantic_extra_types.color import Color | ||
from pydantic_settings import BaseSettings | ||
except ImportError: | ||
raise ImportError( | ||
"Please install `pydantic-settings` and `pydantic-extra-types` to use geolib with " | ||
"pydantic v2 with `pip install pydantic-settings pydantic-extra-types`. Alternatively, " | ||
"you can install geolib with the extra required packages by running `pip install " | ||
"geolib[pydantic-v2]`." | ||
) | ||
else: | ||
# Example of how to raise a DeprecationWarning. Should be enabled when it is decided to remove | ||
# support for pydantic v1 in a future release. | ||
# raise DeprecationWarning( | ||
# "Support for pydantic v1 will be removed in the next major release. Please upgrade to pydantic v2." | ||
# ) | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contains