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

attempt to upgrade to linkml 1.7 compatibility, mimicing docgen's interaction with generator superclass #14

Merged
merged 13 commits into from
Jun 4, 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
21 changes: 17 additions & 4 deletions .github/workflows/pr-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@ jobs:
strategy:
matrix:
python-version: [ 3.8, 3.9]
services:
solr:
image: solr:8
options: --name my_solr
ports:
- 8983:8983
steps:
- uses: actions/checkout@v2
- name: Sleep for 15 seconds to give Solr time to start
run: sleep 15s
shell: bash
- name: Confirm that Solr is answering
run: curl -s -o /dev/null -w "%{http_code}" http://localhost:8983/solr/ || exit 1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
Expand All @@ -30,7 +41,9 @@ jobs:
with:
path: .venv
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies and run
run: |
poetry install --no-interaction
poetry run python -m unittest
- name: Install dependencies
run: poetry install --no-interaction
- name: add test solr core explicitly
run: poetry run lsolr add-cores test
- name: run tests
run: poetry run python -m unittest -v
3 changes: 1 addition & 2 deletions linkml_solr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ def create_schema(schema, url, core, debug, dry_run, top_class):
qe = SolrQueryEngine(schema=schema_obj,
endpoint=SolrEndpoint(url=f'{url}/{core}'),
top_class=top_class)

gen = qe.load_schema(dry_run=dry_run)
gen = qe.load_schema(dry_run=dry_run,)
if debug:
print(gen.serialize())

Expand Down
11 changes: 8 additions & 3 deletions linkml_solr/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,14 @@ def load_schema(self, dry_run: bool = False) -> SolrSchemaGenerator:
'name': 'date',
'class': 'solr.TrieDateField',
}}, path='schema')
gen = SolrSchemaGenerator(self.schema, top_class=self.top_class)
gen.serialize()
post_obj = gen.post_request
gen = SolrSchemaGenerator(self.schema)

if self.top_class:
post_obj = json.loads(gen.class_schema(self.top_class))
else:
gen.serialize()
post_obj = gen.post_request

for f in post_obj['add-field']:
if f['name'] not in existing_fields and not dry_run:
self._solr_request({'add-field': f}, path='schema')
Expand Down
16 changes: 10 additions & 6 deletions linkml_solr/solrschemagen.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,23 @@ class SolrSchemaGenerator(Generator):
generatorname = os.path.basename(__file__)
generatorversion = "0.0.1"
valid_formats = ["json"]
uses_schemaloader = False
visit_all_class_slots = True
transaction: Transaction = None
schemaview: SchemaView = None

def __init__(self, schema: Union[str, TextIO, SchemaDefinition], top_class: Optional[str] = None, **kwargs) -> None:
super().__init__(schema, **kwargs)
# def __init__(self, schema: Union[str, TextIO, SchemaDefinition], top_class: Optional[str] = None, **kwargs) -> None:
def __post_init__(self) -> None:
# super().__init__(schema, **kwargs)
#self.schema = schema
self.transaction = Transaction()
self.post_request = None
self.inline = False
self.topCls = top_class ## SOLR object is one instance of this
self.entryProperties = {}
# SOLR-Schema does not have inheritance,
# so we duplicate slots from inherited parents and mixins
self.visit_all_slots = True
super().__post_init__()
self.schemaview = SchemaView(self.schema)

def _transaction_json(self, transaction: Transaction) -> str:
Expand All @@ -79,8 +81,6 @@ def get_transaction(self, class_name: Union[str, ClassDefinitionName] = None) ->
sv = self.schemaview
field_dict = {}
for cn, c in sv.all_classes().items():
if self.topCls is not None and str(cn) != str(self.topCls):
continue
if class_name is None or str(cn) == str(class_name):
for s in sv.class_induced_slots(cn):
field = self.get_field(s)
Expand All @@ -95,10 +95,14 @@ def get_field(self, slot: SlotDefinition) -> Field:
range = 'string' # FK
elif range in self.schema.enums:
range = 'string'
elif range is None:
range = self.schemaview.schema.default_range if self.schemaview.schema.default_range else 'string'
elif range in self.schema.types:
t = self.schema.types[range]
range = t.typeof
if t.typeof is None:
if t.repr == 'str':
range = 'string'
elif range is None:
range = t.base
range = str(range).lower()
if range in solr_schema_types:
Expand Down
Loading
Loading