Skip to content
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

build(deps): bump pydantic from 1.10.9 to 2.0.2 #509

Merged
merged 7 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Comment on lines +13 to +15
Copy link
Member

@PrettyWood PrettyWood Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the make lintisn't it a bit useless?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the job is called "lint" but we have a "mypy" checker on it... should we really remove it ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep it like that


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
Copy link
Contributor

@Sanix-Darker Sanix-Darker Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note : i programmatically update the pyproject.toml file here on 'pydantic = ...' line for CI purposes

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