calkit-python 0.41.6__py3-none-any.whl → 0.41.7__py3-none-any.whl

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 (31) hide show
  1. calkit/cli/new.py +33 -31
  2. calkit/cli/overleaf.py +12 -7
  3. calkit/core.py +1 -0
  4. calkit/licenses.py +152 -0
  5. calkit/overleaf.py +215 -79
  6. calkit/pipeline.py +13 -1
  7. calkit/releases.py +129 -29
  8. calkit/tests/cli/test_new.py +111 -13
  9. calkit/tests/cli/test_overleaf.py +128 -4
  10. calkit/tests/test_licenses.py +105 -0
  11. calkit/tests/test_releases.py +118 -0
  12. {calkit_python-0.41.6.dist-info → calkit_python-0.41.7.dist-info}/METADATA +1 -1
  13. {calkit_python-0.41.6.dist-info → calkit_python-0.41.7.dist-info}/RECORD +31 -30
  14. {calkit_python-0.41.6.dist-info → calkit_python-0.41.7.dist-info}/WHEEL +1 -1
  15. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/etc/jupyter/jupyter_server_config.d/calkit.json +0 -0
  16. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/install.json +0 -0
  17. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/package.json +0 -0
  18. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/schemas/calkit/package.json.orig +0 -0
  19. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/schemas/calkit/plugin.json +0 -0
  20. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/502.9a2c5772a15466e923ef.js +0 -0
  21. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/695.2c41003a452d43d2b358.js +0 -0
  22. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/867.a42a046aa5108f54f8fb.js +0 -0
  23. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/909.e3f9cc3408834a7fdcc3.js +0 -0
  24. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/946.050af2abf7845cfbdbd2.js +0 -0
  25. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/946.050af2abf7845cfbdbd2.js.LICENSE.txt +0 -0
  26. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/b2f1c3efe70cb539d121.png +0 -0
  27. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/remoteEntry.65469af996e7a96aa983.js +0 -0
  28. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/style.js +0 -0
  29. {calkit_python-0.41.6.data → calkit_python-0.41.7.data}/data/share/jupyter/labextensions/calkit/static/third-party-licenses.json +0 -0
  30. {calkit_python-0.41.6.dist-info → calkit_python-0.41.7.dist-info}/entry_points.txt +0 -0
  31. {calkit_python-0.41.6.dist-info → calkit_python-0.41.7.dist-info}/licenses/LICENSE +0 -0
