Skip to content

Commit be76bb9

Browse files
committed
feat: lint workflow + isort fix
1 parent a2ca2ec commit be76bb9

File tree

10 files changed

+95
-70
lines changed

10 files changed

+95
-70
lines changed

.github/workflows/lint.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Lint
16+
on:
17+
pull_request:
18+
paths-ignore: # Changes to the paths list need to be reflected in lint_fallback.yml
19+
- "*.md"
20+
- ".kokoro/**"
21+
- ".github/**"
22+
23+
jobs:
24+
lint:
25+
runs-on: ubuntu-latest
26+
permissions:
27+
contents: read
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.ref }}
30+
cancel-in-progress: true
31+
32+
steps:
33+
- name: Checkout Repository
34+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3
35+
36+
- name: Setup Python
37+
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0
38+
with:
39+
python-version: "3.11"
40+
41+
- name: Install requirements
42+
run: pip install -r requirements.txt
43+
44+
- name: Install module (and test requirements)
45+
run: pip install -e .[test]
46+
47+
- name: Install linters and type-check
48+
run: pip install black black[jupyter] isort mypy
49+
50+
- name: Run linters
51+
run: |
52+
black --check .
53+
isort --check .
54+
55+
# - name: Run type-check
56+
# run: mypy --install-types --non-interactive .

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
google-cloud-spanner==3.51.0
2+
llama-index-core==0.12.0

src/llama_index_spanner/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .version import __version__
15+
from .graph_retriever import (SpannerGraphCustomRetriever,
16+
SpannerGraphTextToGQLRetriever)
1617
from .property_graph_store import SpannerPropertyGraphStore
17-
from .graph_retriever import (
18-
SpannerGraphCustomRetriever,
19-
SpannerGraphTextToGQLRetriever,
20-
)
18+
from .version import __version__
2119

