citesync 0.4.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 (35) hide show
  1. {citesync-0.4.0 → citesync-0.5.0}/PKG-INFO +11 -11
  2. {citesync-0.4.0 → citesync-0.5.0}/README.md +9 -8
  3. {citesync-0.4.0 → citesync-0.5.0}/pyproject.toml +5 -5
  4. {citesync-0.4.0 → citesync-0.5.0}/pyproject.toml.orig +5 -5
  5. citesync-0.5.0/src/citesync/MAPPING_SOURCE +7 -0
  6. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/__main__.py +2 -4
  7. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/check.py +20 -5
  8. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/cli.py +82 -39
  9. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/codecs.py +14 -2
  10. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/config.py +12 -14
  11. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/core_metadata.py +60 -39
  12. {citesync-0.4.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.4.0 → citesync-0.5.0}/src/citesync/formats.py +213 -38
  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.4.0 → citesync-0.5.0}/src/citesync/mapping.schema.json +10 -4
  20. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/playground.py +4 -4
  21. citesync-0.5.0/src/citesync/playground_exports.py +258 -0
  22. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/positions.py +12 -3
  23. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/research_metadata.py +51 -61
  24. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/rules.py +31 -7
  25. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/write.py +39 -21
  26. citesync-0.4.0/src/citesync/MAPPING_SOURCE +0 -5
  27. citesync-0.4.0/src/citesync/export.py +0 -272
  28. citesync-0.4.0/src/citesync/mapping-local.json +0 -1219
  29. citesync-0.4.0/src/citesync/mapping.py +0 -142
  30. citesync-0.4.0/src/citesync/playground_exports.py +0 -89
  31. {citesync-0.4.0 → citesync-0.5.0}/LICENSE +0 -0
  32. {citesync-0.4.0 → citesync-0.5.0}/NOTICE +0 -0
  33. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/__init__.py +0 -0
  34. {citesync-0.4.0 → citesync-0.5.0}/src/citesync/jsonsplice.py +0 -0
  35. {citesync-0.4.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.4.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
 
@@ -45,16 +45,16 @@ Generate software citation files from package metadata, then keep them in sync a
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, cff, codemeta or zenodo
57
+ citesync export --format apa # print a citation: apa, bibtex, csl-json, jsonld, datacite, ris, endnote, cff, codemeta or zenodo
58
58
  citesync explain version-mismatch # what a rule checks and how to fix it
59
59
  citesync config # the config in use, and the file it came from
60
60
  ```
@@ -72,9 +72,9 @@ A config is optional. A one-line `citesync.toml` is `ignore = ["description-mism
72
72
 
73
73
  - [How check works](https://github.com/simonvanlierde/citesync/blob/main/docs/check.md): the fields, files, options and exit codes.
74
74
  - [How write works](https://github.com/simonvanlierde/citesync/blob/main/docs/write.md): what it changes and what it leaves alone.
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.
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.
76
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 and schema.org JSON-LD files kept in step with the source.
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.
78
78
  - [Rules](https://github.com/simonvanlierde/citesync/blob/main/docs/rules.md): each rule id, what it checks and how to fix it.
79
79
  - [Configuration](https://github.com/simonvanlierde/citesync/blob/main/docs/config.md): where config goes, and every key.
80
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.
@@ -92,13 +92,13 @@ For [prek](https://prek.j178.dev) or [pre-commit](https://pre-commit.com), in `.
92
92
  ```yaml
93
93
  repos:
94
94
  - repo: https://github.com/simonvanlierde/citesync
95
- rev: v0.4.0
95
+ rev: v0.5.0
96
96
  hooks:
97
97
  - id: citesync
98
98
  - id: citesync-write
99
99
  ```
100
100
 
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`), 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.
102
102
 
103
103
  ## Development
104
104
 
@@ -119,7 +119,7 @@ just fmt # apply each stack's fixes and formatting
119
119
  just hooks # the git hooks, as the checks workflow runs them
120
120
  ```
121
121
 
122
- `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.
123
123
 
124
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)).
125
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
 
@@ -15,16 +16,16 @@ Generate software citation files from package metadata, then keep them in sync a
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
27
- citesync export --format apa # print a citation: apa, bibtex, csl-json, jsonld, cff, codemeta or zenodo
28
+ citesync export --format apa # print a citation: apa, bibtex, csl-json, jsonld, datacite, ris, endnote, cff, codemeta or zenodo
28
29
  citesync explain version-mismatch # what a rule checks and how to fix it
29
30
  citesync config # the config in use, and the file it came from
30
31
  ```
@@ -42,9 +43,9 @@ A config is optional. A one-line `citesync.toml` is `ignore = ["description-mism
42
43
 
43
44
  - [How check works](https://github.com/simonvanlierde/citesync/blob/main/docs/check.md): the fields, files, options and exit codes.
44
45
  - [How write works](https://github.com/simonvanlierde/citesync/blob/main/docs/write.md): what it changes and what it leaves alone.
45
- - [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.
46
47
  - [How init works](https://github.com/simonvanlierde/citesync/blob/main/docs/init.md): where a new CITATION.cff takes each field from.
47
- - [Citation exports](https://github.com/simonvanlierde/citesync/blob/main/docs/export.md): BibTeX, CSL-JSON, APA and schema.org JSON-LD files kept in step with the source.
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.
48
49
  - [Rules](https://github.com/simonvanlierde/citesync/blob/main/docs/rules.md): each rule id, what it checks and how to fix it.
49
50
  - [Configuration](https://github.com/simonvanlierde/citesync/blob/main/docs/config.md): where config goes, and every key.
50
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.
@@ -62,13 +63,13 @@ For [prek](https://prek.j178.dev) or [pre-commit](https://pre-commit.com), in `.
62
63
  ```yaml
63
64
  repos:
64
65
  - repo: https://github.com/simonvanlierde/citesync
65
- rev: v0.4.0
66
+ rev: v0.5.0
66
67
  hooks:
67
68
  - id: citesync
68
69
  - id: citesync-write
69
70
  ```
70
71
 
71
- 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`), 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.
72
73
 
73
74
  ## Development
74
75
 
@@ -89,7 +90,7 @@ just fmt # apply each stack's fixes and formatting
89
90
  just hooks # the git hooks, as the checks workflow runs them
90
91
  ```
91
92
 
92
- `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.
93
94
 
94
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)).
95
96
 
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "citesync"
3
- version = "0.4.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.4.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 = {
@@ -216,6 +229,8 @@ def findings(docs: list[Doc], extra: list[Finding], config: Config) -> tuple[set
216
229
  found.add(Finding(doc.path, key, "role-dangling", detail))
217
230
  for term, message in doc.import_notes:
218
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))
219
234
  for key, rule in doc.zenodo_gaps:
220
235
  found.add(Finding(doc.path, key, rule, ZENODO_GAPS[rule]))
221
236
  for term in TERMS:
@@ -375,7 +390,7 @@ def _same_people(ref: Doc, doc: Doc, term: str, *, names: bool) -> bool:
375
390
  """
376
391
  a: tuple[Person, ...] = ref.record[term]
377
392
  b: tuple[Person, ...] = doc.record[term]
378
- if term == "author" and "npm" in {ref.format, doc.format}:
393
+ if term == "author" and ONE_AUTHOR & {ref.format, doc.format}:
379
394
  a, b = a[:1], b[:1]
380
395
  if names and len(a) != len(b):
381
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,16 +15,18 @@ 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
25
28
  # the keys of citesync.export._WRITERS, spelled out so the parser needs no import of that module
26
- _EXPORT_FORMATS = ("bibtex", "csl-json", "apa", "jsonld")
29
+ _EXPORT_FORMATS = ("bibtex", "csl-json", "apa", "jsonld", "datacite", "ris", "endnote")
27
30
  _CITATION_FILES = ("cff", "codemeta", "zenodo") # made by write's builders, so never under exports
28
31
  _ANSI = {"error": "1;31", "warning": "1;33", "info": "1;34"}
29
32
  _GITHUB_LEVEL = {"error": "error", "warning": "warning", "info": "notice"}
@@ -105,7 +108,9 @@ to match one source file."""
105
108
  _EPILOG = f"""exit codes:
106
109
  0 no error finding (warnings and info don't fail)
107
110
  1 an error finding; with write --diff, a change to make or a file it can't read
108
- 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
109
114
 
110
115
  config: the first of citesync.toml, .citesync.toml, [tool.citesync] in pyproject.toml,
111
116
  [workspace.metadata.citesync] or [package.metadata.citesync] in Cargo.toml, or "citesync" in package.json
@@ -167,7 +172,7 @@ def _parser() -> argparse.ArgumentParser:
167
172
  parents=[root],
168
173
  help=export,
169
174
  description=f"{export[0].upper()}{export[1:]}.\n"
170
- "List bibtex, csl-json, apa or jsonld files under exports to keep them in step.",
175
+ "List bibtex, csl-json, apa, jsonld, datacite, ris or endnote files under exports to keep them in step.",
171
176
  )
172
177
  export_.add_argument(
173
178
  "--format", choices=_EXPORT_FORMATS + _CITATION_FILES, required=True, help="the citation format"
@@ -179,32 +184,68 @@ def _parser() -> argparse.ArgumentParser:
179
184
  return parser
180
185
 
181
186
 
182
- def main(argv: list[str] | None = None) -> int: # noqa: C901, PLR0911 - a return per command
187
+ def main(argv: list[str] | None = None) -> int:
183
188
  """Run the command line and return its exit code."""
184
189
  _utf8_streams()
185
190
  args = _parse(argv)
186
- if args.command in {"rules", "explain"}:
187
- return _rules(args)
188
191
  try:
189
- args.root = args.root or find_root(Path.cwd())
190
- config = load_config(args.root, args.source)
191
- if args.command == "config":
192
- print(f"# root: {args.root}\n{render(config)}")
193
- return 0
194
- if args.command == "init":
195
- return _init(args.root, config, diff=args.diff)
196
- if args.command == "export":
197
- return _export(args.root, config, args.format)
198
- if getattr(args, "diff", False):
199
- return _write_diff(args.root, config)
200
- written, skipped, fixed = _write(args.root, config) if args.command == "write" else ({}, {}, None)
201
- findings, files, unused = check(args.root, config)
192
+ return _run(args)
202
193
  except CheckError as err:
203
- print(f"citesync: {err}", file=sys.stderr)
204
- return 2
194
+ return _failed(args, str(err), EXIT_COULD_NOT_RUN)
195
+ except KeyboardInterrupt:
196
+ return _failed(args, "interrupted", EXIT_INTERRUPTED)
205
197
  except Exception as err: # noqa: BLE001 - a crash is "couldn't check", never exit 1 ("they disagree")
206
- print(f"citesync: {args.root}: unexpected error: {type(err).__name__}: {err}", file=sys.stderr)
207
- 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)
208
249
  failed = any(f.severity == "error" for f in findings)
209
250
  if args.command == "check" and failed and args.format == "text" and not args.quiet:
210
251
  fixed = _fixable(args.root, config) # only a failing check pays for write's imports
@@ -275,13 +316,13 @@ def _fixable(root: Path, config: Config) -> list[Finding] | None:
275
316
  return None
276
317
 
277
318
 
278
- def _write_diff(root: Path, config: Config) -> int:
319
+ def _write_diff(root: Path, config: Config, *, quiet: bool) -> int:
279
320
  """Print the edits write would make as a unified diff, and any file it can't read on stderr."""
280
321
  from citesync.write import write # noqa: PLC0415
281
322
 
282
323
  texts, _, unreadable, fixed = write(root, config, dry_run=True)
283
324
  sys.stdout.write(_diff(root, texts))
284
- if texts:
325
+ if texts and not quiet:
285
326
  print(f"would fix {_count(len(fixed), 'finding')} in {_count(len(texts), 'file')}", file=sys.stderr)
286
327
  for f in unreadable: # the diff can't show a file write never touches, so say so
287
328
  print(f"{f.where}: error[unreadable] {f.message}", file=sys.stderr)
@@ -297,8 +338,9 @@ def _export(root: Path, config: Config, fmt: str) -> int:
297
338
 
298
339
  mapping = load_mapping()
299
340
  if fmt == "cff": # built as init builds it, so it needs no CITATION.cff to read
300
- text, skipped = citation_file(fmt, root, config, _merged(root, config, mapping), mapping)
301
- notes = [f"leaving out {term}: {why}" for term, why in skipped.items()]
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
302
344
  else:
303
345
  docs, read = read_docs(root, config, mapping)
304
346
  if not docs[0].readable:
@@ -320,11 +362,11 @@ def _init(root: Path, config: Config, *, diff: bool) -> int:
320
362
  """Write a new CITATION.cff, or with ``diff`` print it as a diff from nothing."""
321
363
  from citesync.write import init # noqa: PLC0415
322
364
 
323
- text, skipped, splits = init(root, config, dry_run=diff)
365
+ text, skipped, splits, left_out = init(root, config, dry_run=diff)
324
366
  left = "; ".join(f"{term}: {why}" for term, why in skipped.items())
325
367
  notes = [
326
368
  f"check the name split: {name!r} became given {given!r}, family {family!r}" for name, given, family in splits
327
- ]
369
+ ] + left_out
328
370
  if diff: # the notes go to stderr, so stdout stays a diff a tool can read
329
371
  sys.stdout.write(_diff(root, {"CITATION.cff": text}))
330
372
  for line in ([f"leaving out {left}"] if left else []) + notes:
@@ -345,10 +387,11 @@ def _report(findings: list[Finding], files: int, args: argparse.Namespace, fixed
345
387
  if args.format == "json":
346
388
  summary = {"files": files, "errors": counts["error"], "warnings": counts["warning"], "info": counts["info"]}
347
389
  report = {
348
- "version": JSON_VERSION,
349
- "tool": {"name": "citesync", "version": _version()},
390
+ "schema_version": JSON_SCHEMA_VERSION,
391
+ "tool": _tool(),
350
392
  "summary": summary,
351
393
  "findings": [f.as_dict() for f in findings],
394
+ "errors": [],
352
395
  }
353
396
  print(json.dumps(report, indent=2))
354
397
  return
@@ -500,4 +543,4 @@ def _escape(text: str, *, property_: bool = False) -> str:
500
543
 
501
544
 
502
545
  if __name__ == "__main__":
503
- 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
 
@@ -1,13 +1,13 @@
1
1
  """Find and validate the config: the first location found wins, flags override it."""
2
2
 
3
3
  import json
4
- from collections.abc import Callable, Iterable
4
+ from collections.abc import Callable
5
5
  from dataclasses import dataclass, replace
6
6
  from pathlib import Path, PurePosixPath
7
7
  from typing import Any
8
8
 
9
- from citesync.errors import CheckError, UnreadableError
10
- from citesync.formats import CITATION_FILES, CODEMETA_VERSIONS, FORMAT_OF, MANIFESTS, load
9
+ from citesync.errors import CheckError, UnreadableError, did_you_mean
10
+ from citesync.formats import CITATION_FILES, CODEMETA_VERSIONS, DATASET_FILES, FORMAT_OF, MANIFESTS, load
11
11
  from citesync.mapping import TERMS, resolve
12
12
  from citesync.rules import MISMATCH, RULES
13
13
 
@@ -71,7 +71,7 @@ def find_root(start: Path) -> Path:
71
71
  names = (*CITATION_FILES, "citesync.toml", ".citesync.toml")
72
72
  if any((directory / name).is_file() for name in names) or find_config(directory)[1] != "defaults":
73
73
  return directory
74
- if (directory / ".git").exists():
74
+ if _is_repo(directory):
75
75
  return directory
76
76
  return start
77
77
 
@@ -79,7 +79,13 @@ def find_root(start: Path) -> Path:
79
79
  def git_top(start: Path) -> Path | None:
80
80
  """The nearest directory from ``start`` up that holds ``.git``: the top of its repo, or None outside one."""
81
81
  start = start.resolve()
82
- return next((directory for directory in (start, *start.parents) if (directory / ".git").exists()), None)
82
+ return next((directory for directory in (start, *start.parents) if _is_repo(directory)), None)
83
+
84
+
85
+ def _is_repo(directory: Path) -> bool:
86
+ """Whether ``directory`` holds a ``.git`` git would accept: a folder with ``HEAD``, or a submodule's file."""
87
+ git = directory / ".git"
88
+ return (git / "HEAD").is_file() or git.is_file()
83
89
 
84
90
 
85
91
  def load_config(root: Path, source: str | None = None) -> Config:
@@ -180,14 +186,6 @@ MANIFEST_TERMS = ("version", "author", "contributor", "license", "codeRepository
180
186
  _RULE_NAMES = {rule.removesuffix("-mismatch"): term for term, rule in MISMATCH.items()}
181
187
 
182
188
 
183
- def did_you_mean(word: str, choices: Iterable[str]) -> str:
184
- """``; did you mean 'x'?`` for the closest of ``choices``, or nothing when none is close."""
185
- import difflib # noqa: PLC0415 - only on an error
186
-
187
- close = difflib.get_close_matches(word, list(choices), n=1)
188
- return f"; did you mean {close[0]!r}?" if close else ""
189
-
190
-
191
189
  def _write_manifests(value: object, origin: str) -> tuple[str, ...]:
192
190
  items = [value] if isinstance(value, str) else value
193
191
  if not isinstance(items, list) or not all(isinstance(i, str) for i in items):
@@ -241,7 +239,7 @@ _PARSE: dict[str, Callable[[object, str], Any]] = {
241
239
  "source": lambda value, origin: _path(value, FORMAT_OF, origin, "source"),
242
240
  "codemeta-version": _codemeta_version,
243
241
  "files": lambda value, origin: _paths(value, CITATION_FILES, origin, "files"),
244
- "manifests": lambda value, origin: _paths(value, MANIFESTS, origin, "manifests"),
242
+ "manifests": lambda value, origin: _paths(value, MANIFESTS | DATASET_FILES, origin, "manifests"),
245
243
  "write-manifests": _write_manifests,
246
244
  "exports": _exports,
247
245
  "zenodo-contributor-type": _zenodo_contributor_type,