calkit/cli/new.py CHANGED
@@ -3124,18 +3124,7 @@ def new_release(
3124
3124
  record_id = None
3125
3125
  # Detect project license IDs if necessary
3126
3126
  if not license_ids:
3127
- license_file = None
3128
- license_txt = None
3129
- license_candidates = [
3130
- "LICENSE",
3131
- "LICENSE.rst",
3132
- "LICENSE.txt",
3133
- "LICENSE.md",
3134
- ]
3135
- for lc in license_candidates:
3136
- if os.path.isfile(lc):
3137
- license_file = lc
3138
- break
3127
+ license_file = calkit.licenses.find_license_file()
3139
3128
  if license_file is None:
3140
3129
  typer.echo("No project license found.")
3141
3130
  use_default_license = typer.confirm(
@@ -3155,15 +3144,18 @@ def new_release(
3155
3144
  f.write(license_txt)
3156
3145
  repo.git.add("LICENSE")
3157
3146
  license_ids = ["mit", "cc-by-4.0"]
3158
- if license_txt is None and license_file is not None:
3147
+ else:
3148
+ typer.echo(f"Detecting license(s) from {license_file}")
3159
3149
  with open(license_file) as f:
3160
3150
  license_txt = f.read()
3161
- # Try to detect licenses
3162
- if "the mit license" in license_txt.lower():
3163
- license_ids.append("mit")
3164
- if "cc by 4.0" in license_txt.lower():
3165
- license_ids.append("cc-by-4.0")
3166
- # TODO: Detect others
3151
+ license_ids = calkit.licenses.detect_license_ids(license_txt)
3152
+ if license_ids:
3153
+ typer.echo(f"Detected license(s): {', '.join(license_ids)}")
3154
+ else:
3155
+ warn(
3156
+ f"Could not detect any known license in {license_file}; "
3157
+ "specify one explicitly with --license"
3158
+ )
3167
3159
  if not license_ids:
3168
3160
  raise_error("Project has no license(s) defined")
3169
3161
  invenio_metadata = dict(
@@ -3189,9 +3181,13 @@ def new_release(
3189
3181
  )
3190
3182
  invenio_metadata["related_identifiers"] = related_identifiers
3191
3183
  # TODO: Add calkit.io URL if applicable?
3192
- # Determine creators from authors, adding to project if not present
3193
- authors = ck_info.get("authors", [])
3194
- if not authors:
3184
+ # Determine creators from authors. CITATION.cff is the single source of
3185
+ # truth for authors, so read them from there; if none are defined yet,
3186
+ # prompt for them and persist them to CITATION.cff.
3187
+ authors = calkit.releases.read_authors_from_cff()
3188
+ if authors:
3189
+ typer.echo(f"Read {len(authors)} author(s) from CITATION.cff")
3190
+ else:
3195
3191
  warn("No authors defined for the project")
3196
3192
  still_entering_authors = True
3197
3193
  n = 0
@@ -3218,24 +3214,27 @@ def new_release(
3218
3214
  still_entering_authors = typer.confirm(
3219
3215
  "Are there more authors to enter?", default=True
3220
3216
  )
3221
- ck_info["authors"] = authors
3222
- # Write authors out to calkit.yaml
3217
+ # Write authors out to CITATION.cff
3223
3218
  if not dry_run:
3224
- typer.echo("Adding authors to calkit.yaml")
3225
- with open("calkit.yaml", "w") as f:
3226
- calkit.ryaml.dump(ck_info, f)
3219
+ typer.echo("Writing authors to CITATION.cff")
3220
+ calkit.releases.set_cff_authors(authors, ck_info=ck_info)
3221
+ repo.git.add("CITATION.cff")
3227
3222
  invenio_creators = []
3228
3223
  for author in authors:
3229
3224
  orcid = author.get("orcid")
3230
- creator = {
3225
+ creator: dict = {
3231
3226
  "person_or_org": {
3232
3227
  "type": "personal",
3233
3228
  "given_name": author["first_name"],
3234
3229
  "family_name": author["last_name"],
3235
3230
  "identifiers": [{"identifier": orcid}] if orcid else [],
3236
3231
  },
3237
- "affiliations": [{"name": author["affiliation"]}],
3238
3232
  }
3233
+ # Affiliation is optional (e.g., authors read from CITATION.cff may
3234
+ # not specify one)
3235
+ affiliation = author.get("affiliation")
3236
+ if affiliation:
3237
+ creator["affiliations"] = [{"name": affiliation}]
3239
3238
  invenio_creators.append(creator)
3240
3239
  invenio_metadata["creators"] = invenio_creators # type: ignore
3241
3240
  # Set InvenioRDM resource_type based on release_type and artifact kind
@@ -3423,10 +3422,13 @@ def new_release(
3423
3422
  )
3424
3423
  releases[name] = release
3425
3424
  ck_info["releases"] = releases
3426
- # Create CITATION.cff file
3425
+ # Create/update CITATION.cff file, preserving existing authors
3427
3426
  if release_type == "project":
3428
3427
  cff = calkit.releases.create_citation_cff(
3429
- ck_info=ck_info, release_name=name, release_date=release_date
3428
+ ck_info=ck_info,
3429
+ release_name=name,
3430
+ release_date=release_date,
3431
+ authors=authors,
3430
3432
  )
3431
3433
  if dry_run:
3432
3434
  typer.echo(f"Would write CITATION.cff:\n{cff}")
calkit/cli/overleaf.py CHANGED
@@ -12,9 +12,9 @@ import typer
12
12
  from typing_extensions import Annotated
13
13
 
14
14
  import calkit
15
- from calkit.cli import raise_error, warn
15
+ from calkit.cli import AliasGroup, raise_error, warn
16
16
 
17
- overleaf_app = typer.Typer(no_args_is_help=True)
17
+ overleaf_app = typer.Typer(cls=AliasGroup, no_args_is_help=True)
18
18
 
19
19
 
20
20
  def _extract_title_from_tex(tex_file_path: str) -> str | None:
@@ -369,8 +369,11 @@ def sync(
369
369
  typer.Option(
370
370
  "--no-commit",
371
371
  help=(
372
- "Do not commit the changes to the project repo. "
373
- "Changes will always be committed to Overleaf."
372
+ "Do not create a commit in the project repo for this sync. "
373
+ "Changes pulled from Overleaf are still applied, but are "
374
+ "left staged so you can review or commit them yourself. "
375
+ "Changes are always committed and pushed to Overleaf "
376
+ "regardless."
374
377
  ),
375
378
  ),
376
379
  ] = False,
@@ -378,6 +381,7 @@ def sync(
378
381
  bool,
379
382
  typer.Option(
380
383
  "--auto-commit",
384
+ "-a",
381
385
  help=(
382
386
  "Automatically commit changes to the project repo if a synced "
383
387
  "folder has changes."
@@ -490,8 +494,9 @@ def sync(
490
494
  )
491
495
  else:
492
496
  raise_error(
493
- f"Uncommitted changes found in {wdir}; "
494
- "please commit or stash them before syncing with Overleaf"
497
+ f"Uncommitted changes found in {wdir}. "
498
+ "Commit or stash them before syncing with Overleaf, "
499
+ "or use --auto-commit/-a to automatically commit them."
495
500
  )
496
501
  # Ensure we've cloned the Overleaf project
497
502
  overleaf_project_dir = os.path.join(
@@ -585,7 +590,7 @@ def compare_folders_recursively(
585
590
  return res
586
591
 
587
592
 
588
- @overleaf_app.command(name="status")
593
+ @overleaf_app.command(name="status|st")
589
594
  def get_status(
590
595
  paths: Annotated[
591
596
  list[str] | None,
calkit/core.py CHANGED
@@ -50,6 +50,7 @@ AUTO_IGNORE_SUFFIXES = [
50
50
  ".env",
51
51
  ".pyc",
52
52
  ".synctex.gz",
53
+ ".auxlock",
53
54
  ".ipynb_checkpoints",
54
55
  ]
55
56
  AUTO_IGNORE_PATHS = [os.path.join(".dvc", "config.local")]
calkit/licenses.py CHANGED
@@ -4,6 +4,158 @@ Calkit projects will often include code, data, text, and other content
4
4
  and artifacts that may each have their own license.
5
5
  """
6
6
 
7
+ from __future__ import annotations
8
+
9
+ import os
10
+ import re
11
+
12
+ # A list of (SPDX license ID, required substring groups) used to detect
13
+ # licenses from the text of a license file.
14
+ # Each entry maps an SPDX ID to a list of "all-of" groups; the license
15
+ # matches if *every* group has at least one of its substrings present in the
16
+ # (lowercased, whitespace-normalized) license text.
17
+ # This is intentionally tolerant so that licenses written by hand, generated
18
+ # by GitHub, or produced by Calkit's own templates are all detected.
19
+ # A single license file may contain more than one license (e.g., Calkit's
20
+ # default dual MIT/CC-BY-4.0 license), so all matching IDs are returned.
21
+ _LICENSE_MARKERS: list[tuple[str, list[list[str]]]] = [
22
+ (
23
+ "mit",
24
+ [
25
+ [
26
+ "mit license",
27
+ "permission is hereby granted, free of charge, to any "
28
+ "person obtaining a copy",
29
+ ]
30
+ ],
31
+ ),
32
+ (
33
+ "apache-2.0",
34
+ [["apache license"], ["version 2.0", "version 2,"]],
35
+ ),
36
+ (
37
+ "bsd-3-clause",
38
+ [
39
+ ["redistribution and use in source and binary forms"],
40
+ ["neither the name of"],
41
+ ],
42
+ ),
43
+ (
44
+ "bsd-2-clause",
45
+ [
46
+ ["redistribution and use in source and binary forms"],
47
+ ],
48
+ ),
49
+ (
50
+ "gpl-3.0",
51
+ [["gnu general public license"], ["version 3"]],
52
+ ),
53
+ (
54
+ "gpl-2.0",
55
+ [["gnu general public license"], ["version 2"]],
56
+ ),
57
+ (
58
+ "lgpl-3.0",
59
+ [["gnu lesser general public license"], ["version 3"]],
60
+ ),
61
+ (
62
+ "agpl-3.0",
63
+ [["gnu affero general public license"], ["version 3"]],
64
+ ),
65
+ (
66
+ "mpl-2.0",
67
+ [["mozilla public license"], ["version 2.0", "version 2,"]],
68
+ ),
69
+ (
70
+ "cc-by-4.0",
71
+ [
72
+ [
73
+ "creative commons attribution 4.0",
74
+ "cc by 4.0",
75
+ "cc-by-4.0",
76
+ "creativecommons.org/licenses/by/4.0",
77
+ ]
78
+ ],
79
+ ),
80
+ (
81
+ "cc0-1.0",
82
+ [
83
+ [
84
+ "cc0 1.0",
85
+ "creative commons zero",
86
+ "creativecommons.org/publicdomain/zero/1.0",
87
+ ]
88
+ ],
89
+ ),
90
+ (
91
+ "isc",
92
+ [
93
+ [
94
+ "isc license",
95
+ "permission to use, copy, modify, and/or distribute this "
96
+ "software",
97
+ ]
98
+ ],
99
+ ),
100
+ (
101
+ "unlicense",
102
+ [
103
+ [
104
+ "this is free and unencumbered software released into the "
105
+ "public domain"
106
+ ]
107
+ ],
108
+ ),
109
+ ]
110
+
111
+ # Candidate file names to search for a project license, in priority order.
112
+ LICENSE_FILE_CANDIDATES = [
113
+ "LICENSE",
114
+ "LICENSE.txt",
115
+ "LICENSE.md",
116
+ "LICENSE.rst",
117
+ "LICENCE",
118
+ "LICENCE.txt",
119
+ "LICENCE.md",
120
+ "COPYING",
121
+ ]
122
+
123
+
124
+ def detect_license_ids(text: str) -> list[str]:
125
+ """Detect SPDX license IDs present in license text.
126
+
127
+ The match is tolerant of whitespace and case, and a single body of text
128
+ can match multiple licenses (e.g., a dual-licensed project).
129
+ Returns the IDs in a deterministic order with duplicates removed.
130
+ """
131
+ if not text:
132
+ return []
133
+ # Lowercase and collapse all runs of whitespace so that line wrapping in
134
+ # the source license file does not break multi-word substring matches
135
+ normalized = re.sub(r"\s+", " ", text.lower())
136
+ found: list[str] = []
137
+ for license_id, groups in _LICENSE_MARKERS:
138
+ # The "bsd-3-clause" and "bsd-2-clause" markers overlap; only report
139
+ # the 2-clause variant when the 3-clause variant did not match
140
+ if license_id == "bsd-2-clause" and "bsd-3-clause" in found:
141
+ continue
142
+ if all(
143
+ any(substring in normalized for substring in group)
144
+ for group in groups
145
+ ):
146
+ found.append(license_id)
147
+ return found
148
+
149
+
150
+ def find_license_file(wdir: str | None = None) -> str | None:
151
+ """Return the path to the project license file, if one exists."""
152
+ for candidate in LICENSE_FILE_CANDIDATES:
153
+ path = candidate if wdir is None else os.path.join(wdir, candidate)
154
+ if os.path.isfile(path):
155
+ return path
156
+ return None
157
+
158
+
7
159
  LICENSE_TEMPLATE_DUAL = """
8
160
  This project is licensed under a dual-license structure to appropriately cover
9
161
  both the software code and the non-code content (data, text, figures, etc.).