2220
__all__ = [
2321
__version__,

src/llama_index_spanner/graph_retriever.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,17 @@
2121
from llama_index.core.output_parsers import PydanticOutputParser
2222
from llama_index.core.postprocessor.llm_rerank import LLMRerank
2323
from llama_index.core.prompts import PromptType
24-
from llama_index.core.retrievers import (
25-
CustomPGRetriever,
26-
VectorContextRetriever,
27-
)
24+
from llama_index.core.retrievers import (CustomPGRetriever,
25+
VectorContextRetriever)
2826
from llama_index.core.schema import NodeWithScore, QueryBundle, TextNode
2927
from llama_index.core.vector_stores.types import VectorStore
3028
from pydantic import BaseModel
3129

3230
from .graph_utils import extract_gql, fix_gql_syntax
33-
from .prompts import (
34-
DEFAULT_GQL_FIX_TEMPLATE,
35-
DEFAULT_GQL_VERIFY_TEMPLATE,
36-
DEFAULT_SPANNER_GQL_TEMPLATE,
37-
DEFAULT_SUMMARY_TEMPLATE,
38-
)
31+
from .prompts import (DEFAULT_GQL_FIX_TEMPLATE, DEFAULT_GQL_VERIFY_TEMPLATE,
32+
DEFAULT_SPANNER_GQL_TEMPLATE, DEFAULT_SUMMARY_TEMPLATE)
3933
from .property_graph_store import SpannerPropertyGraphStore
4034

41-
4235
GQL_GENERATION_PROMPT = PromptTemplate(
4336
template=DEFAULT_SPANNER_GQL_TEMPLATE,
4437
prompt_type=PromptType.TEXT_TO_GRAPH_QUERY,

src/llama_index_spanner/property_graph_store.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,16 @@
1717
from typing import Any, Dict, List, Optional, Tuple
1818

1919
from google.cloud import spanner
20-
from llama_index.core.graph_stores.types import (
21-
ChunkNode,
22-
EntityNode,
23-
LabelledNode,
24-
PropertyGraphStore,
25-
Relation,
26-
Triplet,
27-
)
20+
from llama_index.core.graph_stores.types import (ChunkNode, EntityNode,
21+
LabelledNode,
22+
PropertyGraphStore, Relation,
23+
Triplet)
2824
from llama_index.core.prompts import PromptTemplate, PromptType
2925
from llama_index.core.vector_stores.types import VectorStoreQuery
3026

3127
from .prompts import DEFAULT_SPANNER_GQL_TEMPLATE
32-
from .schema import (
33-
ElementSchema,
34-
GraphDocumentUtility,
35-
SpannerGraphSchema,
36-
group_edges,
37-
group_nodes,
38-
)
28+
from .schema import (ElementSchema, GraphDocumentUtility, SpannerGraphSchema,
29+
group_edges, group_nodes)
3930
from .spanner import SpannerImpl, SpannerInterface, client_with_user_agent
4031
from .version import __version__
4132

src/llama_index_spanner/schema.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@
1414

1515
from __future__ import annotations
1616

17-
import json, re
17+
import json
18+
import re
1819
from typing import Any, Dict, Generator, Iterable, List, Optional, Tuple
1920

2021
from google.cloud.spanner_v1 import JsonObject, param_types
21-
from llama_index.core.graph_stores.types import (
22-
ChunkNode,
23-
EntityNode,
24-
LabelledNode,
25-
Relation,
26-
)
22+
from llama_index.core.graph_stores.types import (ChunkNode, EntityNode,
23+
LabelledNode, Relation)
2724
from requests.structures import CaseInsensitiveDict
2825

2926
from .type_utils import TypeUtility

src/llama_index_spanner/spanner.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
from abc import ABC, abstractmethod
1616
from typing import Any, Dict, List, Optional, Tuple
17+
1718
from google.cloud import spanner
19+
1820
from .type_utils import TypeUtility
1921

2022
MUTATION_BATCH_SIZE = 1000

tests/test_graph_retriever.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from llama_index.core import PropertyGraphIndex
16-
from llama_index.core import Settings
17-
from llama_index.core.graph_stores.types import (
18-
ChunkNode,
19-
EntityNode,
20-
Relation,
21-
)
15+
import pytest
16+
from llama_index.core import PropertyGraphIndex, Settings
17+
from llama_index.core.graph_stores.types import ChunkNode, EntityNode, Relation
2218
from llama_index.core.indices.property_graph import SchemaLLMPathExtractor
2319
from llama_index.core.query_engine import RetrieverQueryEngine
2420
from llama_index.readers.wikipedia import WikipediaReader
25-
import pytest
21+
2622
from llama_index_spanner.graph_retriever import (
27-
SpannerGraphCustomRetriever,
28-
SpannerGraphTextToGQLRetriever,
29-
)
23+
SpannerGraphCustomRetriever, SpannerGraphTextToGQLRetriever)
3024
from tests.utils import get_resources
3125

3226

tests/test_spanner_property_graph_store.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,21 @@
1313
# limitations under the License.
1414

1515
from typing import Generator
16-
from llama_index.core.graph_stores.types import (
17-
ChunkNode,
18-
EntityNode,
19-
Relation,
20-
)
21-
from llama_index.core.vector_stores.types import (
22-
ExactMatchFilter,
23-
FilterCondition,
24-
FilterOperator,
25-
MetadataFilter,
26-
MetadataFilters,
27-
VectorStoreQuery,
28-
)
16+
2917
import pytest
18+
from llama_index.core.graph_stores.types import ChunkNode, EntityNode, Relation
19+
from llama_index.core.vector_stores.types import (ExactMatchFilter,
20+
FilterCondition,
21+
FilterOperator,
22+
MetadataFilter,
23+
MetadataFilters,
24+
VectorStoreQuery)
25+
3026
from llama_index_spanner.property_graph_store import SpannerPropertyGraphStore
3127
from llama_index_spanner.schema import ElementSchema
32-
from tests.utils import (
33-
get_random_suffix,
34-
get_spanner_property_graph_store,
35-
spanner_database_id,
36-
spanner_graph_name,
37-
spanner_instance_id,
38-
)
39-
28+
from tests.utils import (get_random_suffix, get_spanner_property_graph_store,
29+
spanner_database_id, spanner_graph_name,
30+
spanner_instance_id)
4031

4132
pytestmark = pytest.mark.skipif(
4233
(not spanner_instance_id or not spanner_database_id or not spanner_graph_name),

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from llama_index.core.storage import StorageContext
1919
from llama_index.embeddings.google_genai import GoogleGenAIEmbedding
2020
from llama_index.llms.google_genai import GoogleGenAI
21+
2122
from llama_index_spanner import SpannerPropertyGraphStore
2223

2324
spanner_instance_id = os.environ.get("SPANNER_INSTANCE_ID") or "graphdb-spanner-llama"

0 commit comments

Comments
 (0)