add version

This commit is contained in:
VALLONGOL 2025-05-06 09:33:33 +02:00
parent 6f1a5bf8df
commit 5558a49ab9
3 changed files with 91 additions and 77 deletions

3
.gitignore vendored
View File

@ -1,5 +1,4 @@
.svn .svn
_dist/ _dist/
_build/ _build/
__pycache__/ __pycache__/
_version.py

View File

@ -1,75 +0,0 @@
# -*- coding: utf-8 -*-
"""
Main entry point script for the PyInstaller GUI Wrapper application.
This script imports the main GUI class and starts the Tkinter event loop.
Run this file to launch the application.
"""
import sys
import os
import traceback # Import traceback for better error reporting
# --- Crucial: Add the directory containing the modules to sys.path ---
# This allows Python to find 'gui.py', 'config.py', etc. when run directly.
script_dir = os.path.dirname(os.path.abspath(__file__))
print(f"Adding to sys.path: {script_dir}") # Debug print
if script_dir not in sys.path:
sys.path.insert(0, script_dir)
# --- Import the necessary modules ---
# Use direct imports now that the path is set
try:
# Import the main GUI class directly by name
from gui import PyInstallerGUI
# We might need other modules here later if needed at top level
# import config
# import builder
# import spec_parser
except ImportError as e:
print(f"ERROR: Could not import required modules.")
print(f"ImportError: {e}")
print(f"Current sys.path: {sys.path}")
traceback.print_exc() # Print detailed traceback
sys.exit(1)
except Exception as e:
print(f"ERROR: An unexpected error occurred during initial imports: {e}")
traceback.print_exc()
sys.exit(1)
def main():
"""
Initializes and runs the PyInstaller GUI application.
"""
try:
app = PyInstallerGUI()
app.mainloop()
except Exception as e:
print(
f"FATAL ERROR: An unexpected error occurred during application execution: {e}"
)
traceback.print_exc()
try:
# Attempt to show a Tkinter error box if possible
import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
root.withdraw()
messagebox.showerror(
"Fatal Error",
f"Application failed to run:\n{e}\n\nSee console for details.",
)
root.destroy()
except Exception:
pass # Ignore if Tkinter fails here too
sys.exit(1)
# --- Main Execution Guard ---
if __name__ == "__main__":
# Check Python version if needed (Tkinter themes benefit from newer versions)
# print(f"Running with Python {sys.version}")
main()

View File

@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
# File generated by PyInstaller GUI Wrapper. DO NOT EDIT MANUALLY.
# Contains build-time information scraped from Git (if available)
# and a helper function to format version strings.
import re
# --- Version Data (Generated) ---
# This section is automatically generated by the build process.
__version__ = "v.0.0.0.2-dirty"
GIT_COMMIT_HASH = "31e2d9a72daad459abdecea5f5a443cb2f5060a2"
GIT_BRANCH = "master"
BUILD_TIMESTAMP = "2025-05-05T13:42:38Z"
IS_GIT_REPO = True
# --- Default Values (for comparison or fallback) ---
DEFAULT_VERSION = "0.0.0+unknown"
DEFAULT_COMMIT = "Unknown"
DEFAULT_BRANCH = "Unknown"
# --- Helper Function ---
def get_version_string(format_string=None):
"""
Returns a formatted string based on the build version information.
Args:
format_string (str, optional): A format string using placeholders.
Defaults to "{{version}} ({{branch}}/{{commit_short}})" if None.
Placeholders:
{{version}}: Full version string (e.g., 'v1.0.0-5-gabcdef-dirty')
{{tag}}: Clean tag part if exists (e.g., 'v1.0.0'), else DEFAULT_VERSION.
{{commit}}: Full Git commit hash.
{{commit_short}}: Short Git commit hash (7 chars).
{{branch}}: Git branch name.
{{dirty}}: '-dirty' if the repo was dirty, empty otherwise.
{{timestamp}}: Full build timestamp (ISO 8601 UTC).
{{timestamp_short}}: Build date only (YYYY-MM-DD).
{{is_git}}: 'Git' if IS_GIT_REPO is True, 'Unknown' otherwise.
Returns:
str: The formatted version string, or an error message if formatting fails.
"""
if format_string is None:
format_string = "{version} ({branch}/{commit_short})" # Sensible default
replacements = {}
try:
# Prepare data dictionary for substitution
replacements['version'] = __version__ if __version__ else DEFAULT_VERSION
replacements['commit'] = GIT_COMMIT_HASH if GIT_COMMIT_HASH else DEFAULT_COMMIT
replacements['commit_short'] = GIT_COMMIT_HASH[:7] if GIT_COMMIT_HASH and len(GIT_COMMIT_HASH) >= 7 else DEFAULT_COMMIT
replacements['branch'] = GIT_BRANCH if GIT_BRANCH else DEFAULT_BRANCH
replacements['timestamp'] = BUILD_TIMESTAMP if BUILD_TIMESTAMP else "Unknown"
replacements['timestamp_short'] = BUILD_TIMESTAMP.split('T')[0] if BUILD_TIMESTAMP and 'T' in BUILD_TIMESTAMP else "Unknown"
replacements['is_git'] = "Git" if IS_GIT_REPO else "Unknown"
replacements['dirty'] = "-dirty" if __version__ and __version__.endswith('-dirty') else ""
# Extract clean tag using regex (handles versions like v1.0.0, 1.0.0)
tag = DEFAULT_VERSION
if __version__ and IS_GIT_REPO:
# Match optional 'v' prefix, then major.minor.patch
match = re.match(r'^(v?([0-9]+)\.([0-9]+)\.([0-9]+))', __version__)
if match:
tag = match.group(1) # Get the full tag (e.g., 'v1.0.0')
replacements['tag'] = tag
# Perform substitution using regex to find placeholders {placeholder}
output_string = format_string
# Iterate through placeholders and replace them in the format string
for placeholder, value in replacements.items():
# Compile regex pattern for {placeholder}, allowing for whitespace inside braces
pattern = re.compile(r'{\s*' + re.escape(placeholder) + r'\s*}')
# Substitute found patterns with the corresponding string value
output_string = pattern.sub(str(value), output_string)
# Optional: Check if any placeholders remain unsubstituted (could indicate typo)
if re.search(r'{\s*[\w_]+\s*}', output_string):
# You might want to log this or handle it, for now, we return the string as is
# print(f"Warning: Unsubstituted placeholders remain in version string: {output_string}")
pass
return output_string
except Exception as e:
# Return a simple error message in case of unexpected formatting issues
# Avoid printing directly from this generated function
return f"[Formatting Error: {e}]"