Skip to content

Commit 7f7cd5d

Browse files
committed
Merge remote-tracking branch 'origin/main' into csv-test
2 parents 48a1ae6 + 8a8ee69 commit 7f7cd5d

File tree

169 files changed

+31441
-11472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+31441
-11472
lines changed

.github/workflows/main.yaml

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Built from:
22
# https://docs.github.com/en/actions/guides/building-and-testing-python
3-
# https://github.com/snok/install-poetry#workflows-and-tips
3+
# https://github.com/actions/setup-python/
44

55
name: Build and test linkml-runtime
66

@@ -23,42 +23,24 @@ jobs:
2323

2424
steps:
2525

26+
#----------------------------------------------
27+
# install poetry
28+
#----------------------------------------------
29+
- name: Install Poetry
30+
# Pin to 1.3.2 to workaround https://github.com/python-poetry/poetry/issues/7611
31+
run: pipx install poetry==1.3.2
32+
2633
#----------------------------------------------
2734
# check-out repo and set-up python
2835
#----------------------------------------------
2936
- name: Check out repository
30-
uses: actions/checkout@v2
37+
uses: actions/checkout@v3
3138

3239
- name: Set up Python ${{ matrix.python-version }}
33-
uses: actions/setup-python@v2
40+
uses: actions/setup-python@v4
3441
with:
3542
python-version: ${{ matrix.python-version }}
36-
37-
#----------------------------------------------
38-
# install & configure poetry
39-
#----------------------------------------------
40-
- name: Install Poetry
41-
uses: snok/install-poetry@v1.3
42-
with:
43-
virtualenvs-create: true
44-
virtualenvs-in-project: true
45-
46-
#----------------------------------------------
47-
# load cached venv if cache exists
48-
#----------------------------------------------
49-
- name: Load cached venv
50-
id: cached-poetry-dependencies
51-
uses: actions/cache@v2
52-
with:
53-
path: .venv
54-
key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }}
55-
56-
#----------------------------------------------
57-
# install dependencies if cache does not exist
58-
#----------------------------------------------
59-
- name: Install dependencies
60-
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
61-
run: poetry install --no-interaction --no-root
43+
cache: 'poetry'
6244

6345
#----------------------------------------------
6446
# install your root project, if required
@@ -85,7 +67,7 @@ jobs:
8567
# upload coverage results
8668
#----------------------------------------------
8769
- name: Upload coverage report
88-
uses: codecov/codecov-action@v1.0.5
70+
uses: codecov/codecov-action@v3
8971
with:
9072
name: codecov-results-${{ matrix.os }}-${{ matrix.python-version }}
9173
token: ${{ secrets.CODECOV_TOKEN }}

.github/workflows/pypi-publish.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ jobs:
1818
python-version: 3.8
1919

2020
- name: Install Poetry
21-
uses: snok/install-poetry@v1.1.6
22-
with:
23-
virtualenvs-create: true
24-
virtualenvs-in-project: true
21+
run: pipx install poetry
2522

2623
- name: Install dependencies
2724
run: poetry install --no-interaction

CONTRIBUTING.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@ When contributing to this repository, please first discuss the changes you wish
66

77
### Reporting bugs or making feature requests
88

