citesync 0.3.0__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. {citesync-0.3.0 → citesync-0.5.0}/PKG-INFO +13 -11
  2. {citesync-0.3.0 → citesync-0.5.0}/README.md +11 -8
  3. {citesync-0.3.0 → citesync-0.5.0}/pyproject.toml +5 -5
  4. {citesync-0.3.0 → citesync-0.5.0}/pyproject.toml.orig +5 -5
  5. citesync-0.5.0/src/citesync/MAPPING_SOURCE +7 -0
  6. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/__main__.py +2 -4
  7. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/check.py +26 -6
  8. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/cli.py +122 -34
  9. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/codecs.py +14 -2
  10. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/config.py +32 -14
  11. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/core_metadata.py +63 -37
  12. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/errors.py +11 -1
  13. citesync-0.5.0/src/citesync/export.py +539 -0
  14. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/formats.py +219 -31
  15. citesync-0.5.0/src/citesync/mapping-4.0.json +5363 -0
  16. citesync-0.5.0/src/citesync/mapping-local.json +5085 -0
  17. citesync-0.5.0/src/citesync/mapping-vectors.json +1358 -0
  18. citesync-0.5.0/src/citesync/mapping.py +202 -0
  19. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/mapping.schema.json +10 -4
  20. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/playground.py +8 -7
  21. citesync-0.5.0/src/citesync/playground_exports.py +258 -0
  22. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/positions.py +12 -3
  23. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/research_metadata.py +63 -75
  24. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/rules.py +36 -3
  25. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/write.py +126 -46
  26. citesync-0.3.0/src/citesync/MAPPING_SOURCE +0 -5
  27. citesync-0.3.0/src/citesync/mapping-local.json +0 -728
  28. citesync-0.3.0/src/citesync/mapping.py +0 -142
  29. citesync-0.3.0/src/citesync/playground_exports.py +0 -153
  30. {citesync-0.3.0 → citesync-0.5.0}/LICENSE +0 -0
  31. {citesync-0.3.0 → citesync-0.5.0}/NOTICE +0 -0
  32. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/__init__.py +0 -0
  33. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/jsonsplice.py +0 -0
  34. {citesync-0.3.0 → citesync-0.5.0}/src/citesync/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: citesync
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Summary: Generate and synchronize software citation files from package metadata. CLI, pre-commit hook and browser playground.
5
5
  Keywords: citation,CITATION.cff,codemeta,zenodo,software-metadata,pre-commit
6
6
  Author: Simon van Lierde
@@ -13,7 +13,6 @@ Classifier: Environment :: Console
13
13
  Classifier: Intended Audience :: Developers
14
14
  Classifier: Intended Audience :: Science/Research
15
15
  Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
18
17
  Classifier: Programming Language :: Python :: 3.14
19
18
  Classifier: Topic :: Software Development :: Quality Assurance
@@ -21,7 +20,7 @@ Classifier: Typing :: Typed
21
20
  Requires-Dist: packaging>=26.3
22
21
  Requires-Dist: ruamel-yaml>=0.19
23
22
  Requires-Dist: tomlkit>=0.15.2
24
- Requires-Python: >=3.12
23
+ Requires-Python: >=3.13
25
24
  Project-URL: Homepage, https://simonvanlierde.com/citesync/
26
25
  Project-URL: Source, https://github.com/simonvanlierde/citesync
27
26
  Project-URL: Issues, https://github.com/simonvanlierde/citesync/issues
