|
3 | 3 | import logging |
4 | 4 | from pathlib import Path |
5 | 5 |
|
| 6 | +from importlib_metadata import version |
| 7 | + |
6 | 8 | from ..core.models import SomesyConfig |
7 | 9 | from .exec import gen_codemeta |
8 | 10 | from .utils import cff_codemeta_tempfile, update_codemeta_file |
9 | 11 |
|
10 | 12 | log = logging.getLogger("somesy") |
11 | 13 |
|
12 | 14 |
|
| 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 | + |
13 | 38 | def collect_cm_sources(conf: SomesyConfig): |
14 | 39 | """Assemble list of inputs for codemetapy based on somesy config. |
15 | 40 |
|
@@ -38,6 +63,7 @@ def update_codemeta(conf: SomesyConfig) -> bool: |
38 | 63 |
|
39 | 64 | Returns True if file has been written, False if it was up to date. |
40 | 65 | """ |
| 66 | + patch_codemetapy() |
41 | 67 | cm_sources = collect_cm_sources(conf) |
42 | 68 |
|
43 | 69 | # if cff file is given, convert it to codemeta tempfile and pass as extra input |
|
0 commit comments