Skip to content

Commit

Permalink
fix: Import grpc only for type checking in errors.py (#4533)
Browse files Browse the repository at this point in the history
* fix: grpc import error

Signed-off-by: tokoko <[email protected]>

* fix: loosen protobuf build requirement

Signed-off-by: tokoko <[email protected]>

* fix: pin grpcio-tools version

Signed-off-by: tokoko <[email protected]>

* fix: revert build-system in pyproject

Signed-off-by: tokoko <[email protected]>

* fix: add manual install of setuptools and grpcio-tools

Signed-off-by: tokoko <[email protected]>

* fix: remove incorrect pixi call

Signed-off-by: tokoko <[email protected]>

* fix: add in-function imports in errors.py

Signed-off-by: tokoko <[email protected]>

* fix: formatting

Signed-off-by: tokoko <[email protected]>

* fix: merge changes from master

Signed-off-by: tokoko <[email protected]>

* fix: add line endings

Signed-off-by: tokoko <[email protected]>

* fix: add line endings

Signed-off-by: tokoko <[email protected]>

* chore: remove proto generation from make commands

Signed-off-by: tokoko <[email protected]>

---------

Signed-off-by: tokoko <[email protected]>
  • Loading branch information
tokoko authored Sep 22, 2024
1 parent 00910bc commit f308572
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
"ghcr.io/devcontainers-contrib/features/maven-sdkman:2": {
"jdkVersion": "11.0.24-amzn"
}
},
}

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

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

// Configure tool-specific properties.
// "customizations": {},
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/smoke_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: smoke-tests

on: [pull_request]
jobs:
unit-test-python:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [ "3.9", "3.10", "3.11"]
os: [ ubuntu-latest ]
env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v4
- name: Setup Python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Get uv cache dir
id: uv-cache
run: |
echo "::set-output name=dir::$(uv cache dir)"
- name: uv cache
uses: actions/cache@v4
with:
path: ${{ steps.uv-cache.outputs.dir }}
key: ${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-uv-${{ hashFiles(format('**/py{0}-ci-requirements.txt', env.PYTHON)) }}
- name: Install dependencies
run: make install-python-dependencies-uv
- name: Test Imports
run: python -c "from feast import cli"
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ build: protos build-java build-docker

# Python SDK

install-python-dependencies-uv:
uv pip sync --system sdk/python/requirements/py$(PYTHON_VERSION)-requirements.txt
uv pip install --system --no-deps .

install-python-dependencies-uv-venv:
uv pip sync sdk/python/requirements/py$(PYTHON_VERSION)-requirements.txt
uv pip install --no-deps .

install-python-ci-dependencies:
python -m piptools sync sdk/python/requirements/py$(PYTHON_VERSION)-ci-requirements.txt
pip install --no-deps -e .
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ requires = [
"sphinx!=4.0.0",
"wheel",
]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
# Including this section is comparable to supplying use_scm_version=True in setup.py.
Expand Down
18 changes: 13 additions & 5 deletions sdk/python/feast/errors.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import importlib
import json
import logging
from typing import Any, List, Optional, Set
from typing import TYPE_CHECKING, Any, List, Optional, Set

from colorama import Fore, Style
from fastapi import status as HttpStatusCode
from grpc import StatusCode as GrpcStatusCode

if TYPE_CHECKING:
from grpc import StatusCode as GrpcStatusCode

from feast.field import Field

Expand All @@ -15,7 +17,9 @@
class FeastError(Exception):
pass

def grpc_status_code(self) -> GrpcStatusCode:
def grpc_status_code(self) -> "GrpcStatusCode":
from grpc import StatusCode as GrpcStatusCode

return GrpcStatusCode.INTERNAL

def http_status_code(self) -> int:
Expand Down Expand Up @@ -89,7 +93,9 @@ def __init__(self, ds_name: str):
class FeastObjectNotFoundException(FeastError):
pass

def grpc_status_code(self) -> GrpcStatusCode:
def grpc_status_code(self) -> "GrpcStatusCode":
from grpc import StatusCode as GrpcStatusCode

return GrpcStatusCode.NOT_FOUND

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

def grpc_status_code(self) -> GrpcStatusCode:
def grpc_status_code(self) -> "GrpcStatusCode":
from grpc import StatusCode as GrpcStatusCode

return GrpcStatusCode.PERMISSION_DENIED

def http_status_code(self) -> int:
Expand Down

0 comments on commit f308572

Please sign in to comment.