|
1 | 1 | """Integration with codemetapy (to re-generate codemeta as part of somesy sync).""" |
2 | | -import contextlib |
3 | | -import logging |
4 | | -from pathlib import Path |
| 2 | +from .create import Codemeta |
5 | 3 |
|
6 | | -from ..core.models import SomesyConfig |
7 | | -from .exec import gen_codemeta |
8 | | -from .utils import cff_codemeta_tempfile, update_codemeta_file |
9 | | - |
10 | | -log = logging.getLogger("somesy") |
11 | | - |
12 | | - |
13 | | -def collect_cm_sources(conf: SomesyConfig): |
14 | | - """Assemble list of inputs for codemetapy based on somesy config. |
15 | | -
|
16 | | - Returns files that are supported by both somesy and codemetapy and are enabled for somesy. |
17 | | - """ |
18 | | - cm_sources = [] |
19 | | - if ( |
20 | | - not conf.no_sync_pyproject |
21 | | - and conf.pyproject_file is not None |
22 | | - and conf.pyproject_file.is_file() |
23 | | - ): |
24 | | - cm_sources.append(conf.pyproject_file) |
25 | | - # NOTE: we don't add CFF directly, because it must be handled separately |
26 | | - # NOTE: add other suitable somesy targets / codemeta sources (except CFF and codemeta) here |
27 | | - if ( |
28 | | - conf.no_sync_package_json |
29 | | - and conf.package_json_file is not None |
30 | | - and conf.package_json_file.is_file() |
31 | | - ): |
32 | | - cm_sources.append(conf.package_json_file) |
33 | | - return cm_sources |
34 | | - |
35 | | - |
36 | | -def update_codemeta(conf: SomesyConfig): |
37 | | - """Generate or update codemeta file based on sources that somesy supports. |
38 | | -
|
39 | | - Returns True if file has been written, False if it was up to date. |
40 | | - """ |
41 | | - cm_sources = collect_cm_sources(conf) |
42 | | - |
43 | | - # if cff file is given, convert it to codemeta tempfile and pass as extra input |
44 | | - temp_cff_cm = contextlib.nullcontext(None) |
45 | | - if not conf.no_sync_cff and conf.cff_file is not None: |
46 | | - temp_cff_cm = cff_codemeta_tempfile(conf.cff_file) |
47 | | - cm_sources.append(Path(temp_cff_cm.name)) |
48 | | - |
49 | | - # run codemetapy |
50 | | - with temp_cff_cm: |
51 | | - cm_harvest = gen_codemeta(cm_sources) |
52 | | - |
53 | | - # NOTE: once codemetapy is fixed (still broken with 2.5.1), we should not need |
54 | | - # update_codemeta_file + codemeta context dump + most of utils.py + their tests anymore |
55 | | - # we'll first disable the workaround and see for a while if everything works |
56 | | - # as expected, and if it does, the cleanup can be completed. |
57 | | - # |
58 | | - # save to file with same settings as used by codemetapy |
59 | | - # with open(conf.codemeta_file, "w") as f: |
60 | | - # f.write(json.dumps(cm_harvest, indent=4, ensure_ascii=False, sort_keys=True)) |
61 | | - |
62 | | - # check output and write file if needed (with workaround checking graph equivalence) |
63 | | - return update_codemeta_file(conf.codemeta_file, cm_harvest) |
64 | | - |
65 | | - |
66 | | -__all__ = ["update_codemeta"] |
| 4 | +__all__ = ["Codemeta"] |
0 commit comments