Skip to content

Commit

Permalink
add validation for code metadata (#78)
Browse files Browse the repository at this point in the history
And prepare way for transition to YAML format for code metadata.
  • Loading branch information
ltalirz committed Aug 23, 2021
1 parent ad408ff commit d26f07a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 2 deletions.
64 changes: 64 additions & 0 deletions .github/codes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
"""Schema and validation of simulation code metadata."""
from dataclasses import dataclass
from enum import Enum
from typing import Dict, Optional, List
from pathlib import Path
from serde import serialize, deserialize, json, yaml

DATA_DIR = Path(__file__).parent.parent / 'src' / 'data'

class QueryMethods(str, Enum):
"""Methods for querying Google Scholar."""
SEARCH = 'search term'
PUBLICATION = 'publication'


@deserialize
@serialize
@dataclass
class Code: # pylint: disable=too-many-instance-attributes
"""Class representing a code.
Optional fields are no longer used by the web application.
Fields with default values are used by the web application.
"""
name: str
benchmarks: List[str]
homepage: str
author_name: Optional[str]
query_method: str
query_string: str
types: List[str]
license: str
tags: List
nomad_tags: list = None
query_publication_id: int = None
notes: str = None
license_annotation: str = None

def read_codes_json(path: Path = DATA_DIR / 'codes.json') -> Dict[str, Code]:
"""Read codes.json file and return dictionary."""

with open(path) as handle:
return json.from_json(Dict[str, Code], handle.read())

def write_codes_yaml(path: Path = DATA_DIR / 'codes.yaml', codes: Dict[str, Code] = read_codes_json()) -> None:
"""Write codes.yaml file.
May use if switch to yaml format is made.
"""

with open(path, 'w') as handle:
handle.write(yaml.to_yaml(codes))

def read_codes_yaml(path: Path = DATA_DIR / 'codes.yaml') -> Dict[str, Code]:
"""Read codes.yaml file and return dictionary.
May use if switch to yaml format is made.
"""

with open(path) as handle:
return yaml.from_yaml(Dict[str, Code], handle.read())

print(read_codes_json())
1 change: 1 addition & 0 deletions .github/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyserde[yaml]~=0.4.0
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ jobs:
run: npm install --include=dev
- name: Run ESLint
run: npx eslint 'src/**/*js'

validate-codes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: pip install -r .github/requirements.txt
- name: Validate code metadata
run: python .github/codes.py
4 changes: 2 additions & 2 deletions src/text/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

Practitioners and software developers in the field of atomistic simulations may find it useful for:

* getting an overview of major simulation engines with specific features, licensing conditions, ...
* getting an [overview of major simulation engines](#/table) with specific features, licensing conditions, ...
* monitoring how the use of individual simulation engines has evolved over time
* analyzing trends at the ecosystem level (licensing, ...)
* analyzing [trends at the ecosystem level](#/statistics) (licensing, ...)

Citation data are updated annually, while [corrections and additions](${this.packageJson.repository.url}#adding-a-simulation-engine) are welcome throughout the year.

Expand Down

0 comments on commit d26f07a

Please sign in to comment.