Skip to content

Commit f308572

Browse files
authored
fix: Import grpc only for type checking in errors.py (feast-dev#4533)
* fix: grpc import error Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: loosen protobuf build requirement Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: pin grpcio-tools version Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: revert build-system in pyproject Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: add manual install of setuptools and grpcio-tools Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: remove incorrect pixi call Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: add in-function imports in errors.py Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: formatting Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: merge changes from master Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: add line endings Signed-off-by: tokoko <togurgenidze@gmail.com> * fix: add line endings Signed-off-by: tokoko <togurgenidze@gmail.com> * chore: remove proto generation from make commands Signed-off-by: tokoko <togurgenidze@gmail.com> --------- Signed-off-by: tokoko <togurgenidze@gmail.com>
1 parent 00910bc commit f308572

File tree

5 files changed

+61
-8
lines changed

5 files changed

+61
-8
lines changed

.devcontainer/devcontainer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
"ghcr.io/devcontainers-contrib/features/maven-sdkman:2": {
1818
"jdkVersion": "11.0.24-amzn"
1919
}
20-
},
20+
}
2121

2222
// Use 'forwardPorts' to make a list of ports inside the container available locally.
2323
// "forwardPorts": [],
2424

2525
// Uncomment the next line to run commands after the container is created.
26-
"postCreateCommand": "make install-python-ci-dependencies-uv-venv"
26+
// "postCreateCommand": "make install-python-ci-dependencies-uv-venv"
2727

2828
// Configure tool-specific properties.
2929
// "customizations": {},

.github/workflows/smoke_tests.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: smoke-tests
2+
3+
on: [pull_request]
4+
jobs:
5+
unit-test-python:
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
python-version: [ "3.9", "3.10", "3.11"]
11+
os: [ ubuntu-latest ]
12+
env:
13+
OS: ${{ matrix.os }}
14+
PYTHON: ${{ matrix.python-version }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Setup Python
18+
id: setup-python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
architecture: x64
23+
- name: Install uv
24+
run: |
25+
curl -LsSf https://astral.sh/uv/install.sh | sh
26+
- name: Get uv cache dir
27+
id: uv-cache
28+
run: |
29+
echo "::set-output name=dir::$(uv cache dir)"
30+
- name: uv cache
31+
uses: actions/cache@v4
32+
with:
33+
path: ${{ steps.uv-cache.outputs.dir }}
34+
key: ${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-uv-${{ hashFiles(format('**/py{0}-ci-requirements.txt', env.PYTHON)) }}
35+
- name: Install dependencies
36+
run: make install-python-dependencies-uv
37+
- name: Test Imports
38+
run: python -c "from feast import cli"

Makefile

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ build: protos build-java build-docker
3737

3838
# Python SDK
3939

40+
install-python-dependencies-uv:
41+
uv pip sync --system sdk/python/requirements/py$(PYTHON_VERSION)-requirements.txt
42+
uv pip install --system --no-deps .
43+
44+
install-python-dependencies-uv-venv:
45+
uv pip sync sdk/python/requirements/py$(PYTHON_VERSION)-requirements.txt
46+
uv pip install --no-deps .
47+
4048
install-python-ci-dependencies:
4149
python -m piptools sync sdk/python/requirements/py$(PYTHON_VERSION)-ci-requirements.txt
4250
pip install --no-deps -e .

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ requires = [
66
"sphinx!=4.0.0",
77
"wheel",
88
]
9-
build-backend = "setuptools.build_meta"
109

1110
[tool.setuptools_scm]
1211
# Including this section is comparable to supplying use_scm_version=True in setup.py.

sdk/python/feast/errors.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import importlib
22
import json
33
import logging
4-
from typing import Any, List, Optional, Set
4+
from typing import TYPE_CHECKING, Any, List, Optional, Set
55

66
from colorama import Fore, Style
77
from fastapi import status as HttpStatusCode
8-
from grpc import StatusCode as GrpcStatusCode
8+
9+
if TYPE_CHECKING:
10+
from grpc import StatusCode as GrpcStatusCode
911

1012
from feast.field import Field
1113

@@ -15,7 +17,9 @@
1517
class FeastError(Exception):
1618
pass
1719

18-
def grpc_status_code(self) -> GrpcStatusCode:
20+
def grpc_status_code(self) -> "GrpcStatusCode":
21+
from grpc import StatusCode as GrpcStatusCode
22+
1923
return GrpcStatusCode.INTERNAL
2024

2125
def http_status_code(self) -> int:
@@ -89,7 +93,9 @@ def __init__(self, ds_name: str):
8993
class FeastObjectNotFoundException(FeastError):
9094
pass
9195

92-
def grpc_status_code(self) -> GrpcStatusCode:
96+
def grpc_status_code(self) -> "GrpcStatusCode":
97+
from grpc import StatusCode as GrpcStatusCode
98+
9399
return GrpcStatusCode.NOT_FOUND
94100

95101
def http_status_code(self) -> int:
@@ -504,7 +510,9 @@ class FeastPermissionError(FeastError, PermissionError):
504510
def __init__(self, details: str):
505511
super().__init__(f"Permission error:\n{details}")
506512

507-
def grpc_status_code(self) -> GrpcStatusCode:
513+
def grpc_status_code(self) -> "GrpcStatusCode":
514+
from grpc import StatusCode as GrpcStatusCode
515+
508516
return GrpcStatusCode.PERMISSION_DENIED
509517

510518
def http_status_code(self) -> int:

0 commit comments

Comments
 (0)