9-
You can use the [Issues](https://github.com/linkml/linkml-runtime/issues) tab to create bug and feature requests. Providing enough details to the developers to verify and troubleshoot your issue is paramount:
9+
To report a bug or suggest a new feature, please go to the [linkml/linkml issue tracker](https://github.com/linkml/linkml/issues), as we are
10+
consolidating issues there.
11+
12+
Please supply enough details to the developers to enable them to verify and troubleshoot your issue:
1013

1114
* Provide a clear and descriptive title as well as a concise summary of the issue to identify the problem.
1215
* Describe the exact steps which reproduce the problem in as many details as possible.
1316
* Describe the behavior you observed after following the steps and point out what exactly is the problem with that behavior.
1417
* Explain which behavior you expected to see instead and why.
1518
* Provide screenshots of the expected or actual behaviour where applicable.
16-
* Tag the issue with appropriate label names. For ex., if your issue is about a bug that needs to be fixed in the repo, tag the issue with the `bug` label from the list of [labels](https://github.com/linkml/linkml-runtime/labels). If an appropriate label name doesn't exist, create one, with a name that clearly encapsulates the topic of the issue.
19+
* Tag the issue with appropriate label names. For example, if your issue is about a bug that needs to be fixed in the repo, tag the issue with the `bug` label from the list of [labels](https://github.com/linkml/linkml-runtime/labels). If an appropriate label doesn't exist, create one, with a name that clearly encapsulates the topic of the issue.
1720

1821
### The development lifecycle
1922

@@ -24,6 +27,8 @@ You can use the [Issues](https://github.com/linkml/linkml-runtime/issues) tab to
2427

2528
Note: All the development must be done on a branch on your fork.
2629

30+
ALSO NOTE: github.com lets you create a pull request from the main branch, automating the steps above.
31+
2732
> A code review (which happens with both the contributor and the reviewer present) is required for contributing.
2833
2934
## Development environment setup

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ update_model:
1111

1212
test:
1313
poetry run python -m unittest discover
14+
15+
# temporary measure until linkml-model is synced
16+
linkml_runtime/processing/validation_datamodel.py: linkml_runtime/processing/validation_datamodel.yaml
17+
gen-python $< > $@.tmp && mv $@.tmp $@

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![PyPIDownloadsMonth](https://img.shields.io/pypi/dm/linkml-runtime?logo=PyPI&color=blue)](https://pypi.org/project/linkml-runtime)
88
[![codecov](https://codecov.io/gh/linkml/linkml-runtime/branch/main/graph/badge.svg?token=FOBHNSK5WG)](https://codecov.io/gh/linkml/linkml-runtime)
99

10-
Runtime support for linkml generated models
10+
Runtime support for linkml generated data classes
1111

1212
## About
1313

linkml_runtime/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from pathlib import Path
12
from linkml_runtime.utils.curienamespace import CurieNamespace
23
from linkml_runtime.utils.schemaview import SchemaView
34
from rdflib import RDF, RDFS, SKOS, XSD, OWL
@@ -21,6 +22,13 @@
2122
__version__ = importlib_metadata.version(__name__)
2223

2324

25+
THIS_PATH = Path(__file__).parent
26+
27+
SCHEMA_DIRECTORY = THIS_PATH / "linkml_model" / "model" / "schema"
28+
29+
MAIN_SCHEMA_PATH = SCHEMA_DIRECTORY / "meta.yaml"
30+
31+
2432
class MappingError(ValueError):
2533
"""
2634
An error when mapping elements of a LinkML model to runtime objects

linkml_runtime/dumpers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from linkml_runtime.dumpers.json_dumper import JSONDumper
22
from linkml_runtime.dumpers.rdf_dumper import RDFDumper
33
from linkml_runtime.dumpers.rdflib_dumper import RDFLibDumper
4+
from linkml_runtime.dumpers.tsv_dumper import TSVDumper
45
from linkml_runtime.dumpers.yaml_dumper import YAMLDumper
56
from linkml_runtime.dumpers.csv_dumper import CSVDumper
67

@@ -9,3 +10,4 @@
910
rdflib_dumper = RDFLibDumper()
1011
yaml_dumper = YAMLDumper()
1112
csv_dumper = CSVDumper()
13+
tsv_dumper = TSVDumper()
Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,8 @@
1-
import io
2-
import yaml
3-
import json
4-
from typing import Dict, List, Any
1+
from linkml_runtime.dumpers.delimited_file_dumper import DelimitedFileDumper
52

6-
from linkml_runtime.dumpers.dumper_root import Dumper
7-
from linkml_runtime.dumpers.json_dumper import JSONDumper
8-
from linkml_runtime.utils.yamlutils import YAMLRoot
9-
from linkml_runtime.linkml_model.meta import SlotDefinitionName, SchemaDefinition
10-
from linkml_runtime.utils.schemaview import SchemaView
113

12-
from linkml_runtime.utils.csvutils import GlobalConfig, get_configmap
13-
from json_flattener import flatten_to_csv
4+
class CSVDumper(DelimitedFileDumper):
145

15-
16-
class CSVDumper(Dumper):
17-
18-
def dumps(self, element: YAMLRoot,
19-
index_slot: SlotDefinitionName = None,
20-
schema: SchemaDefinition = None,
21-
schemaview: SchemaView = None,
22-
**kwargs) -> str:
23-
""" Return element formatted as CSV lines """
24-
json_dumper = JSONDumper()
25-
element_j = json.loads(json_dumper.dumps(element))
26-
objs = element_j[index_slot]
27-
if schemaview is None:
28-
schemaview = SchemaView(schema)
29-
configmap = get_configmap(schemaview, index_slot)
30-
config = GlobalConfig(key_configs=configmap)
31-
output = io.StringIO()
32-
flatten_to_csv(objs, output, config=config, **kwargs)
33-
return output.getvalue()
6+
@property
7+
def delimiter(self):
8+
return ","
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import io
2+
import yaml
3+
import json
4+
from abc import ABC, abstractmethod
5+
from typing import Union
6+
from pydantic import BaseModel
7+
8+
from linkml_runtime.dumpers.dumper_root import Dumper
9+
from linkml_runtime.dumpers.json_dumper import JSONDumper
10+
from linkml_runtime.utils.yamlutils import YAMLRoot
11+
from linkml_runtime.linkml_model.meta import SlotDefinitionName, SchemaDefinition
12+
from linkml_runtime.utils.schemaview import SchemaView
13+
14+
from linkml_runtime.utils.csvutils import GlobalConfig, get_configmap
15+
from json_flattener import flatten_to_csv
16+
17+
18+
class DelimitedFileDumper(Dumper, ABC):
19+
20+
@property
21+
@abstractmethod
22+
def delimiter(self):
23+
pass
24+
25+
def dumps(self, element: Union[BaseModel, YAMLRoot],
26+
index_slot: SlotDefinitionName = None,
27+
schema: SchemaDefinition = None,
28+
schemaview: SchemaView = None,
29+
**kwargs) -> str:
30+
""" Return element formatted as CSV lines """
31+
json_dumper = JSONDumper()
32+
element_j = json.loads(json_dumper.dumps(element))
33+
objs = element_j[index_slot]
34+
if schemaview is None:
35+
schemaview = SchemaView(schema)
36+
configmap = get_configmap(schemaview, index_slot)
37+
config = GlobalConfig(key_configs=configmap, csv_delimiter=self.delimiter)
38+
output = io.StringIO()
39+
flatten_to_csv(objs, output, config=config, **kwargs)
40+
return output.getvalue()

linkml_runtime/dumpers/dumper_root.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from abc import ABC, abstractmethod
2+
from typing import Union
23

34
from linkml_runtime.utils.yamlutils import YAMLRoot
5+
from pydantic import BaseModel
46

57

68
class Dumper(ABC):
79
""" Abstract base class for all dumpers """
810

9-
def dump(self, element: YAMLRoot, to_file: str, **_) -> None:
11+
def dump(self, element: Union[BaseModel, YAMLRoot], to_file: str, **_) -> None:
1012
"""
1113
Write element to to_file
1214
:param element: LinkML object to be dumped
@@ -17,10 +19,10 @@ def dump(self, element: YAMLRoot, to_file: str, **_) -> None:
1719
output_file.write(self.dumps(element, **_))
1820

1921
@abstractmethod
20-
def dumps(self, element: YAMLRoot, **_) -> str:
22+
def dumps(self, element: Union[BaseModel, YAMLRoot], **_) -> str:
2123
"""
2224
Convert element to a string
23-
@param element: YAMLRoot object to be rendered
25+
@param element: Union[BaseModel, YAMLRoot] object to be rendered
2426
@param _: method specific arguments
2527
@return: stringified representation of element
2628
"""

0 commit comments

Comments
 (0)