Skip to content

Commit e7c531d

Browse files
authored
Merge pull request nexpy#258 from rayosborn:update-copyright-dates
Update copyright dates
2 parents 7008566 + bb406aa commit e7c531d

17 files changed

Lines changed: 105 additions & 14 deletions

File tree

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ repos:
44
hooks:
55
- id: ruff-check
66
args: [--fix]
7+
8+
- repo: local
9+
hooks:
10+
- id: update-copyright
11+
name: Update Copyright Year
12+
entry: python scripts/update_copyright.py
13+
language: python
14+
files: \.py$
15+
pass_filenames: true

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ version_file = "src/nexusformat/_version.py"
6868
"nexusformat.notebooks" = ["*.pnyb"]
6969

7070
[tool.ruff]
71-
line-length = 88
71+
line-length = 80
7272
target-version = "py39"
7373
exclude = ["src/nexusformat/notebooks"]
7474

scripts/sync_copyright.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import re
2+
import sys
3+
import subprocess
4+
5+
CLEANUP_REGEX = re.compile(r"(#\s*Copyright\s*\(c\)\s*)([^,]+)(,.*)")
6+
7+
def get_git_years(filepath):
8+
try:
9+
cmd = ["git", "log", "--follow", "--format=%ad", "--date=format:%Y",
10+
"--", filepath]
11+
output = subprocess.check_output(
12+
cmd, stderr=subprocess.STDOUT).decode('utf-8').strip()
13+
if not output:
14+
return None, None
15+
16+
history = output.splitlines()
17+
return str(history[-1]), str(history[0])
18+
except Exception:
19+
return None, None
20+
21+
def sync_file(filepath):
22+
first, last = get_git_years(filepath)
23+
if not first:
24+
return
25+
26+
with open(filepath, 'r', encoding='utf-8') as f:
27+
lines = f.readlines()
28+
29+
new_lines = []
30+
for line in lines:
31+
match = CLEANUP_REGEX.search(line)
32+
if match:
33+
prefix = match.group(1)
34+
suffix = match.group(3)
35+
36+
date_part = f"{first}-{last}" if first != last else f"{first}"
37+
new_line = f"{prefix}{date_part}{suffix}\n"
38+
new_lines.append(new_line)
39+
else:
40+
new_lines.append(line)
41+
42+
with open(filepath, 'w', encoding='utf-8') as f:
43+
f.writelines(new_lines)
44+
print(f"Cleaned and Synced: {filepath} ({first}-{last})")
45+
46+
if __name__ == "__main__":
47+
for arg in sys.argv[1:]:
48+
sync_file(arg)

scripts/update_copyright.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import re
2+
import sys
3+
from datetime import datetime
4+
5+
# Current year
6+
CURRENT_YEAR = str(datetime.now().year)
7+
COPYRIGHT_REGEX = re.compile(r"(#\s*Copyright\s*\(c\)\s*)(\d{4})(-\d{4})?(.*)")
8+
9+
def update_file(filepath):
10+
with open(filepath, 'r', encoding='utf-8') as f:
11+
content = f.read()
12+
13+
def replace_year(match):
14+
prefix = match.group(1)
15+
start_year = match.group(2)
16+
suffix = match.group(4)
17+
18+
if start_year == CURRENT_YEAR:
19+
return f"{prefix}{start_year}{suffix}"
20+
21+
return f"{prefix}{start_year}-{CURRENT_YEAR}{suffix}"
22+
23+
new_content = COPYRIGHT_REGEX.sub(replace_year, content)
24+
25+
if new_content != content:
26+
with open(filepath, 'w', encoding='utf-8') as f:
27+
f.write(new_content)
28+
return True
29+
return False
30+
31+
if __name__ == "__main__":
32+
for arg in sys.argv[1:]:
33+
update_file(arg)

src/nexusformat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2013-2021, NeXpy Development Team.
2+
# Copyright (c) 2014-2026, NeXpy Development Team.
33
#
44
# Distributed under the terms of the Modified BSD License.
55
#

src/nexusformat/definitions/applications/stress/gauge_volume.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
ax.add_collection3d(
3939
Poly3DCollection(
40-
faces, facecolors="lightblue", linewidths=1.5, edgecolors="black", alpha=0.1
40+
faces, facecolors="lightblue", linewidths=1.5, edgecolors="black",
41+
alpha=0.1
4142
)
4243
)
4344

src/nexusformat/nexus/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2013-2021, NeXpy Development Team.
2+
# Copyright (c) 2014-2026, NeXpy Development Team.
33
#
44
# Author: Paul Kienzle, Ray Osborn
55
#

src/nexusformat/nexus/completer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2019-2021, NeXpy Development Team.
2+
# Copyright (c) 2019-2025, NeXpy Development Team.
33
#
44
# Author: Paul Kienzle, Ray Osborn
55
#

src/nexusformat/nexus/lock.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2019-2021, NeXpy Development Team.
2+
# Copyright (c) 2019-2022, NeXpy Development Team.
33
#
44
# Author: Paul Kienzle, Ray Osborn
55
#

src/nexusformat/nexus/plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2013-2025, NeXpy Development Team.
2+
# Copyright (c) 2014-2026, NeXpy Development Team.
33
#
44
# Author: Paul Kienzle, Ray Osborn
55
#

0 commit comments

Comments
 (0)