Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Allow import argilla_server module with pydantic 2.0 #12

Merged
merged 2 commits into from
Feb 5, 2024
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
9 changes: 8 additions & 1 deletion src/argilla_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from argilla_server._app import app # noqa
import warnings

from argilla_server.pydantic_v1 import PYDANTIC_MAJOR_VERSION

if PYDANTIC_MAJOR_VERSION >= 2:
warnings.warn("The argilla_server package is not compatible with Pydantic 2. " "Please use Pydantic 1.x instead.")

Check warning on line 20 in src/argilla_server/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/argilla_server/__init__.py#L20

Added line #L20 was not covered by tests
else:
from argilla_server._app import app # noqa
6 changes: 6 additions & 0 deletions src/argilla_server/pydantic_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from importlib import metadata

try:
from pydantic.v1 import * # noqa: F403
except ImportError:
from pydantic import * # noqa: F403

try:
PYDANTIC_MAJOR_VERSION: int = int(metadata.version("pydantic").split(".")[0])
except metadata.PackageNotFoundError:
PYDANTIC_MAJOR_VERSION = 0

Check warning on line 24 in src/argilla_server/pydantic_v1/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/argilla_server/pydantic_v1/__init__.py#L23-L24

Added lines #L23 - L24 were not covered by tests
Loading