Skip to content

Commit

Permalink
build(deps): bump pydantic from 1.10.9 to 2.0.2 (#509)
Browse files Browse the repository at this point in the history
* build(deps): bump pydantic from 1.10.9 to 2.0.2

Bumps [pydantic](https://github.com/pydantic/pydantic) from 1.10.9 to 2.0.2.
- [Release notes](https://github.com/pydantic/pydantic/releases)
- [Changelog](https://github.com/pydantic/pydantic/blob/main/HISTORY.md)
- [Commits](pydantic/pydantic@v1.10.9...v2.0.2)

---
updated-dependencies:
- dependency-name: pydantic
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* feat: from the pydantic-2 documentation

__post_init_post_parse__ is no longer supported, and we can replace it
with __post_init__ in our case.

* feat: conditional post_ini based on pydantic version

* fix: another specificity from the migration

* add support for pydantic 1 and 2 in the CI for lint and test

* chore: update the CHANGELOG to get ready for a bump

* feat: update from PR review

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: sanix-darker <s4nixd@gmail.com>
  • Loading branch information
dependabot[bot] and Sanix-Darker authored Jul 13, 2023
1 parent d5325ad commit e9105ab
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 53 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,35 @@ jobs:
python-version:
- "3.10"
- "3.11"
pydantic-version:
- "^1.10"
- "^2.0"

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: install_system_deps
run: sudo make install_system_deps

- name: Update Pydantic version on the toml & lock
run: |
pip install -U pip poetry
# we update the pydantic version corresponding to the matrix
sed -i "s/pydantic = \".*\"/pydantic = \"${PYDANTIC_VERSION}\"/" pyproject.toml
poetry lock --no-update
env:
PYDANTIC_VERSION: ${{ matrix.pydantic-version }}

- name: install
run: make install

- name: lint
run: make lint

- name: mypy
run: make mypy

Expand All @@ -32,19 +49,37 @@ jobs:
python-version:
- "3.10"
- "3.11"
pydantic-version:
- "^1.10"
- "^2.0"

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: install_system_deps
run: sudo make install_system_deps

- name: Update Pydantic version on the toml & lock
run: |
pip install -U pip poetry
# we update the pydantic version corresponding to the matrix
sed -i "s/pydantic = \".*\"/pydantic = \"${PYDANTIC_VERSION}\"/" pyproject.toml
poetry lock --no-update
env:
PYDANTIC_VERSION: ${{ matrix.pydantic-version }}

- name: install
run: make install

- name: test
run: make test
env:
FTP_PATH: ${{ secrets.FTP_PATH }}
PYDANTIC_VERSION: ${{ matrix.pydantic-version }}

- name: Upload coverage
uses: codecov/codecov-action@v3
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### Changed

- Support for pydantic V2 (We still support pydantic >=1 for now).

## [0.11.1] - 2023-04-19

### Added
Expand Down
36 changes: 29 additions & 7 deletions peakina/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from urllib.parse import urlparse, uses_netloc, uses_params, uses_relative

import pandas as pd
from pydantic import ConfigDict, __version__ as pydantic_version
from pydantic.dataclasses import dataclass
from slugify import slugify

Expand All @@ -35,6 +36,9 @@
PD_VALID_URLS = set(uses_relative + uses_netloc + uses_params) | AVAILABLE_SCHEMES


_PYDANTIC_VERSION_ONE = pydantic_version.startswith("1.")


@dataclass
class DataSource:
uri: str
Expand All @@ -44,15 +48,33 @@ class DataSource:
reader_kwargs: dict[str, Any] = field(default_factory=dict)
fetcher_kwargs: dict[str, Any] = field(default_factory=dict)

def __post_init_post_parse__(self) -> None:
self._fetcher: Fetcher | None = None
self.scheme = urlparse(self.uri).scheme
if self.scheme not in PD_VALID_URLS:
raise AttributeError(f"Invalid scheme {self.scheme!r}")
# TODO: This is temporary, in the future we will only support V2
# and get rid of this condition + update the CI (link/test)
if _PYDANTIC_VERSION_ONE:

def __post_init_post_parse__(self) -> None:
self._fetcher: Fetcher | None = None
self.scheme = urlparse(self.uri).scheme
if self.scheme not in PD_VALID_URLS:
raise AttributeError(f"Invalid scheme {self.scheme!r}")

self.type = self.type or detect_type(urlparse(self.uri).path, is_regex=bool(self.match))

validate_kwargs(self.reader_kwargs, self.type)

else:

def __post_init__(self) -> None:
self._fetcher: Fetcher | None = None # type: ignore[no-redef]
self.scheme = urlparse(self.uri).scheme
if self.scheme not in PD_VALID_URLS:
raise AttributeError(f"Invalid scheme {self.scheme!r}")

self.type = self.type or detect_type(urlparse(self.uri).path, is_regex=bool(self.match))

self.type = self.type or detect_type(urlparse(self.uri).path, is_regex=bool(self.match))
validate_kwargs(self.reader_kwargs, self.type)

validate_kwargs(self.reader_kwargs, self.type)
model_config = ConfigDict(arbitrary_types_allowed=True)

@property
def fetcher(self) -> Fetcher:
Expand Down
Loading

0 comments on commit e9105ab

Please sign in to comment.