Skip to content

Commit f731c0f

Browse files
authored
Merge pull request #46 from Materials-Data-Science-and-Informatics/pydantic2
Migration to Pydantic 2 + codemetapy update
2 parents 37662ac + b1fdabb commit f731c0f

26 files changed

Lines changed: 980 additions & 880 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,5 @@ Thumbs.db
164164

165165
# SonarQube files
166166
.sonarqube
167-
.scannerwork
167+
.scannerwork
168+
.idea

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ repos:
5050
- id: pydocstyle
5151
additional_dependencies: ['tomli==2.0.1']
5252
files: '^src/'
53-
- repo: https://github.com/econchick/interrogate
54-
rev: '1.5.0'
55-
hooks:
56-
- id: interrogate
57-
files: '^src/'
5853
- repo: https://github.com/pre-commit/mirrors-mypy
5954
rev: 'v1.1.1'
6055
hooks:

.somesy.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "somesy"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "A CLI tool for synchronizing software project metadata."
55
keywords = ["metadata", "FAIR"]
66
license = "MIT"

.sourcery.yaml

Lines changed: 0 additions & 70 deletions
This file was deleted.

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ type: software
33
message: If you use this software, please cite it using this metadata.
44

55
title: somesy
6-
version: 0.1.0
6+
version: 0.1.1
77
abstract: A CLI tool for synchronizing software project metadata.
88
repository-code: https://github.com/Materials-Data-Science-and-Informatics/somesy
99
license: MIT

codemeta.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,14 @@
6868
"identifier": "'version':",
6969
"name": "'version':",
7070
"runtimePlatform": "Python 3",
71-
"version": "'^1.9.2'}"
71+
"version": "'^0.7.0'}"
7272
},
7373
{
7474
"@type": "SoftwareApplication",
7575
"identifier": "'version':",
7676
"name": "'version':",
7777
"runtimePlatform": "Python 3",
78-
"version": "'^0.7.0'}"
78+
"version": "'^2.4.2'}"
7979
},
8080
{
8181
"@type": "SoftwareApplication",
@@ -89,7 +89,7 @@
8989
"identifier": "codemetapy",
9090
"name": "codemetapy",
9191
"runtimePlatform": "Python 3",
92-
"version": "^2.5.0"
92+
"version": "^2.5.1"
9393
},
9494
{
9595
"@type": "SoftwareApplication",
@@ -170,5 +170,5 @@
170170
"runtimePlatform": "Python 3"
171171
},
172172
"url": "https://materials-data-science-and-informatics.github.io/somesy",
173-
"version": "0.1.0"
173+
"version": "0.1.1"
174174
}

docs/manual.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,21 @@ Here is an overview of the schemas used in somesy.
6666
import json
6767
from io import StringIO
6868
from somesy.core.models import SomesyInput, ProjectMetadata, Person, SomesyConfig
69+
from pydantic_core import PydanticUndefined
70+
from typing_extensions import get_args
71+
72+
def pp_type(th):
73+
# NOTE: this does not work correctly with non-trivial unions!
74+
while args := get_args(th):
75+
th = args[0]
76+
return th.__name__
6977

7078
def fmt_desc(desc, pref=""):
7179
if not desc:
7280
return ""
7381
return "\n".join(map(lambda x: pref + x.strip(), desc.split("\n")))
7482

83+
7584
def model2md(m, out = None):
7685
out = out or StringIO()
7786

@@ -80,20 +89,15 @@ def model2md(m, out = None):
8089
out.write("\t\n\n")
8190
out.write("\t| Field | Type | Required? | Default | Description |\n")
8291
out.write("\t| ----- | ---- | --------- | ------- | ----------- |\n")
83-
for fld in m.__fields__.values():
84-
n = fld.name
85-
86-
t = fld.type_.__name__
87-
if t == "ConstrainedStrValue":
88-
t = "str"
89-
if t == "AnyUrl":
90-
t = "URL"
91-
if fld.field_info.min_items:
92-
t = f"list[{t}]"
93-
94-
r = "**yes**" if fld.required else "no"
95-
v = json.dumps(fld.default, default=str) if fld.default is not None else ""
96-
d = fmt_desc(fld.field_info.description)
92+
for n, fld in m.model_fields.items():
93+
t = pp_type(fld.annotation)
94+
r = "**yes**" if fld.is_required() else "no"
95+
dv = fld.default
96+
if dv is not None and dv != PydanticUndefined:
97+
v = json.dumps(fld.default, default=str)
98+
else:
99+
v = ""
100+
d = fmt_desc(fld.description)
97101
out.write(f"\t| {n} | {t} | {r} | {v} | {d} |\n")
98102
out.write("\n")
99103

0 commit comments

Comments
 (0)