-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MAINT] convert several maintenance scripts to python (#1268)
* use python instead of bash * ref * use python instead of bash * update make file
- Loading branch information
Showing
13 changed files
with
181 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import re | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from update_versions_bug_report import main as update_bug_report | ||
|
||
from utils import root_dir | ||
|
||
|
||
def read_version_from_citation() -> str: | ||
with open(root_dir() / "CITATION.cff", encoding="utf-8") as file: | ||
for line in file: | ||
if line.startswith("version:"): | ||
version = line.strip().replace("version: ", "v") | ||
with open( | ||
root_dir() / "version.txt", "w", encoding="utf-8" | ||
) as version_file: | ||
version_file.write(version) | ||
return version[1:] # Remove the leading 'v' | ||
|
||
|
||
def update_file(file_path, pattern, replacement): | ||
file_path = Path(file_path) | ||
content = file_path.read_text(encoding="utf-8") | ||
new_content = re.sub(pattern, replacement, content) | ||
file_path.write_text(new_content, encoding="utf-8") | ||
|
||
|
||
def main(): | ||
version = read_version_from_citation() | ||
|
||
if not version: | ||
print("Version not found in CITATION.cff") | ||
return | ||
|
||
update_file("README.md", r"version = {.*}", f"version = {{{version}}}") | ||
update_file("README.md", r"__version__ = .*", f"version = {{{version}}}") | ||
update_file( | ||
"src/reports/bidspm.bib", r" version = {.*}", f" version = {{{version}}}" | ||
) | ||
|
||
tools_dir = Path("tools") | ||
|
||
versions_txt_path = tools_dir / "versions.txt" | ||
versions = ( | ||
subprocess.run(["git", "tag", "--list"], capture_output=True, text=True) | ||
.stdout.strip() | ||
.split("\n")[::-1] | ||
) | ||
versions_txt_path.write_text("\n".join(versions), encoding="utf-8") | ||
|
||
update_bug_report() | ||
|
||
print(f"Version updated to {version}") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Update CITATION.cff file.""" | ||
|
||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import Any | ||
|
||
import ruamel.yaml | ||
|
||
from utils import root_dir | ||
|
||
yaml = ruamel.yaml.YAML() | ||
yaml.indent(mapping=2, sequence=4, offset=2) | ||
|
||
|
||
def citation_file() -> Path: | ||
"""Return path to CITATIONS.cff file.""" | ||
return root_dir() / "CITATION.cff" | ||
|
||
|
||
def read_citation_cff() -> dict[str, Any]: | ||
"""Read CITATION.cff file.""" | ||
print(f"Reading file: {citation_file()}") | ||
with open(citation_file(), encoding="utf8") as f: | ||
citation = yaml.load(f) | ||
return citation | ||
|
||
|
||
def write_citation_cff(citation: dict[str, Any]) -> None: | ||
"""Write CITATION.cff file.""" | ||
print(f"Writing file: {citation_file()}") | ||
with open(citation_file(), "w", encoding="utf8") as f: | ||
yaml.dump(citation, f) | ||
|
||
|
||
def sort_authors(authors: list[dict[str, str]]) -> list[dict[str, str]]: | ||
"""Sort authors by given name.""" | ||
print(" Sorting authors by given name") | ||
authors.sort(key=lambda x: x["given-names"]) | ||
return authors | ||
|
||
|
||
def main() -> None: | ||
"""Update names.rst and AUTHORS.rst files.""" | ||
citation = read_citation_cff() | ||
citation["authors"] = sort_authors(citation["authors"]) | ||
write_citation_cff(citation) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Print functions that are called less than twice in the code base.""" | ||
|
||
from pathlib import Path | ||
|
||
from rich import print | ||
|
||
from utils import root_dir | ||
|
||
|
||
def find_files_with_extension(directory, extension) -> list[Path]: | ||
"""Recursively find all files in directory with the given extension.""" | ||
return list(Path(directory).rglob(f"*{extension}")) | ||
|
||
|
||
def main() -> None: | ||
src_folder = root_dir() / "src" | ||
files = find_files_with_extension(src_folder, ".m") | ||
|
||
for file in files: | ||
function = file.stem | ||
|
||
occurrences = [] | ||
for other_file in files: | ||
with open(other_file, encoding="utf-8") as f: | ||
content = f.read() | ||
if function in content: | ||
occurrences.append(f"{other_file}:{content.find(function)}") | ||
|
||
nb_lines = len(occurrences) | ||
|
||
if nb_lines < 2: | ||
print( | ||
"\n---------------------------------------------------------------------" | ||
) | ||
print(function) | ||
print() | ||
for line in occurrences: | ||
print(line) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
|
||
def root_dir() -> Path: | ||
"""Return path to root directory.""" | ||
return Path(__file__).parent.parent |