Skip to content

Commit badccf9

Browse files
authored
Merge pull request #37 from Materials-Data-Science-and-Informatics/monkeypatch_codemeta
fix: monkeypatch codemetapy 2.5.0 to fix poetry pyproject parsing
2 parents 2b50cd9 + d4f4688 commit badccf9

6 files changed

Lines changed: 75 additions & 55 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ Here is an overview of all the currently supported files and formats.
143143

144144
| Input Formats | Status | | Target Formats | Status |
145145
| -------------- | ------ |-| ----------------------------- | ------ |
146-
| (.)somesy.toml | ✓ | | pyproject.toml _(poetry)_ | ✓ |
147-
| pyproject.toml | ✓(1.) | | pyproject.toml _(setuptools)_ | ✓(2.) |
148-
| package.json | TBD | | package.json | TBD |
146+
| (.)somesy.toml | ✓ | | pyproject.toml _(poetry)_ | ✓ |
147+
| pyproject.toml | ✓(1.) | | pyproject.toml _(setuptools)_ | ✓(2.) |
148+
| package.json | | | package.json | |
149149
| | | | mkdocs.yml | TBD |
150150
| | | | CITATION.cff | ✓ |
151151
| | | | codemeta.json | ✓(3.) |

codemeta.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
"identifier": "'version':",
5050
"name": "'version':",
5151
"runtimePlatform": "Python 3",
52-
"version": "'^1.9.2'}"
52+
"version": "'^0.7.0'}"
5353
},
5454
{
5555
"@type": "SoftwareApplication",
5656
"identifier": "'version':",
5757
"name": "'version':",
5858
"runtimePlatform": "Python 3",
59-
"version": "'^0.7.0'}"
59+
"version": "'^1.9.2'}"
6060
},
6161
{
6262
"@type": "SoftwareApplication",
@@ -70,7 +70,7 @@
7070
"identifier": "codemetapy",
7171
"name": "codemetapy",
7272
"runtimePlatform": "Python 3",
73-
"version": "{'git': 'https://github.com/proycon/codemetapy.git'}"
73+
"version": "^2.5.0"
7474
},
7575
{
7676
"@type": "SoftwareApplication",

docs/manual.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,4 @@ everybody's life easier. Furthermore, nobody needs to care whether, under the
305305
hood, you use `somesy` (or anything like it) or not - they can use the
306306
corresponding files they already know to get the information they need.
307307
So there is no "risk" involved in adopting `somesy`, because it does not try to
308-
abolish any other formats or standards or becoming such.
308+
abolish any other formats or standards or becoming such.

poetry.lock

Lines changed: 41 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ cffconvert = "^2.0.0"
4444
wrapt = "^1.15.0"
4545
packaging = "^23.1"
4646
rdflib = "^6.3.2"
47-
codemetapy = { git = "https://github.com/proycon/codemetapy.git" }
48-
# codemetapy = "^2.5.1" # TODO: use once released
47+
codemetapy = "^2.5.0"
4948

5049
[tool.poetry.group.dev.dependencies]
5150
poethepoet = "^0.18.1"

src/somesy/codemeta/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,38 @@
33
import logging
44
from pathlib import Path
55

6+
from importlib_metadata import version
7+
68
from ..core.models import SomesyConfig
79
from .exec import gen_codemeta
810
from .utils import cff_codemeta_tempfile, update_codemeta_file
911

1012
log = logging.getLogger("somesy")
1113

1214

15+
def patch_codemetapy():
16+
"""Monkey-patch codemetapy (2.5.0 -> 2.5.1)."""
17+
# TODO: remove once codemeta update is published)
18+
if version("codemetapy") != "2.5.0":
19+
return
20+
from codemeta.parsers import python as cmpy
21+
22+
# https://github.com/proycon/codemetapy/blob/88098dc638e4cdfed9de6ad98002e16dfeede952/codemeta/parsers/python.py
23+
def fixed_metadata_from_pyproject(pyproject):
24+
"""Parse metadata from pyproject.toml."""
25+
if pyproject.project and "name" in pyproject.project:
26+
return pyproject.project
27+
elif "poetry" in pyproject.tool:
28+
return pyproject.tool["poetry"]
29+
elif pyproject.tool and "name" in list(pyproject.tool.values())[0]:
30+
# fallback: no poetry but another tool that defines at least a name
31+
return list(pyproject.tool.values())[0]
32+
return None
33+
34+
cmpy.metadata_from_pyproject = fixed_metadata_from_pyproject
35+
log.debug("monkeypatch codemetapy 2.5.0 -> 2.5.1")
36+
37+
1338
def collect_cm_sources(conf: SomesyConfig):
1439
"""Assemble list of inputs for codemetapy based on somesy config.
1540
@@ -38,6 +63,7 @@ def update_codemeta(conf: SomesyConfig) -> bool:
3863
3964
Returns True if file has been written, False if it was up to date.
4065
"""
66+
patch_codemetapy()
4167
cm_sources = collect_cm_sources(conf)
4268

4369
# if cff file is given, convert it to codemeta tempfile and pass as extra input

0 commit comments

Comments
 (0)