@@ -34,6 +33,7 @@ Description-Content-Type: text/markdown
34
33
  [![PyPI](https://img.shields.io/pypi/v/citesync)](https://pypi.org/project/citesync/)
35
34
  [![Python versions](https://img.shields.io/pypi/pyversions/citesync)](https://pypi.org/project/citesync/)
36
35
  [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/simonvanlierde/citesync/badge)](https://scorecard.dev/viewer/?uri=github.com/simonvanlierde/citesync)
36
+ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/16151/badge)](https://www.bestpractices.dev/projects/16151)
37
37
  [![license](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/simonvanlierde/citesync/blob/main/LICENSE)
38
38
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23779706.svg)](https://doi.org/10.5281/zenodo.23779706)
39
39
 
@@ -41,19 +41,20 @@ Status: experimental. It may change in ways that break your code, without notice
41
41
 
42
42
  Questions and bugs: see [CONTRIBUTING.md](https://github.com/simonvanlierde/citesync/blob/main/.github/CONTRIBUTING.md).
43
43
 
44
- Generate software citation files from package metadata, then keep them in sync across CITATION.cff, codemeta.json, .zenodo.json and package manifests. Use the CLI, a pre-commit hook or the [browser playground](https://simonvanlierde.com/citesync/). Field mappings come from CodeMeta's crosswalks, as exported by [codemeta-drift](https://github.com/simonvanlierde/codemeta-drift).
44
+ Generate software citation files from package metadata, then keep them in sync across CITATION.cff, codemeta.json, .zenodo.json and package manifests, including [Typst and Quarto plugin manifests](docs/formats.md#plugin-manifests). Use the CLI, a pre-commit hook or the [browser playground](https://simonvanlierde.com/citesync/). Field mappings come from CodeMeta's crosswalks, as exported by [codemeta-drift](https://github.com/simonvanlierde/codemeta-drift).
45
45
 
46
46
  ## Usage
47
47
 
48
- citesync compares eleven fields, from title to release date, with one file: the source. The source is CITATION.cff unless you pick another with `--source`. With neither, citesync exits 2. Use citesync through its command line and the pre-commit hook. Its Python modules are internal and may change in any release.
48
+ citesync compares eleven fields, from title to release date, with one file: the source. The source is CITATION.cff unless you pick another with `--source`. With neither, citesync exits 3. Use citesync through its command line and the pre-commit hook. Its Python modules are internal and may change in any release.
49
49
 
50
50
  ```sh
51
51
  uv tool install citesync # or run it once with uvx citesync check
52
- citesync check # exit 0: no error finding; 1: an error finding; 2: citesync couldn't run
52
+ citesync check # exit 0: no error finding; 1: an error finding; 2: usage error; 3: couldn't run
53
53
  citesync check --source pyproject.toml
54
54
  citesync write --diff # print what write would change, and change nothing
55
55
  citesync write # rewrite the other files to agree with the source
56
56
  citesync init # write a CITATION.cff from codemeta.json, .zenodo.json and the manifests
57
+ citesync export --format apa # print a citation: apa, bibtex, csl-json, jsonld, datacite, ris, endnote, cff, codemeta or zenodo
57
58
  citesync explain version-mismatch # what a rule checks and how to fix it
58
59
  citesync config # the config in use, and the file it came from
59
60
  ```
@@ -71,11 +72,12 @@ A config is optional. A one-line `citesync.toml` is `ignore = ["description-mism
71
72
 
72
73
  - [How check works](https://github.com/simonvanlierde/citesync/blob/main/docs/check.md): the fields, files, options and exit codes.
73
74
  - [How write works](https://github.com/simonvanlierde/citesync/blob/main/docs/write.md): what it changes and what it leaves alone.
74
- - [Supported files](https://github.com/simonvanlierde/citesync/blob/main/docs/formats.md): which files citesync reads, updates and creates, including read-only Python distribution, R and Julia metadata.
75
+ - [Supported files](https://github.com/simonvanlierde/citesync/blob/main/docs/formats.md): which files citesync reads, updates and creates, including read-only Python distribution, R and Julia metadata, and the RO-Crate and Croissant files sourceledger makes.
75
76
  - [How init works](https://github.com/simonvanlierde/citesync/blob/main/docs/init.md): where a new CITATION.cff takes each field from.
77
+ - [Citation exports](https://github.com/simonvanlierde/citesync/blob/main/docs/export.md): BibTeX, CSL-JSON, APA, schema.org JSON-LD, DataCite XML, RIS and EndNote files kept in step with the source.
76
78
  - [Rules](https://github.com/simonvanlierde/citesync/blob/main/docs/rules.md): each rule id, what it checks and how to fix it.
77
79
  - [Configuration](https://github.com/simonvanlierde/citesync/blob/main/docs/config.md): where config goes, and every key.
78
- - [Use citation exports with Pandoc](https://github.com/simonvanlierde/citesync/blob/main/docs/pandoc.md): cite software from the playground’s CSL-JSON or BibTeX files.
80
+ - [Use citation exports with Pandoc](https://github.com/simonvanlierde/citesync/blob/main/docs/pandoc.md): cite software from the CSL-JSON or BibTeX files `citesync export` or the playground makes.
79
81
  - [Output formats](https://github.com/simonvanlierde/citesync/blob/main/docs/output.md): JSON, GitHub annotations and SARIF.
80
82
  - [Tested on real repositories](https://github.com/simonvanlierde/citesync/blob/main/docs/tested-repositories.md): what citesync reports on five public repositories.
81
83
 
@@ -90,13 +92,13 @@ For [prek](https://prek.j178.dev) or [pre-commit](https://pre-commit.com), in `.
90
92
  ```yaml
91
93
  repos:
92
94
  - repo: https://github.com/simonvanlierde/citesync
93
- rev: v0.3.0
95
+ rev: v0.5.0
94
96
  hooks:
95
97
  - id: citesync
96
98
  - id: citesync-write
97
99
  ```
98
100
 
99
- The `citesync` hook runs when a commit changes a supported metadata file or a citesync config, at any depth. It checks every file, not only the staged ones, and fails the commit on an error finding. The `citesync-write` hook runs only when you ask for it: `prek run citesync-write --stage manual --all-files`.
101
+ The `citesync` hook runs when a commit changes a supported metadata file, a citesync config or a file with an export suffix (`.bib`, `.csl.json`, `.apa.txt`, `.jsonld`, `.datacite.xml`, `.ris`, `.enw`), at any depth. It checks every file, not only the staged ones, and fails the commit on an error finding (exit 1) or when citesync can't run (exit 3), such as on a bad config. The [exit codes](https://github.com/simonvanlierde/citesync/blob/main/docs/check.md#findings-and-exit-codes) are the same as on the command line. The `citesync-write` hook runs only when you ask for it: `prek run citesync-write --stage manual --all-files`. Both hooks need Python 3.13 or newer.
100
102
 
101
103
  ## Development
102
104
 
@@ -117,7 +119,7 @@ just fmt # apply each stack's fixes and formatting
117
119
  just hooks # the git hooks, as the checks workflow runs them
118
120
  ```
119
121
 
120
- `just mutation` mutation-tests the modules `only_mutate` lists under `[tool.mutmut]` in `pyproject.toml`. CI doesn't run it. It fails when the tests miss a change that `tests/mutation-baseline.txt` doesn't list. A change that can't alter behaviour goes in that file, with the reason. It also fails when the tests now catch a listed change, so drop that line.
122
+ `just mutation` mutation-tests the modules `only_mutate` lists under `[tool.mutmut]` in `pyproject.toml`. CI runs it weekly, on Mondays ([`mutation.yml`](.github/workflows/mutation.yml)). It fails when the tests miss a change that `tests/mutation-baseline.txt` doesn't list. A change that can't alter behaviour goes in that file, with the reason. It also fails when the tests now catch a listed change, so drop that line.
121
123
 
122
124
  uv locks only releases at least a week old. If `just check` fails on a newer security fix, add the package to `exclude-newer-package` under `[tool.uv]` in `pyproject.toml`, and remove it a week later ([how](https://github.com/simonvanlierde/project-templates/blob/main/docs/tooling.md#dependencies)).
123
125
 
@@ -4,6 +4,7 @@
4
4
  [![PyPI](https://img.shields.io/pypi/v/citesync)](https://pypi.org/project/citesync/)
5
5
  [![Python versions](https://img.shields.io/pypi/pyversions/citesync)](https://pypi.org/project/citesync/)
6
6
  [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/simonvanlierde/citesync/badge)](https://scorecard.dev/viewer/?uri=github.com/simonvanlierde/citesync)
7
+ [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/16151/badge)](https://www.bestpractices.dev/projects/16151)
7
8
  [![license](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/simonvanlierde/citesync/blob/main/LICENSE)
8
9
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.23779706.svg)](https://doi.org/10.5281/zenodo.23779706)
9
10
 
@@ -11,19 +12,20 @@ Status: experimental. It may change in ways that break your code, without notice
11
12
 
12
13
  Questions and bugs: see [CONTRIBUTING.md](https://github.com/simonvanlierde/citesync/blob/main/.github/CONTRIBUTING.md).
13
14
 
14
- Generate software citation files from package metadata, then keep them in sync across CITATION.cff, codemeta.json, .zenodo.json and package manifests. Use the CLI, a pre-commit hook or the [browser playground](https://simonvanlierde.com/citesync/). Field mappings come from CodeMeta's crosswalks, as exported by [codemeta-drift](https://github.com/simonvanlierde/codemeta-drift).
15
+ Generate software citation files from package metadata, then keep them in sync across CITATION.cff, codemeta.json, .zenodo.json and package manifests, including [Typst and Quarto plugin manifests](docs/formats.md#plugin-manifests). Use the CLI, a pre-commit hook or the [browser playground](https://simonvanlierde.com/citesync/). Field mappings come from CodeMeta's crosswalks, as exported by [codemeta-drift](https://github.com/simonvanlierde/codemeta-drift).
15
16
 
16
17
  ## Usage
17
18
 
18
- citesync compares eleven fields, from title to release date, with one file: the source. The source is CITATION.cff unless you pick another with `--source`. With neither, citesync exits 2. Use citesync through its command line and the pre-commit hook. Its Python modules are internal and may change in any release.
19
+ citesync compares eleven fields, from title to release date, with one file: the source. The source is CITATION.cff unless you pick another with `--source`. With neither, citesync exits 3. Use citesync through its command line and the pre-commit hook. Its Python modules are internal and may change in any release.
19
20
 
20
21
  ```sh
21
22
  uv tool install citesync # or run it once with uvx citesync check
22
- citesync check # exit 0: no error finding; 1: an error finding; 2: citesync couldn't run
23
+ citesync check # exit 0: no error finding; 1: an error finding; 2: usage error; 3: couldn't run
23
24
  citesync check --source pyproject.toml
24
25
  citesync write --diff # print what write would change, and change nothing
25
26
  citesync write # rewrite the other files to agree with the source
26
27
  citesync init # write a CITATION.cff from codemeta.json, .zenodo.json and the manifests
28
+ citesync export --format apa # print a citation: apa, bibtex, csl-json, jsonld, datacite, ris, endnote, cff, codemeta or zenodo
27
29
  citesync explain version-mismatch # what a rule checks and how to fix it
28
30
  citesync config # the config in use, and the file it came from
29
31
  ```
@@ -41,11 +43,12 @@ A config is optional. A one-line `citesync.toml` is `ignore = ["description-mism
41
43
 
42
44
  - [How check works](https://github.com/simonvanlierde/citesync/blob/main/docs/check.md): the fields, files, options and exit codes.
43
45
  - [How write works](https://github.com/simonvanlierde/citesync/blob/main/docs/write.md): what it changes and what it leaves alone.
44
- - [Supported files](https://github.com/simonvanlierde/citesync/blob/main/docs/formats.md): which files citesync reads, updates and creates, including read-only Python distribution, R and Julia metadata.
46
+ - [Supported files](https://github.com/simonvanlierde/citesync/blob/main/docs/formats.md): which files citesync reads, updates and creates, including read-only Python distribution, R and Julia metadata, and the RO-Crate and Croissant files sourceledger makes.
45
47
  - [How init works](https://github.com/simonvanlierde/citesync/blob/main/docs/init.md): where a new CITATION.cff takes each field from.
48
+ - [Citation exports](https://github.com/simonvanlierde/citesync/blob/main/docs/export.md): BibTeX, CSL-JSON, APA, schema.org JSON-LD, DataCite XML, RIS and EndNote files kept in step with the source.
46
49
  - [Rules](https://github.com/simonvanlierde/citesync/blob/main/docs/rules.md): each rule id, what it checks and how to fix it.
47
50
  - [Configuration](https://github.com/simonvanlierde/citesync/blob/main/docs/config.md): where config goes, and every key.
48
- - [Use citation exports with Pandoc](https://github.com/simonvanlierde/citesync/blob/main/docs/pandoc.md): cite software from the playground’s CSL-JSON or BibTeX files.
51
+ - [Use citation exports with Pandoc](https://github.com/simonvanlierde/citesync/blob/main/docs/pandoc.md): cite software from the CSL-JSON or BibTeX files `citesync export` or the playground makes.
49
52
  - [Output formats](https://github.com/simonvanlierde/citesync/blob/main/docs/output.md): JSON, GitHub annotations and SARIF.
50
53
  - [Tested on real repositories](https://github.com/simonvanlierde/citesync/blob/main/docs/tested-repositories.md): what citesync reports on five public repositories.
51
54
 
@@ -60,13 +63,13 @@ For [prek](https://prek.j178.dev) or [pre-commit](https://pre-commit.com), in `.
60
63
  ```yaml
61
64
  repos:
62
65
  - repo: https://github.com/simonvanlierde/citesync
63
- rev: v0.3.0
66
+ rev: v0.5.0
64
67
  hooks:
65
68
  - id: citesync
66
69
  - id: citesync-write
67
70
  ```
68
71
 
69
- The `citesync` hook runs when a commit changes a supported metadata file or a citesync config, at any depth. It checks every file, not only the staged ones, and fails the commit on an error finding. The `citesync-write` hook runs only when you ask for it: `prek run citesync-write --stage manual --all-files`.
72
+ The `citesync` hook runs when a commit changes a supported metadata file, a citesync config or a file with an export suffix (`.bib`, `.csl.json`, `.apa.txt`, `.jsonld`, `.datacite.xml`, `.ris`, `.enw`), at any depth. It checks every file, not only the staged ones, and fails the commit on an error finding (exit 1) or when citesync can't run (exit 3), such as on a bad config. The [exit codes](https://github.com/simonvanlierde/citesync/blob/main/docs/check.md#findings-and-exit-codes) are the same as on the command line. The `citesync-write` hook runs only when you ask for it: `prek run citesync-write --stage manual --all-files`. Both hooks need Python 3.13 or newer.
70
73
 
71
74
  ## Development
72
75
 
@@ -87,7 +90,7 @@ just fmt # apply each stack's fixes and formatting
87
90
  just hooks # the git hooks, as the checks workflow runs them
88
91
  ```
89
92
 
90
- `just mutation` mutation-tests the modules `only_mutate` lists under `[tool.mutmut]` in `pyproject.toml`. CI doesn't run it. It fails when the tests miss a change that `tests/mutation-baseline.txt` doesn't list. A change that can't alter behaviour goes in that file, with the reason. It also fails when the tests now catch a listed change, so drop that line.
93
+ `just mutation` mutation-tests the modules `only_mutate` lists under `[tool.mutmut]` in `pyproject.toml`. CI runs it weekly, on Mondays ([`mutation.yml`](.github/workflows/mutation.yml)). It fails when the tests miss a change that `tests/mutation-baseline.txt` doesn't list. A change that can't alter behaviour goes in that file, with the reason. It also fails when the tests now catch a listed change, so drop that line.
91
94
 
92
95
  uv locks only releases at least a week old. If `just check` fails on a newer security fix, add the package to `exclude-newer-package` under `[tool.uv]` in `pyproject.toml`, and remove it a week later ([how](https://github.com/simonvanlierde/project-templates/blob/main/docs/tooling.md#dependencies)).
93
96
 
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "citesync"
3
- version = "0.3.0"
3
+ version = "0.5.0"
4
4
  description = "Generate and synchronize software citation files from package metadata. CLI, pre-commit hook and browser playground."
5
5
  readme = "README.md"
6
- requires-python = ">=3.12"
6
+ requires-python = ">=3.13"
7
7
  license = "Apache-2.0"
8
8
  license-files = [
9
9
  "LICENSE",
@@ -23,7 +23,6 @@ classifiers = [
23
23
  "Intended Audience :: Developers",
24
24
  "Intended Audience :: Science/Research",
25
25
  "Programming Language :: Python :: 3",
26
- "Programming Language :: Python :: 3.12",
27
26
  "Programming Language :: Python :: 3.13",
28
27
  "Programming Language :: Python :: 3.14",
29
28
  "Topic :: Software Development :: Quality Assurance",
@@ -40,7 +39,7 @@ name = "Simon van Lierde"
40
39
  email = "code@duinlab.nl"
41
40
 
42
41
  [project.scripts]
43
- citesync = "citesync.cli:main"
42
+ citesync = "citesync.cli:entry"
44
43
 
45
44
  [project.urls]
46
45
  Homepage = "https://simonvanlierde.com/citesync/"
@@ -53,13 +52,14 @@ dev = [
53
52
  "hypothesis>=6.140",
54
53
  "jsonschema>=4.25",
55
54
  "memray>=1.20.0 ; sys_platform != 'win32'",
56
- "mutmut==3.8.0",
55
+ "mutmut==3.8.1",
57
56
  "pybtex>=0.25",
58
57
  "pyinstrument>=5.1.3",
59
58
  "pytest>=9.1.1",
60
59
  "pytest-cov>=7.1.0",
61
60
  "ruff>=0.17.1",
62
61
  "ty>=0.0.89",
62
+ "xmlschema>=4.3.2",
63
63
  ]
64
64
 
65
65
  [build-system]
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "citesync"
3
- version = "0.3.0"
3
+ version = "0.5.0"
4
4
  description = "Generate and synchronize software citation files from package metadata. CLI, pre-commit hook and browser playground."
5
5
  readme = "README.md"
6
- requires-python = ">=3.12"
6
+ requires-python = ">=3.13"
7
7
  authors = [{ name = "Simon van Lierde", email = "code@duinlab.nl" }]
8
8
  license = "Apache-2.0"
9
9
  license-files = ["LICENSE", "NOTICE"]
@@ -14,7 +14,6 @@ classifiers = [
14
14
  "Intended Audience :: Developers",
15
15
  "Intended Audience :: Science/Research",
16
16
  "Programming Language :: Python :: 3",
17
- "Programming Language :: Python :: 3.12",
18
17
  "Programming Language :: Python :: 3.13",
19
18
  "Programming Language :: Python :: 3.14",
20
19
  "Topic :: Software Development :: Quality Assurance",
@@ -27,7 +26,7 @@ dependencies = [
27
26
  ]
28
27
 
29
28
  [project.scripts]
30
- citesync = "citesync.cli:main"
29
+ citesync = "citesync.cli:entry"
31
30
 
32
31
  [project.urls]
33
32
  Homepage = "https://simonvanlierde.com/citesync/"
@@ -40,13 +39,14 @@ dev = [
40
39
  "hypothesis>=6.140",
41
40
  "jsonschema>=4.25",
42
41
  "memray>=1.20.0 ; sys_platform != 'win32'",
43
- "mutmut==3.8.0",
42
+ "mutmut==3.8.1",
44
43
  "pybtex>=0.25",
45
44
  "pyinstrument>=5.1.3",
46
45
  "pytest>=9.1.1",
47
46
  "pytest-cov>=7.1.0",
48
47
  "ruff>=0.17.1",
49
48
  "ty>=0.0.89",
49
+ "xmlschema>=4.3.2",
50
50
  ]
51
51
 
52
52
  [build-system]
@@ -0,0 +1,7 @@
1
+ # Vendored from simonvanlierde/codemeta-drift; tests/test_mapping.py checks the sha256 lines.
2
+ tag v0.8.0
3
+ commit 4b68ef7a9038992a918d806829c6dfbc45eac481
4
+ sha256 443f5c075e54416086cbb97f4680cb88900b671a435d9feb4e85d09c69c17cad mapping-local.json examples/mapping-3.1.json
5
+ sha256 99a26aa91a026cdd4fc0ac0631ec38749e6b3a96d5176bb115b2e22bb2298bc5 mapping-4.0.json examples/mapping-4.0.json
6
+ sha256 8c3dc9f4ce49e50b9fe3c6fbd4ba6082ca100439974b3f531485740218b2aa7b mapping.schema.json src/codemeta_drift/mapping.schema.json
7
+ sha256 a761fda190f4ddc4e981a30c87780a77f4f7416949da68e41cbf55350705eb1a mapping-vectors.json src/codemeta_drift/mapping-vectors.json
@@ -1,7 +1,5 @@
1
1
  """``python -m citesync``, the same as the ``citesync`` command."""
2
2
 
3
- import sys
3
+ from citesync.cli import entry
4
4
 
5
- from citesync.cli import main
6
-
7
- sys.exit(main())
5
+ entry()
@@ -7,8 +7,19 @@ from pathlib import Path
7
7
  from citesync import codecs
8
8
  from citesync.config import Config, git_top
9
9
  from citesync.errors import CheckError, UnreadableError
10
- from citesync.formats import CITATION_FILES, MANIFESTS, Doc, Person, format_of, read_doc, same_name, slots
11
- from citesync.mapping import FORMATS, PEOPLE, TERMS, Mapping, load_mapping
10
+ from citesync.formats import (
11
+ CITATION_FILES,
12
+ DATASET_FILES,
13
+ MANIFESTS,
14
+ ONE_AUTHOR,
15
+ Doc,
16
+ Person,
17
+ format_of,
18
+ read_doc,
19
+ same_name,
20
+ slots,
21
+ )
22
+ from citesync.mapping import DATASETS, FORMATS, IMPORTED, PEOPLE, TERMS, Mapping, load_mapping
12
23
  from citesync.rules import MISMATCH, RULES, url
13
24
 
14
25
 
@@ -79,7 +90,7 @@ def discover(root: Path, config: Config) -> list[str]:
79
90
  citation = config.files if config.files is not None else tuple(CITATION_FILES)
80
91
  paths = [config.source, *(p for p in citation if (root / p).is_file())]
81
92
  if config.manifests is None:
82
- paths += [p for p in MANIFESTS if (root / p).is_file()]
93
+ paths += [p for p in (*MANIFESTS, *DATASET_FILES) if (root / p).is_file()]
83
94
  else:
84
95
  for path in config.manifests:
85
96
  if not (root / path).is_file():
@@ -123,7 +134,9 @@ def read_docs(root: Path, config: Config, mapping: Mapping) -> tuple[list[Doc],
123
134
  Finding(d.path, None, "manifest-skipped", _NOT_RELEASED[d.format]) for d in docs if d not in kept
124
135
  ]
125
136
  docs = kept
126
- return docs[:1] + sorted(docs[1:], key=lambda d: (FORMATS.index(d.format), d.path)), unreadable
137
+ return docs[:1] + sorted(
138
+ docs[1:], key=lambda d: ((*FORMATS, *IMPORTED, *DATASETS).index(d.format), d.path)
139
+ ), unreadable
127
140
 
128
141
 
129
142
  _NOT_RELEASED = {
@@ -136,7 +149,12 @@ def check(root: Path, config: Config) -> tuple[list[Finding], int, list[str]]:
136
149
  """Every finding for the repo at ``root``, sorted, the number of files checked, and the unused ignore entries."""
137
150
  mapping = load_mapping()
138
151
  docs, read = read_docs(root, config, mapping)
139
- found, unused = findings(docs, [*read, *version_behind_tag(docs[0], git_tags(root))], config)
152
+ extra = [*read, *version_behind_tag(docs[0], git_tags(root))]
153
+ if config.exports:
154
+ from citesync.export import stale # noqa: PLC0415
155
+
156
+ extra += stale(root, docs, config)
157
+ found, unused = findings(docs, extra, config)
140
158
  if any(f.file and f.term for f in found): # a check with nothing to point at reads no file twice
141
159
  from citesync.positions import place # noqa: PLC0415
142
160
 
@@ -211,6 +229,8 @@ def findings(docs: list[Doc], extra: list[Finding], config: Config) -> tuple[set
211
229
  found.add(Finding(doc.path, key, "role-dangling", detail))
212
230
  for term, message in doc.import_notes:
213
231
  found.add(Finding(doc.path, term, "metadata-omitted", message))
232
+ for key, rule, message in doc.stray_terms:
233
+ found.add(Finding(doc.path, key, rule, message))
214
234
  for key, rule in doc.zenodo_gaps:
215
235
  found.add(Finding(doc.path, key, rule, ZENODO_GAPS[rule]))
216
236
  for term in TERMS:
@@ -370,7 +390,7 @@ def _same_people(ref: Doc, doc: Doc, term: str, *, names: bool) -> bool:
370
390
  """
371
391
  a: tuple[Person, ...] = ref.record[term]
372
392
  b: tuple[Person, ...] = doc.record[term]
373
- if term == "author" and "npm" in {ref.format, doc.format}:
393
+ if term == "author" and ONE_AUTHOR & {ref.format, doc.format}:
374
394
  a, b = a[:1], b[:1]
375
395
  if names and len(a) != len(b):
376
396
  return False
@@ -1,9 +1,10 @@
1
1
  """Command line: ``citesync check|write|init|config|rules|explain``.
2
2
 
3
3
  Exit codes: 0 when the files agree (after ``write``, once it has written), 1 on any error
4
- finding (that ``write`` may not fix), 2 when citesync couldn't run. ``write --diff`` exits 1
5
- when it would change a file or can't read one, as ``ruff format --diff`` does. ``write`` then wrote nothing,
6
- unless moving a written file into place failed: files moved before it stay written.
4
+ finding (that ``write`` may not fix), 2 on a usage error, 3 when citesync couldn't run, 130 after
5
+ Ctrl-C. ``write --diff`` exits 1 when it would change a file or can't read one, as ``ruff format --diff``
6
+ does. ``write`` then wrote nothing, unless moving a written file into place failed: files moved before
7
+ it stay written.
7
8
  """
8
9
 
9
10
  import argparse
@@ -14,14 +15,19 @@ import re
14
15
  import sys
15
16
  from dataclasses import replace
16
17
  from pathlib import Path
17
- from typing import Any
18
+ from typing import Any, NoReturn
18
19
 
19
20
  from citesync.check import Finding, check
20
- from citesync.config import Config, did_you_mean, find_root, git_top, load_config, render
21
- from citesync.errors import CheckError
21
+ from citesync.config import Config, find_root, git_top, load_config, render
22
+ from citesync.errors import CheckError, did_you_mean
22
23
  from citesync.rules import DOCS_URL, RULES, explain, url
23
24
 
24
- JSON_VERSION = 1
25
+ JSON_SCHEMA_VERSION = 1
26
+ EXIT_COULD_NOT_RUN = 3
27
+ EXIT_INTERRUPTED = 130
28
+ # the keys of citesync.export._WRITERS, spelled out so the parser needs no import of that module
29
+ _EXPORT_FORMATS = ("bibtex", "csl-json", "apa", "jsonld", "datacite", "ris", "endnote")
30
+ _CITATION_FILES = ("cff", "codemeta", "zenodo") # made by write's builders, so never under exports
25
31
  _ANSI = {"error": "1;31", "warning": "1;33", "info": "1;34"}
26
32
  _GITHUB_LEVEL = {"error": "error", "warning": "warning", "info": "notice"}
27
33
  _SARIF_LEVEL = {"error": "error", "warning": "warning", "info": "note"}
@@ -97,11 +103,14 @@ def _directory(value: str) -> Path:
97
103
 
98
104
 
99
105
  _DESCRIPTION = """Check that CITATION.cff, codemeta.json, .zenodo.json and the package manifests
100
- (pyproject.toml, Cargo.toml, package.json) agree, and rewrite them to match one source file."""
106
+ (pyproject.toml, Cargo.toml, package.json, typst.toml, _extension.yml) agree, and rewrite them
107
+ to match one source file."""
101
108
  _EPILOG = f"""exit codes:
102
109
  0 no error finding (warnings and info don't fail)
103
110
  1 an error finding; with write --diff, a change to make or a file it can't read
104
- 2 citesync couldn't run: a bad config or option, a missing source file
111
+ 2 usage error: an unknown command, option or rule
112
+ 3 citesync couldn't run: a bad config, a missing source file
113
+ 130 interrupted with Ctrl-C
105
114
 
106
115
  config: the first of citesync.toml, .citesync.toml, [tool.citesync] in pyproject.toml,
107
116
  [workspace.metadata.citesync] or [package.metadata.citesync] in Cargo.toml, or "citesync" in package.json
@@ -157,6 +166,17 @@ def _parser() -> argparse.ArgumentParser:
157
166
  " holds it: --source, then the files in the order above.",
158
167
  )
159
168
  init_.add_argument("--diff", action="store_true", help="print the new file as a unified diff and write nothing")
169
+ export = "print a citation or citation file made from the source, writing nothing"
170
+ export_ = sub.add_parser(
171
+ "export",
172
+ parents=[root],
173
+ help=export,
174
+ description=f"{export[0].upper()}{export[1:]}.\n"
175
+ "List bibtex, csl-json, apa, jsonld, datacite, ris or endnote files under exports to keep them in step.",
176
+ )
177
+ export_.add_argument(
178
+ "--format", choices=_EXPORT_FORMATS + _CITATION_FILES, required=True, help="the citation format"
179
+ )
160
180
  sub.add_parser("config", parents=[root], help="print the config in use and where it came from")
161
181
  rules = sub.add_parser("rules", help="list the rules")
162
182
  rules.add_argument("--format", choices=("text", "json"), default="text", help="output format (default: text)")
@@ -164,30 +184,68 @@ def _parser() -> argparse.ArgumentParser:
164
184
  return parser
165
185
 
166
186
 
167
- def main(argv: list[str] | None = None) -> int: # noqa: C901, PLR0911 - a return per command
187
+ def main(argv: list[str] | None = None) -> int:
168
188
  """Run the command line and return its exit code."""
169
189
  _utf8_streams()
170
190
  args = _parse(argv)
171
- if args.command in {"rules", "explain"}:
172
- return _rules(args)
173
191
  try:
174
- args.root = args.root or find_root(Path.cwd())
175
- config = load_config(args.root, args.source)
176
- if args.command == "config":
177
- print(f"# root: {args.root}\n{render(config)}")
178
- return 0
179
- if args.command == "init":
180
- return _init(args.root, config, diff=args.diff)
181
- if getattr(args, "diff", False):
182
- return _write_diff(args.root, config)
183
- written, skipped, fixed = _write(args.root, config) if args.command == "write" else ({}, {}, None)
184
- findings, files, unused = check(args.root, config)
192
+ return _run(args)
185
193
  except CheckError as err:
186
- print(f"citesync: {err}", file=sys.stderr)
187
- return 2
194
+ return _failed(args, str(err), EXIT_COULD_NOT_RUN)
195
+ except KeyboardInterrupt:
196
+ return _failed(args, "interrupted", EXIT_INTERRUPTED)
188
197
  except Exception as err: # noqa: BLE001 - a crash is "couldn't check", never exit 1 ("they disagree")
189
- print(f"citesync: {args.root}: unexpected error: {type(err).__name__}: {err}", file=sys.stderr)
190
- return 2
198
+ where = f"{args.root}: " if getattr(args, "root", None) else ""
199
+ return _failed(args, f"{where}unexpected error: {type(err).__name__}: {err}", EXIT_COULD_NOT_RUN)
200
+
201
+
202
+ def entry() -> NoReturn:
203
+ """The ``citesync`` command: run :func:`main`, and after Ctrl-C die of SIGINT, as the shell expects.
204
+
205
+ A shell loop stops on Ctrl-C only when the command was killed by the signal; exit 130 alone doesn't stop it.
206
+ """
207
+ code = main()
208
+ if code == EXIT_INTERRUPTED and sys.platform != "win32":
209
+ import signal # noqa: PLC0415
210
+
211
+ sys.stdout.flush()
212
+ sys.stderr.flush()
213
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
214
+ os.kill(os.getpid(), signal.SIGINT)
215
+ sys.exit(code)
216
+
217
+
218
+ def _failed(args: argparse.Namespace, message: str, code: int) -> int:
219
+ """Report a run that couldn't finish: ``citesync: <message>`` on stderr, or with JSON a report of the error."""
220
+ if getattr(args, "format", None) == "json":
221
+ errors = [{"message": message, "help": None}]
222
+ print(json.dumps({"schema_version": JSON_SCHEMA_VERSION, "tool": _tool(), "errors": errors}, indent=2))
223
+ else:
224
+ print(f"citesync: {message}", file=sys.stderr)
225
+ return code
226
+
227
+
228
+ def _tool() -> dict[str, str]:
229
+ return {"name": "citesync", "version": _version()}
230
+
231
+
232
+ def _run(args: argparse.Namespace) -> int:
233
+ """Run the parsed command; :func:`main` turns what it raises into an exit code."""
234
+ if args.command in {"rules", "explain"}:
235
+ return _rules(args)
236
+ args.root = args.root or find_root(Path.cwd())
237
+ config = load_config(args.root, args.source)
238
+ if args.command == "config":
239
+ print(f"# root: {args.root}\n{render(config)}")
240
+ return 0
241
+ if args.command == "init":
242
+ return _init(args.root, config, diff=args.diff)
243
+ if args.command == "export":
244
+ return _export(args.root, config, args.format)
245
+ if getattr(args, "diff", False):
246
+ return _write_diff(args.root, config, quiet=args.quiet)
247
+ written, skipped, fixed = _write(args.root, config) if args.command == "write" else ({}, {}, None)
248
+ findings, files, unused = check(args.root, config)
191
249
  failed = any(f.severity == "error" for f in findings)
192
250
  if args.command == "check" and failed and args.format == "text" and not args.quiet:
193
251
  fixed = _fixable(args.root, config) # only a failing check pays for write's imports
@@ -258,28 +316,57 @@ def _fixable(root: Path, config: Config) -> list[Finding] | None:
258
316
  return None
259
317
 
260
318
 
261
- def _write_diff(root: Path, config: Config) -> int:
319
+ def _write_diff(root: Path, config: Config, *, quiet: bool) -> int:
262
320
  """Print the edits write would make as a unified diff, and any file it can't read on stderr."""
263
321
  from citesync.write import write # noqa: PLC0415
264
322
 
265
323
  texts, _, unreadable, fixed = write(root, config, dry_run=True)
266
324
  sys.stdout.write(_diff(root, texts))
267
- if texts:
325
+ if texts and not quiet:
268
326
  print(f"would fix {_count(len(fixed), 'finding')} in {_count(len(texts), 'file')}", file=sys.stderr)
269
327
  for f in unreadable: # the diff can't show a file write never touches, so say so
270
328
  print(f"{f.where}: error[unreadable] {f.message}", file=sys.stderr)
271
329
  return 1 if texts or unreadable else 0
272
330
 
273
331
 
332
+ def _export(root: Path, config: Config, fmt: str) -> int:
333
+ """Print the source's citation in ``fmt``; what it left out goes to stderr."""
334
+ from citesync.check import read_docs # noqa: PLC0415
335
+ from citesync.export import record, render # noqa: PLC0415
336
+ from citesync.mapping import load_mapping # noqa: PLC0415
337
+ from citesync.write import _merged, citation_file, union # noqa: PLC0415
338
+
339
+ mapping = load_mapping()
340
+ if fmt == "cff": # built as init builds it, so it needs no CITATION.cff to read
341
+ source, left_out = _merged(root, config, mapping)
342
+ text, skipped = citation_file(fmt, root, config, source, mapping)
343
+ notes = [f"leaving out {term}: {why}" for term, why in skipped.items()] + left_out
344
+ else:
345
+ docs, read = read_docs(root, config, mapping)
346
+ if not docs[0].readable:
347
+ bad = next(f for f in read if f.file == docs[0].path and f.rule == "unreadable")
348
+ msg = f"{bad.where}: {bad.message}"
349
+ raise CheckError(msg)
350
+ if fmt in _CITATION_FILES:
351
+ text, skipped = citation_file(fmt, root, config, replace(docs[0], record=union(docs, config)), mapping)
352
+ notes = [f"leaving out {term}: {why}" for term, why in skipped.items()]
353
+ else:
354
+ text, notes = render(fmt, record(docs))
355
+ sys.stdout.write(text)
356
+ for note in notes:
357
+ print(note, file=sys.stderr)
358
+ return 0
359
+
360
+
274
361
  def _init(root: Path, config: Config, *, diff: bool) -> int:
275
362
  """Write a new CITATION.cff, or with ``diff`` print it as a diff from nothing."""
276
363
  from citesync.write import init # noqa: PLC0415
277
364
 
278
- text, skipped, splits = init(root, config, dry_run=diff)
365
+ text, skipped, splits, left_out = init(root, config, dry_run=diff)
279
366
  left = "; ".join(f"{term}: {why}" for term, why in skipped.items())
280
367
  notes = [
281
368
  f"check the name split: {name!r} became given {given!r}, family {family!r}" for name, given, family in splits
282
- ]
369
+ ] + left_out
283
370
  if diff: # the notes go to stderr, so stdout stays a diff a tool can read
284
371
  sys.stdout.write(_diff(root, {"CITATION.cff": text}))
285
372
  for line in ([f"leaving out {left}"] if left else []) + notes:
@@ -300,10 +387,11 @@ def _report(findings: list[Finding], files: int, args: argparse.Namespace, fixed
300
387
  if args.format == "json":
301
388
  summary = {"files": files, "errors": counts["error"], "warnings": counts["warning"], "info": counts["info"]}
302
389
  report = {
303
- "version": JSON_VERSION,
304
- "tool": {"name": "citesync", "version": _version()},
390
+ "schema_version": JSON_SCHEMA_VERSION,
391
+ "tool": _tool(),
305
392
  "summary": summary,
306
393
  "findings": [f.as_dict() for f in findings],
394
+ "errors": [],
307
395
  }
308
396
  print(json.dumps(report, indent=2))
309
397
  return
@@ -455,4 +543,4 @@ def _escape(text: str, *, property_: bool = False) -> str:
455
543
 
456
544
 
457
545
  if __name__ == "__main__":
458
- sys.exit(main())
546
+ entry()
@@ -64,8 +64,8 @@ def license_decode(raw: object) -> str | None:
64
64
  return " OR ".join(ids) or None
65
65
  if isinstance(raw, dict):
66
66
  raw = raw.get("text") # a {file = ...} table names a file, not a licence
67
- if not isinstance(raw, str) or not raw.strip():
68
- return None
67
+ if not isinstance(raw, str) or not raw.strip() or raw.strip().startswith("#"):
68
+ return None # a JSON-LD local id, such as an RO-Crate's #license, names an entity, not a licence
69
69
  raw = raw.strip()
70
70
  match = _SPDX_URL.match(raw)
71
71
  return match["id"] if match else raw
@@ -277,6 +277,18 @@ def date_decode(raw: object) -> str | None:
277
277
  return text[:10] if text and _ISO_DATE.match(text) else text
278
278
 
279
279
 
280
+ def publisher_decode(raw: object) -> str | None:
281
+ """A publisher's name: the text the row reads (``publisher.name`` or ``publisher``).
282
+
283
+ The row takes an Organization's ``name`` itself. Its second alternative reads a list whole, and that
284
+ gives the first name when every item is an Organization with one, else nothing.
285
+ """
286
+ if isinstance(raw, list):
287
+ names = [version_decode(item.get("name")) if isinstance(item, dict) else None for item in raw]
288
+ return names[0] if names and all(names) else None
289
+ return version_decode(raw)
290
+
291
+
280
292
  def version_key(version: str) -> "Version | str":
281
293
  """The parsed PEP 440 version, or for one that isn't (``unreleased``) the string itself.
282
294