-
Notifications
You must be signed in to change notification settings - Fork 34
Centralize Versioning #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,73 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| """A script to synchronize the version from _version.py to CITATION.cff.""" | ||
|
|
||
| import re | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # --- Configuration --------------------------------------------------- | ||
|
|
||
| # Append the parent directory (simopt package) to the system path | ||
| SIMOPT_PACKAGE_DIR = Path(__file__).resolve().parent.parent | ||
| sys.path.append(str(SIMOPT_PACKAGE_DIR)) | ||
|
|
||
| # Source directory containing the _version.py file | ||
| SIMOPT_DIR = SIMOPT_PACKAGE_DIR / "simopt" | ||
|
|
||
| # Source of the citation file | ||
| CITATION_FILENAME = "CITATION.cff" | ||
| CITATION_FILE: Path = SIMOPT_PACKAGE_DIR / CITATION_FILENAME | ||
|
|
||
| # Regex pattern to identify the version line in CITATION.cff | ||
|
|
||
| VERSION_PATTERN = re.compile(r"^(version:\s*).+$") | ||
|
|
||
| # --------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def main() -> None: | ||
| """Reads the version and updates the CITATION.cff file.""" | ||
| # --- Get the source version --- | ||
| from simopt._version import __version__ | ||
|
|
||
| # --- Read and update the CITATION.cff file --- | ||
| if not CITATION_FILE.exists(): | ||
| print(f"Error: File not found at {CITATION_FILE}") | ||
| sys.exit(1) | ||
|
|
||
| # We use 'str(__version__)' to handle non-string version types | ||
| # and add quotes to be safe YAML, especially for pre-release tags. | ||
| replacement_line = f'version: "{__version__!s}"' | ||
|
|
||
| print(f"Updating {CITATION_FILE}...") | ||
|
|
||
| new_lines = [] | ||
| found = False | ||
|
|
||
| with CITATION_FILE.open("r") as f: | ||
| for line in f: | ||
| # Check if the line matches our version pattern | ||
| if not found and VERSION_PATTERN.match(line): | ||
| # If it matches, replace it with our new line | ||
| new_lines.append(replacement_line + "\n") | ||
| found = True | ||
| print(f" - Replaced: {line.strip()}") | ||
| print(f" + With: {replacement_line}") | ||
| else: | ||
| # Otherwise, keep the line as-is | ||
| new_lines.append(line) | ||
|
|
||
| if not found: | ||
| print("Error: A 'version:' line was not found in the file.") | ||
| sys.exit(1) | ||
|
|
||
| # Write the modified content back to the file | ||
| with CITATION_FILE.open("w") as f: | ||
| f.writelines(new_lines) | ||
|
|
||
| print("Update complete.") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,4 @@ | ||
| """Init file for the simopt package.""" | ||
|
|
||
| # Make the version easily accessible to users | ||
| from simopt._version import __version__ # noqa: F401 |
This file contains hidden or 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 @@ | ||
| __version__ = "1.2.2.dev0" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.