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

0.2.2 release #66

Merged
merged 6 commits into from
Nov 16, 2023
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
87 changes: 75 additions & 12 deletions docs/api_docs.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Final targets: convert_project, get_available_pep_filters, inspect_project, read_schema, validate_config, validate_project, validate_sample
Final targets: EidoValidationError, convert_project, get_available_pep_filters, get_input_files_size, inspect_project, read_schema, validate_config, validate_input_files, validate_project, validate_sample
<script>
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelectorAll('h3 code').forEach((block) => {
Expand All @@ -8,7 +8,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
</script>

<style>
h3 .content {
h3 .content {
padding-left: 22px;
text-indent: -15px;
}
Expand All @@ -19,7 +19,7 @@ h3 .hljs .content {
martin-bottom: 0px;
}
h4 .content, table .content, p .content, li .content { margin-left: 30px; }
h4 .content {
h4 .content {
font-style: italic;
font-size: 1em;
margin-bottom: 0px;
Expand All @@ -33,22 +33,33 @@ h4 .content {

Project configuration

## <a name="EidoValidationError"></a> Class `EidoValidationError`
Object was not validated successfully according to schema.


```python
def validate_project(project, schema, exclude_case=False)
def __init__(self, message, errors_by_type)
```

Initialize self. See help(type(self)) for accurate signature.



```python
def validate_project(project, schema)
```

Validate a project object against a schema
#### Parameters:

- `project` (`peppy.Sample`): a project object to validate
- `schema` (`str | dict`): schema dict to validate against or a path to one
- `exclude_case` (`bool`): whether to exclude validated objectsfrom the error. Useful when used ith large projects
- `project` (`peppy.Project`): a project object to validate
- `schema` (`str | dict`): schema dict to validate against or a path to onefrom the error. Useful when used ith large projects




```python
def validate_sample(project, sample_name, schema, exclude_case=False)
def validate_sample(project, sample_name, schema)
```

Validate the selected sample object against a schema
Expand All @@ -57,21 +68,19 @@ Validate the selected sample object against a schema
- `project` (`peppy.Project`): a project object to validate
- `sample_name` (`str | int`): name or index of the sample to validate
- `schema` (`str | dict`): schema dict to validate against or a path to one
- `exclude_case` (`bool`): whether to exclude validated objectsfrom the error. Useful when used ith large projects




```python
def validate_config(project, schema, exclude_case=False)
def validate_config(project, schema)
```

Validate the config part of the Project object against a schema
#### Parameters:

- `project` (`peppy.Project`): a project object to validate
- `schema` (`str | dict`): schema dict to validate against or a path to one
- `exclude_case` (`bool`): whether to exclude validated objectsfrom the error. Useful when used ith large projects



Expand Down Expand Up @@ -145,7 +154,61 @@ Convert a `peppy.Project` object to a selected format



```python
def validate_input_files(project, schemas, sample_name=None)
```

Determine which of the required and optional files are missing.

The names of the attributes that are required and/or deemed as inputs
are sourced from the schema, more specifically from `required_files`
and `files` sections in samples section:
- If any of the required files are missing, this function raises an error.
- If any of the optional files are missing, the function raises a warning.
Note, this function also performs Sample object validation with jsonschema.
#### Parameters:

- `project` (`peppy.Project`): project that defines the samples to validate
- `schema` (`str | dict`): schema dict to validate against or a path to one
- `sample_name` (`str | int`): name or index of the sample to validate. If None,validate all samples in the project


#### Raises:

- `PathAttrNotFoundError`: if any required sample attribute is missing




```python
def get_input_files_size(sample, schema)
```

Determine which of this Sample's required attributes/files are missing and calculate sizes of the files (inputs).

The names of the attributes that are required and/or deemed as inputs
are sourced from the schema, more specifically from required_input_attrs
and input_attrs sections in samples section. Note, this function does
perform actual Sample object validation with jsonschema.
#### Parameters:

- `sample` (`peppy.Sample`): sample to investigate
- `schema` (`list[dict] | str`): schema dict to validate against or a path to one


#### Returns:

- `dict`: dictionary with validation data, i.e missing,required_inputs, all_inputs, input_file_size


#### Raises:

- `ValidationError`: if any required sample attribute is missing







*Version Information: `eido` v0.1.5-dev, generated by `lucidoc` v0.4.2*
*Version Information: `eido` v0.2.2-dev, generated by `lucidoc` v0.4.4*
14 changes: 3 additions & 11 deletions docs/autodoc_build/eido.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,19 @@ h4 .content {
# Package `eido` Documentation

```python
def validate_project(project, schema, exclude_case=False)
def validate_project(project, schema)
```

Validate a project object against a schema
#### Parameters:

- `project` (`peppy.Sample`): a project object to validate
- `schema` (`str | dict`): schema dict to validate against or a path to one
- `exclude_case` (`bool`): whether to exclude validated objectsfrom the error. Useful when used ith large projects




```python
def validate_sample(project, sample_name, schema, exclude_case=False)
def validate_sample(project, sample_name, schema)
```

Validate the selected sample object against a schema
Expand All @@ -53,23 +51,17 @@ Validate the selected sample object against a schema
- `project` (`peppy.Project`): a project object to validate
- `sample_name` (`str | int`): name or index of the sample to validate
- `schema` (`str | dict`): schema dict to validate against or a path to one
- `exclude_case` (`bool`): whether to exclude validated objectsfrom the error. Useful when used ith large projects




```python
def validate_config(project, schema, exclude_case=False)
def validate_config(project, schema)
```

Validate the config part of the Project object against a schema
#### Parameters:

- `project` (`peppy.Project`): a project object to validate
- `schema` (`str | dict`): schema dict to validate against or a path to one
- `exclude_case` (`bool`): whether to exclude validated objectsfrom the error. Useful when used ith large projects




```python
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [0.2.2] - 2023-11-16

### Changed
- remove unused `exclude-case` from CLI. Fixes #65

## [0.2.1] - 2023-07-05

### Changed
Expand Down
20 changes: 10 additions & 10 deletions docs/plugin_api_docs.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
**The PEP filters are an experimental feature and may change in feature versions of `eido`**

Final targets: basic_pep_filter, csv_pep_filter, yaml_pep_filter, yaml_samples_pep_filter
<script>
document.addEventListener('DOMContentLoaded', (event) => {
Expand All @@ -10,7 +8,7 @@ document.addEventListener('DOMContentLoaded', (event) => {
</script>

<style>
h3 .content {
h3 .content {
padding-left: 22px;
text-indent: -15px;
}
Expand All @@ -21,7 +19,7 @@ h3 .hljs .content {
martin-bottom: 0px;
}
h4 .content, table .content, p .content, li .content { margin-left: 30px; }
h4 .content {
h4 .content {
font-style: italic;
font-size: 1em;
margin-bottom: 0px;
Expand All @@ -30,11 +28,13 @@ h4 .content {
</style>


# Built-in `eido` Plugins Documentation
# Package `eido` Documentation


Project configuration

```python
def basic_pep_filter(p, **kwargs)
def basic_pep_filter(p, **kwargs) -> Dict[str, str]
```

Basic PEP filter, that does not convert the Project object.
Expand All @@ -48,7 +48,7 @@ This filter can save the PEP representation to file, if kwargs include `path`.


```python
def yaml_pep_filter(p, **kwargs)
def yaml_pep_filter(p, **kwargs) -> Dict[str, str]
```

YAML PEP filter, that returns Project object representation.
Expand All @@ -62,7 +62,7 @@ This filter can save the YAML to file, if kwargs include `path`.


```python
def csv_pep_filter(p, **kwargs)
def csv_pep_filter(p, **kwargs) -> Dict[str, str]
```

CSV PEP filter, that returns Sample object representations
Expand All @@ -77,7 +77,7 @@ This filter can save the CSVs to files, if kwargs include


```python
def yaml_samples_pep_filter(p, **kwargs)
def yaml_samples_pep_filter(p, **kwargs) -> Dict[str, str]
```

YAML samples PEP filter, that returns only Sample object representations.
Expand All @@ -93,4 +93,4 @@ This filter can save the YAML to file, if kwargs include `path`.



*Version Information: `eido` v0.1.5-dev, generated by `lucidoc` v0.4.2*
*Version Information: `eido` v0.2.2-dev, generated by `lucidoc` v0.4.4*
2 changes: 1 addition & 1 deletion eido/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.1"
__version__ = "0.2.2"
10 changes: 0 additions & 10 deletions eido/argparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,6 @@ def build_argparser():
metavar="S",
)

sps[VALIDATE_CMD].add_argument(
"-e",
"--exclude-case",
default=False,
action="store_true",
help="Whether to exclude the validation case from an error. "
"Only the human readable message explaining the error will "
"be raised. Useful when validating large PEPs.",
)

sps[INSPECT_CMD].add_argument(
"-n",
"--sample-name",
Expand Down
6 changes: 3 additions & 3 deletions eido/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,19 @@ def main():
f"against a schema: {args.schema}"
)
validator = validate_sample
arguments = [p, args.sample_name, args.schema, args.exclude_case]
arguments = [p, args.sample_name, args.schema]
elif args.just_config:
_LOGGER.debug(
f"Comparing Project ('{args.pep}') against a schema: {args.schema}"
)
validator = validate_config
arguments = [p, args.schema, args.exclude_case]
arguments = [p, args.schema]
else:
_LOGGER.debug(
f"Comparing Project ('{args.pep}') against a schema: {args.schema}"
)
validator = validate_project
arguments = [p, args.schema, args.exclude_case]
arguments = [p, args.schema]
try:
validator(*arguments)
except EidoValidationError as e:
Expand Down
4 changes: 4 additions & 0 deletions eido/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ class EidoValidationError(EidoException):
def __init__(self, message, errors_by_type):
super().__init__(message)
self.errors_by_type = errors_by_type
self.message = message

def __str__(self):
return f"EidoValidationError ({self.message}): {self.errors_by_type}"
6 changes: 5 additions & 1 deletion eido/inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def get_input_files_size(sample, schema):
all_inputs.update(required_inputs)
with catch_warnings(record=True) as w:
input_file_size = sum(
[size(f, size_str=False) or 0.0 for f in all_inputs if f != ""]
[
size(f, size_str=False) or 0.0
for f in all_inputs
if f != "" and f != None
]
) / (1024**3)
if w:
_LOGGER.warning(
Expand Down
10 changes: 5 additions & 5 deletions eido/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
_LOGGER = getLogger(__name__)


def _validate_object(object, schema, sample_name_colname=False):
def _validate_object(obj, schema, sample_name_colname=False):
"""
Generic function to validate object against a schema

:param Mapping object: an object to validate
:param Mapping obj: an object to validate
:param str | dict schema: schema dict to validate against or a path to one
from the error. Useful when used ith large projects
:raises EidoValidationError: if validation is unsuccessful
"""
validator = Draft7Validator(schema)
_LOGGER.debug(f"{object},\n {schema}")
if not validator.is_valid(object):
errors = sorted(validator.iter_errors(object), key=lambda e: e.path)
_LOGGER.debug(f"{obj},\n {schema}")
if not validator.is_valid(obj):
errors = sorted(validator.iter_errors(obj), key=lambda e: e.path)
errors_by_type = {}

# Accumulate and restructure error objects by error type
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-all.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jsonschema>=3.0.1
logmuse>=0.2.5
pandas
peppy>=0.35.5
peppy>=0.35.7
ubiquerg>=0.5.2
2 changes: 1 addition & 1 deletion webeido/webeido/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def validate_pep(request: Request, files: List[UploadFile] = File(...)):
def vwrap(p, schema):
x = None
try:
eido.validate_project(project=p, schema=schema, exclude_case=True)
eido.validate_project(project=p, schema=schema)
except Exception as e:
x = e
print(x)
Expand Down
Loading