Compare commits

...

3 Commits

15 changed files with 621 additions and 60 deletions

7
hooks/hook-pygount.py Normal file
View File

@ -0,0 +1,7 @@
from PyInstaller.utils.hooks import collect_all
# Collect all package data, binaries and hidden imports from pygount
datas, binaries, hiddenimports = collect_all('pygount')
# Export to PyInstaller
__all__ = ['datas', 'binaries', 'hiddenimports']

View File

@ -143,8 +143,8 @@
{
"name": "DSP",
"paths": [
"C:\\__temp\\Metrics\\attuale\\REP\\Projects\\DSP",
"C:\\__temp\\Metrics\\attuale\\REP\\Projects\\DspAlgorithms"
"C:\\src\\____GitProjects\\SXXXXXXX_PyUcc\\__UCC\\Metrics\\_25_11\\REP\\Projects\\DSP",
"C:\\src\\____GitProjects\\SXXXXXXX_PyUcc\\__UCC\\Metrics\\_25_11\\REP\\Projects\\DspAlgorithms"
],
"languages": [
"C",

23
pyucc.spec.bak Normal file
View File

@ -0,0 +1,23 @@
from PyInstaller.utils.hooks import collect_all
# Ensure pygount package contents are explicitly collected (datas, binaries, hiddenimports)
_pygount_datas, _pygount_binaries, _pygount_hiddenimports = collect_all('pygount')
block_cipher = None
a = Analysis(pathex=['pyucc', '.'], binaries=[], datas=[('PyUcc.ico', '.'), ('external\\python-tkinter-logger\\tkinter_logger.py', '.'), ('external\\python-resource-monitor\\resource_monitor.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger'), ('external\\_setup_paths.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger'), ('external\\_setup_paths.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger'), ('external\\_setup_paths.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger')], hiddenimports=['tkinter_logger', 'resource_monitor', 'pyucc.core.differ', 'pyucc.gui.gui', 'pyucc.config.settings', 'logging', 'logging.handlers', 'logging.config', 'ConfigParser', 'Cython', 'HTMLParser', 'IPython', 'OpenSSL', 'PIL', 'Queue', 'StringIO', 'android', 'annotationlib', 'argcomplete', 'attr', 'autocommand', 'backports', 'cgi', 'chardet', 'colorama', 'contextlib2', 'cryptography', 'ctags', 'distutils', 'dl', 'docutils', 'dummy_thread', 'dummy_threading', 'exceptiongroup', 'fcntl', 'filelock', 'future_builtins', 'git', 'gitdb', 'gitdb_speedups', 'google', 'grp', 'htmlentitydefs', 'httplib', 'importlib_metadata', 'importlib_resources', 'inflect', 'ini2toml', 'iniconfig', 'ipywidgets', 'jaraco', 'java', 'jinja2', 'jnius', 'keyring', 'linkify_it', 'lizard', 'lizard_ext', 'lizard_languages', 'markdown_it', 'mdurl', 'mock', 'mod', 'mod2', 'more_itertools', 'nspkg', 'ntlm', 'numpy', 'packaging', 'path', 'pathspec', 'pexpect', 'pip', 'pkg1', 'pkg_resources', 'platformdirs', 'pluggy', 'psutil', 'pwd', 'py', 'pygments', 'pygount', 'pytest', 'pyucc', 'pywintypes', 'readline', 'redis', 'resource', 'rich', 'setuptools', 'sha', 'smmap', 'socks', 'sphinx', 'target_simulator', 'thread', 'tomli', 'tomli_w', 'trove_classifiers', 'twisted', 'typeguard', 'typeshed', 'typing_extensions', 'urllib2', 'urllib3_secure_extra', 'urlparse', 'wheel', 'win32api', 'win32con', 'win32process', 'wmi', 'xmlrpclib', 'xx', 'zipp', 'zope', 'traitlets', 'gdb', 'matplotlib', 'PyInstaller'], hookspath=['hooks'], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False, scripts=['pyucc\\__main__.py'])
try:
a.hiddenimports += _pygount_hiddenimports
except Exception:
pass
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='PyUcc', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=False, icon='PyUcc.ico', exclude_binaries=True)
coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='PyUcc')
block_cipher = None
a = Analysis(pathex=['pyucc', '.'], binaries=[], datas=[('PyUcc.ico', '.'), ('external\\python-tkinter-logger\\tkinter_logger.py', '.'), ('external\\python-resource-monitor\\resource_monitor.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger'), ('external\\_setup_paths.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger'), ('external\\_setup_paths.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger'), ('external\\_setup_paths.py', '.'), ('external\\python-resource-monitor', 'python-resource-monitor'), ('external\\python-tkinter-logger', 'python-tkinter-logger')], hiddenimports=['tkinter_logger', 'resource_monitor', 'pyucc.core.differ', 'pyucc.gui.gui', 'pyucc.config.settings', 'logging', 'logging.handlers', 'logging.config', 'ConfigParser', 'Cython', 'HTMLParser', 'IPython', 'OpenSSL', 'PIL', 'Queue', 'StringIO', 'android', 'annotationlib', 'argcomplete', 'attr', 'autocommand', 'backports', 'cgi', 'chardet', 'colorama', 'contextlib2', 'cryptography', 'ctags', 'distutils', 'dl', 'docutils', 'dummy_thread', 'dummy_threading', 'exceptiongroup', 'fcntl', 'filelock', 'future_builtins', 'git', 'gitdb', 'gitdb_speedups', 'google', 'grp', 'htmlentitydefs', 'httplib', 'importlib_metadata', 'importlib_resources', 'inflect', 'ini2toml', 'iniconfig', 'ipywidgets', 'jaraco', 'java', 'jinja2', 'jnius', 'keyring', 'linkify_it', 'lizard', 'lizard_ext', 'lizard_languages', 'markdown_it', 'mdurl', 'mock', 'mod', 'mod2', 'more_itertools', 'nspkg', 'ntlm', 'numpy', 'packaging', 'path', 'pathspec', 'pexpect', 'pip', 'pkg1', 'pkg_resources', 'platformdirs', 'pluggy', 'psutil', 'pwd', 'py', 'pygments', 'pygount', 'pytest', 'pyucc', 'pywintypes', 'readline', 'redis', 'resource', 'rich', 'setuptools', 'sha', 'smmap', 'socks', 'sphinx', 'target_simulator', 'thread', 'tomli', 'tomli_w', 'trove_classifiers', 'twisted', 'typeguard', 'typeshed', 'typing_extensions', 'urllib2', 'urllib3_secure_extra', 'urlparse', 'wheel', 'win32api', 'win32con', 'win32process', 'wmi', 'xmlrpclib', 'xx', 'zipp', 'zope', 'traitlets', 'gdb', 'matplotlib', 'PyInstaller'], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False, scripts=['pyucc\\__main__.py'])
try:
a.hiddenimports += _pygount_hiddenimports
except Exception:
pass
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, [], name='PyUcc', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, upx_exclude=[], runtime_tmpdir=None, console=False, icon='PyUcc.ico', exclude_binaries=True)
coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='PyUcc')

View File

@ -145,6 +145,26 @@ def main():
args = parser.parse_args()
# Inform the user early if pygount is not available (affects comment counting)
try:
from pyucc.core import countings_impl
if not getattr(countings_impl, "_HAS_PYGOUNT", False):
print(
"WARNING: the 'pygount' package is not available. Comment counts and some extended metrics may not be available.",
file=sys.stderr,
)
print(
"To fix: activate the virtualenv used to run the app and run 'pip install pygount'",
file=sys.stderr,
)
print(
"If you ship a PyInstaller executable, rebuild it including 'pygount' (add a hook or hiddenimports).",
file=sys.stderr,
)
except Exception:
# Non-critical: continue execution
pass
# If user asked for GUI, or no positional directories were provided, launch GUI and exit
if args.gui or len(args.baseline_dirs or []) == 0:
try:

Binary file not shown.

View File

@ -6,10 +6,10 @@
import re
# --- Version Data (Generated) ---
__version__ = "v.0.0.0.20-0-g9538919-dirty"
GIT_COMMIT_HASH = "95389193747b356fc287b149371c64ad557fcb30"
__version__ = "v.0.0.0.23-0-gc67280d-dirty"
GIT_COMMIT_HASH = "c67280df44cb0db1bad3815a2938adc0904a10de"
GIT_BRANCH = "master"
BUILD_TIMESTAMP = "2025-12-12T09:15:00.613998+00:00"
BUILD_TIMESTAMP = "2025-12-15T09:32:07.391542+00:00"
IS_GIT_REPO = True
# --- Default Values (for comparison or fallback) ---

View File

@ -10,14 +10,90 @@ import subprocess
import logging
import threading
import hashlib
import os
import sys
import glob
try:
import pygount # type: ignore
_HAS_PYGOUNT = True
except Exception:
# Try to load a bundled pygount wheel (offline install) — useful for PyInstaller one-folder
_HAS_PYGOUNT = False
def _attempt_load_bundled_pygount() -> bool:
"""If a pygount wheel is bundled with the app (e.g. in _internal), add it to sys.path and try import.
Returns True if import succeeded.
"""
candidates = []
# If running frozen (PyInstaller), packaged data are extracted to sys._MEIPASS
base = getattr(sys, "_MEIPASS", None)
if base:
# search both at root of MEIPASS and recursively (some datas end up nested)
candidates.append(os.path.join(base, "pygount*.whl"))
candidates.append(os.path.join(base, "**", "pygount*.whl"))
candidates.append(os.path.join(base, "pygount", "**", "*.py"))
candidates.append(os.path.join(base, "**", "pygount", "**", "*.py"))
# Also look into a relative _internal folder in source tree
repo_internal = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "_internal"))
candidates.append(os.path.join(repo_internal, "pygount*.whl"))
candidates.append(os.path.join(repo_internal, "pygount", "**", "*.py"))
found_paths = []
for pattern in candidates:
try:
for p in glob.glob(pattern, recursive=True):
if p and p not in found_paths:
found_paths.append(p)
except Exception:
continue
# Prefer a wheel file if present (zipimport works for wheels)
wheel_paths = [p for p in found_paths if p.lower().endswith('.whl')]
if wheel_paths:
wheel = wheel_paths[0]
try:
if wheel not in sys.path:
sys.path.insert(0, wheel)
import pygount # type: ignore
return True
except Exception:
# remove added path if import failed
try:
if wheel in sys.path:
sys.path.remove(wheel)
except Exception:
pass
# If no wheel, try adding a plain package folder
pkg_dirs = [os.path.dirname(p) for p in found_paths if p.lower().endswith('.py')]
# remove duplicates
pkg_dirs = list(dict.fromkeys(pkg_dirs))
for d in pkg_dirs:
try:
if d not in sys.path:
sys.path.insert(0, d)
import pygount # type: ignore
return True
except Exception:
try:
if d in sys.path:
sys.path.remove(d)
except Exception:
pass
return False
try:
if _attempt_load_bundled_pygount():
_HAS_PYGOUNT = True
except Exception:
_HAS_PYGOUNT = False
_LOG = logging.getLogger(__name__)
# Cache to store counting results by file content hash ONLY

View File

@ -231,6 +231,44 @@ class App(tk.Tk):
except Exception:
pass
# Check if pygount is available and warn the user if not.
try:
from ..core import countings_impl
if not getattr(countings_impl, "_HAS_PYGOUNT", False):
msg = (
"""
The 'pygount' package is not available.
Comment counting and some extended metrics may not work correctly.
Possible fixes:
1) If you are using a development environment: activate the virtualenv and run 'pip install pygount'.
2) If you are using a PyInstaller-built executable: rebuild it including 'pygount' (hook or hiddenimports).
3) Quick check: run
python -c "from pyucc.core import countings_impl; print(countings_impl._HAS_PYGOUNT)"
"""
)
try:
messagebox.showwarning("Missing dependency: pygount", msg)
except Exception:
# If messagebox fails (headless), fallback to logging
pass
try:
self.log(
"pygount not available: comment counting and extended metrics disabled",
level="WARNING",
)
except Exception:
pass
try:
self.phase_var.set("Ready (pygount missing — limited functionality)")
except Exception:
pass
except Exception:
# ignore any unexpected error when checking for pygount
pass
# small helper: expose a convenient log method that forwards to
# the standard logging system so messages flow through the queue.
def log(self, msg: str, level: str = "INFO"):

View File

@ -62,6 +62,8 @@ class ProfileManager(tk.Toplevel):
self.title("Profile Manager")
self.geometry("1100x700")
self.on_change = on_change
# currently loaded profile dict (or None for new)
self._loaded_profile = None
self.profiles = profiles_cfg.load_profiles()
@ -97,7 +99,7 @@ class ProfileManager(tk.Toplevel):
self.ext_frame.grid(row=0, column=1, sticky="nsew")
# Paths listbox + scrollbar inside its frame
self.paths_listbox = tk.Listbox(self.paths_frame, height=12)
self.paths_listbox = tk.Listbox(self.paths_frame, height=12, exportselection=False)
self.paths_listbox.grid(row=0, column=0, sticky="nsew")
paths_vsb = ttk.Scrollbar(
self.paths_frame, orient="vertical", command=self.paths_listbox.yview
@ -141,7 +143,7 @@ class ProfileManager(tk.Toplevel):
).grid(row=1, column=1, padx=6, pady=4)
# Extensions listbox + scrollbar inside its frame
self.ext_listbox = tk.Listbox(self.ext_frame, selectmode="extended", height=12)
self.ext_listbox = tk.Listbox(self.ext_frame, selectmode="extended", height=12, exportselection=False)
self.ext_listbox.grid(row=0, column=0, sticky="nsew")
ext_vsb = ttk.Scrollbar(
self.ext_frame, orient="vertical", command=self.ext_listbox.yview
@ -215,10 +217,16 @@ class ProfileManager(tk.Toplevel):
ttk.Button(btn_frame, text="Delete", command=self._delete).grid(
row=0, column=3, padx=4
)
ttk.Button(btn_frame, text="Close", command=self.destroy).grid(
ttk.Button(btn_frame, text="Close", command=self._on_close).grid(
row=0, column=4, padx=4
)
# handle window close (X) the same way as Close button
try:
self.protocol("WM_DELETE_WINDOW", self._on_close)
except Exception:
pass
right.columnconfigure(1, weight=1)
# If no profiles exist, prefill form with sensible defaults (widgets are ready)
@ -247,36 +255,25 @@ class ProfileManager(tk.Toplevel):
if f:
self._insert_path_display("end", str(Path(f)))
def _populate_ext_listbox(self):
# Populate extension listbox with LANGUAGE_EXTENSIONS entries
try:
from ..config.languages import LANGUAGE_EXTENSIONS
except Exception:
return
self.ext_listbox.delete(0, "end")
keys = sorted(LANGUAGE_EXTENSIONS.keys(), key=lambda s: s.lower())
for k in keys:
exts = LANGUAGE_EXTENSIONS.get(k) or []
exts_label = f" ({', '.join(exts)})" if exts else ""
self.ext_listbox.insert("end", f"{k}{exts_label}")
def _insert_path_display(self, index, path_str: str):
# choose a prefix depending on whether path is dir/file/unknown
p = Path(path_str)
if p.exists():
prefix = "[D] " if p.is_dir() else "[F] "
else:
prefix = "[?] "
display = f"{prefix}{path_str}"
self.paths_listbox.insert(index, display)
def _clear_ext_selection(self):
self.ext_listbox.selection_clear(0, "end")
def _edit_selected_path(self):
sel = self.paths_listbox.curselection()
if not sel:
return
idx = sel[0]
current = self.paths_listbox.get(idx)
# strip prefix for editing
stripped = self._strip_display_prefix(current)
new = simpledialog.askstring(
"Edit Path", "Path:", initialvalue=stripped, parent=self
)
if new:
self.paths_listbox.delete(idx)
self._insert_path_display(idx, new)
def _strip_display_prefix(self, display_text: str) -> str:
# remove known prefixes like [D] , [F] , [?] if present
if (
display_text.startswith("[D] ")
or display_text.startswith("[F] ")
or display_text.startswith("[?] ")
):
return display_text[4:]
return display_text
def _remove_selected_path(self):
sel = list(self.paths_listbox.curselection())
@ -319,25 +316,107 @@ class ProfileManager(tk.Toplevel):
for i in [min(size - 1, x + 1) for x in sel]:
self.paths_listbox.selection_set(i)
def _insert_path_display(self, index, path_str: str):
# choose a prefix depending on whether path is dir/file/unknown
p = Path(path_str)
if p.exists():
prefix = "[D] " if p.is_dir() else "[F] "
else:
prefix = "[?] "
display = f"{prefix}{path_str}"
self.paths_listbox.insert(index, display)
def _populate_ext_listbox(self):
# Populate extension listbox with LANGUAGE_EXTENSIONS entries
try:
from ..config.languages import LANGUAGE_EXTENSIONS
except Exception:
return
self.ext_listbox.delete(0, "end")
keys = sorted(LANGUAGE_EXTENSIONS.keys(), key=lambda s: s.lower())
for k in keys:
exts = LANGUAGE_EXTENSIONS.get(k) or []
exts_label = f" ({', '.join(exts)})" if exts else ""
self.ext_listbox.insert("end", f"{k}{exts_label}")
def _strip_display_prefix(self, display_text: str) -> str:
# remove known prefixes like [D] , [F] , [?] if present
if (
display_text.startswith("[D] ")
or display_text.startswith("[F] ")
or display_text.startswith("[?] ")
):
return display_text[4:]
return display_text
def _clear_ext_selection(self):
self.ext_listbox.selection_clear(0, "end")
def _edit_selected_path(self):
sel = self.paths_listbox.curselection()
if not sel:
return
idx = sel[0]
current = self.paths_listbox.get(idx)
# strip prefix for editing
stripped = self._strip_display_prefix(current)
new = self._ask_edit_path(stripped)
if new:
self.paths_listbox.delete(idx)
self._insert_path_display(idx, new)
def _ask_edit_path(self, initial: str) -> str:
"""Open a small modal dialog with a larger entry widget for editing paths.
Returns the edited string, or None if cancelled.
"""
dlg = tk.Toplevel(self)
dlg.title("Edit Path")
dlg.transient(self)
dlg.grab_set()
frm = ttk.Frame(dlg)
frm.grid(row=0, column=0, padx=8, pady=8, sticky="nsew")
ttk.Label(frm, text="Path:").grid(row=0, column=0, columnspan=2, sticky="w")
val = tk.StringVar(value=initial)
entry = ttk.Entry(frm, textvariable=val, width=90)
entry.grid(row=1, column=0, sticky="ew", pady=(6, 0))
def _on_browse():
d = filedialog.askdirectory(parent=dlg)
if d:
val.set(str(Path(d)))
entry.focus_set()
entry.selection_range(0, 'end')
browse_btn = ttk.Button(frm, text="Browse...", command=_on_browse)
browse_btn.grid(row=1, column=1, padx=(6, 0), pady=(6, 0))
btns = ttk.Frame(frm)
btns.grid(row=2, column=0, columnspan=2, pady=(10, 0), sticky="e")
ok_pressed = {"ok": False}
def _on_ok():
ok_pressed["ok"] = True
try:
dlg.destroy()
except Exception:
pass
def _on_cancel():
try:
dlg.destroy()
except Exception:
pass
ttk.Button(btns, text="OK", command=_on_ok).grid(row=0, column=0, padx=6)
ttk.Button(btns, text="Cancel", command=_on_cancel).grid(row=0, column=1)
frm.columnconfigure(0, weight=1)
# center dialog above parent (ProfileManager)
try:
dlg.update_idletasks()
pwx = self.winfo_rootx()
pwy = self.winfo_rooty()
pww = self.winfo_width()
pwh = self.winfo_height()
dw = dlg.winfo_width()
dh = dlg.winfo_height()
cx = pwx + max(0, (pww - dw) // 2)
cy = pwy + max(0, (pwh - dh) // 2)
dlg.geometry(f"+{cx}+{cy}")
except Exception:
pass
entry.focus_set()
entry.selection_range(0, 'end')
self.wait_window(dlg)
if ok_pressed["ok"]:
return val.get().strip()
return None
def _get_paths_from_listbox(self) -> List[str]:
out = []
@ -356,6 +435,8 @@ class ProfileManager(tk.Toplevel):
def _load_profile(self, pr):
self.name_var.set(pr.get("name", ""))
# remember loaded profile so we can detect unsaved changes on close
self._loaded_profile = dict(pr)
# Load only new-style 'paths' list (no legacy compatibility)
self.paths_listbox.delete(0, "end")
paths = pr.get("paths") or []
@ -396,6 +477,8 @@ class ProfileManager(tk.Toplevel):
self.ignore_text.delete("1.0", "end")
# insert the DEFAULT_IGNORES joined by commas
self.ignore_text.insert("1.0", ",".join(self.DEFAULT_IGNORES))
# new form — no loaded profile
self._loaded_profile = None
def _apply_default_ignores(self):
"""Merge current ignore patterns with the DEFAULT_IGNORES and
@ -472,6 +555,11 @@ class ProfileManager(tk.Toplevel):
messagebox.showinfo("Saved", f"Profile '{name}' saved.")
if self.on_change:
self.on_change()
# mark this as the currently loaded profile
try:
self._loaded_profile = dict(profile)
except Exception:
self._loaded_profile = None
def _delete(self):
name = self.name_var.get().strip()
@ -487,3 +575,71 @@ class ProfileManager(tk.Toplevel):
self._new()
if self.on_change:
self.on_change()
self._loaded_profile = None
def _on_close(self):
"""Handle window close: if form differs from loaded profile, ask to save."""
# build current form representation
try:
cur_name = self.name_var.get().strip()
cur_paths = self._get_paths_from_listbox()
cur_langs = []
try:
sel = [self.ext_listbox.get(i) for i in self.ext_listbox.curselection()]
for s in sel:
lang_name = s.split(" (", 1)[0]
if lang_name and lang_name not in cur_langs:
cur_langs.append(lang_name)
except Exception:
pass
raw_custom = self.custom_text.get("1.0", "end").strip()
raw_custom = raw_custom.replace("\n", ",")
custom = [c.strip() for c in raw_custom.split(",") if c.strip()]
cur_langs.extend([c for c in custom if c])
raw_ignore = self.ignore_text.get("1.0", "end").strip()
raw_ignore = raw_ignore.replace("\n", ",")
cur_ignore = [s.strip() for s in raw_ignore.split(",") if s.strip()]
cur_profile = {
"name": cur_name,
"paths": cur_paths,
"languages": cur_langs,
"ignore": cur_ignore,
}
except Exception:
cur_profile = None
changed = False
if self._loaded_profile is None and any([v for v in (cur_name, cur_paths, cur_langs, cur_ignore) if v]):
changed = True
elif self._loaded_profile is not None and cur_profile is not None:
# compare simple dicts
# note: do not attempt deep-normalization beyond this
if (
self._loaded_profile.get("name") != cur_profile.get("name")
or self._loaded_profile.get("paths") != cur_profile.get("paths")
or self._loaded_profile.get("languages") != cur_profile.get("languages")
or self._loaded_profile.get("ignore") != cur_profile.get("ignore")
):
changed = True
if changed:
ans = messagebox.askyesnocancel(
"Unsaved Changes", "Save changes to profile before closing?"
)
# True => save, False => discard and close, None => cancel
if ans is None:
return
if ans:
try:
self._save()
except Exception:
# if save fails, don't close
return
try:
self.destroy()
except Exception:
try:
super().destroy()
except Exception:
pass

View File

@ -101,7 +101,26 @@ class TopBar(ttk.Frame):
def _open_manager(self):
def _refresh():
# remember current selection, reload profiles and restore selection
cur = self.profile_var.get()
self._load_profiles()
vals = list(self.profile_cb["values"]) if self.profile_cb["values"] else []
if cur and cur in vals:
# keep same selection and refresh derived UI
self.profile_var.set(cur)
self._on_profile_selected()
elif vals:
# if there is at least one profile, ensure UI reflects a valid selection
# keep existing selection if already set, otherwise pick first
if not self.profile_var.get():
self.profile_var.set(vals[0])
self._on_profile_selected()
else:
# no profiles available
self.profile_var.set("")
self.current_profile = None
self.path_var.set("")
self.project_type_var.set("-")
pm = ProfileManager(self.master, on_change=_refresh)
pm.grab_set()

View File

@ -316,8 +316,49 @@ def generate_differ_report(result, profile_config, baseline_id, output_path):
m = counts.get("modified", 0)
u = counts.get("unmodified", 0)
cd = pair.get("countings_delta") or {}
md = pair.get("metrics_delta") or {}
# Prefer explicit deltas computed by the differ, but if missing
# (e.g. added or deleted files where only one side exists) fall
# back to using the current or baseline values so the compact
# table shows meaningful numbers for new/deleted files.
cd = pair.get("countings_delta")
if cd is None:
cur_cnt = pair.get("current_countings") or {}
base_cnt = pair.get("baseline_countings") or {}
if cur_cnt and not base_cnt:
cd = {
"physical_lines": cur_cnt.get("physical_lines", 0),
"code_lines": cur_cnt.get("code_lines", 0),
"comment_lines": cur_cnt.get("comment_lines", 0),
"blank_lines": cur_cnt.get("blank_lines", 0),
}
elif base_cnt and not cur_cnt:
cd = {
"physical_lines": -base_cnt.get("physical_lines", 0),
"code_lines": -base_cnt.get("code_lines", 0),
"comment_lines": -base_cnt.get("comment_lines", 0),
"blank_lines": -base_cnt.get("blank_lines", 0),
}
else:
cd = {}
md = pair.get("metrics_delta")
if md is None:
cur_m = pair.get("current_metrics") or {}
base_m = pair.get("baseline_metrics") or {}
if cur_m and not base_m:
md = {
"func_count": cur_m.get("func_count", 0),
"avg_cc": cur_m.get("avg_cc", 0.0),
"mi": cur_m.get("mi", 0.0),
}
elif base_m and not cur_m:
md = {
"func_count": -base_m.get("func_count", 0),
"avg_cc": -base_m.get("avg_cc", 0.0),
"mi": -base_m.get("mi", 0.0),
}
else:
md = {}
def fmt_int(v):
try:

View File

@ -5,8 +5,14 @@
"duplicates": {
"threshold": 5.0,
"extensions": [
".py",
".pyw"
".inl",
".h",
".hh",
".c",
".cxx",
".hpp",
".cpp",
".cc"
],
"k": 25,
"window": 4

View File

@ -28,4 +28,8 @@
- [x] colorare la tabella
- [x] salvare il file delle diff in automatico
- [x] mettere le hint per spiegare i vari parametri cosa sono
- [x] ordinare le righe selezionando la colonna sia in ordine screscente che descrescente
- [x] ordinare le righe selezionando la colonna sia in ordine screscente che descrescente
- [x] aggiornare profilo percorso quando premo su salva
- [x] non perdere la selezione sulle estensioni quando modifico il profilo
- [x] verificare con dsp 10 e 11 le differenze con quelle di UCC intorno ai 70000 linee di codice 708 linee di codice modificato
- [x] verificare se i commenti vengo conteggiati oppure no, nei file c++, c, h ecc

162
tools/bundle_pygount.py Normal file
View File

@ -0,0 +1,162 @@
#!/usr/bin/env python3
"""Bundle pygount wheel into the project and update pyucc.spec.
Usage: run inside your project's virtualenv/checkout root:
python tools/bundle_pygount.py
What it does:
- Locates a local `pygount-*.whl` in the current Python environment (site-packages)
- Copies it to `pyucc/_internal/`
- Updates `pyucc.spec`, adding the wheel as a `datas` entry so PyInstaller bundles it
This enables the runtime fallback added in `pyucc.core.countings_impl` to import pygount
from a bundled wheel when running on an offline target.
"""
from __future__ import annotations
import os
import sys
import shutil
import glob
from pathlib import Path
import sysconfig
import site
import re
REPO_ROOT = Path(__file__).resolve().parents[1]
SPEC_PATH = REPO_ROOT / "pyucc.spec"
DEST_DIR = REPO_ROOT / "pyucc" / "_internal"
def find_local_pygount_wheel() -> Path | None:
"""Search common site-packages locations for pygount-*.whl and return first match."""
candidates = []
# Preferred: current environment's site-packages (sysconfig)
try:
purelib = sysconfig.get_paths().get("purelib")
if purelib:
candidates.append(Path(purelib))
except Exception:
pass
# site.getsitepackages() may return multiple dirs
try:
for p in site.getsitepackages():
candidates.append(Path(p))
except Exception:
pass
# Fallback: sys.path entries
for p in sys.path:
try:
candidates.append(Path(p))
except Exception:
continue
# Also check repository-local wheel folder and current working dir
try:
candidates.append(REPO_ROOT / "wheels")
except Exception:
pass
try:
candidates.append(Path.cwd())
except Exception:
pass
try:
candidates.append(DEST_DIR)
except Exception:
pass
seen = set()
for base in candidates:
if not base:
continue
base = base.resolve()
if str(base) in seen:
continue
seen.add(str(base))
pattern = str(base / "pygount-*.whl")
for f in glob.glob(pattern):
if f:
return Path(f).resolve()
return None
def copy_wheel_to_internal(wheel_path: Path) -> Path:
DEST_DIR.mkdir(parents=True, exist_ok=True)
dest = DEST_DIR / wheel_path.name
shutil.copy2(wheel_path, dest)
return dest
def patch_spec_add_datas(spec_path: Path, wheel_rel_path: str) -> bool:
"""Insert a datas tuple ('<wheel_rel_path>', '_internal') into all datas=[...] lists in the spec.
Returns True if file modified.
"""
text = spec_path.read_text(encoding="utf-8")
tuple_entry = f"('{wheel_rel_path}', '_internal'),"
if tuple_entry in text:
print("Spec already contains wheel datas entry; nothing to do.")
return False
# Find all occurrences of 'datas=[' and insert the tuple after the opening bracket
new_text = text
inserts = 0
idx = 0
while True:
m = re.search(r"\bdatas\s*=\s*\[", new_text[idx:])
if not m:
break
# m.start() relative to new_text[idx:]
start = idx + m.end()
# Insert after start
new_text = new_text[:start] + tuple_entry + new_text[start:]
inserts += 1
idx = start + len(tuple_entry)
if inserts:
backup = spec_path.with_suffix(spec_path.suffix + ".bak")
spec_path.replace(backup)
spec_path.write_text(new_text, encoding="utf-8")
print(f"Patched {spec_path} - inserted datas entry in {inserts} places (backup saved to {backup}).")
return True
print(r"No datas=\[...] occurrences found in spec; no changes made.")
return False
def main():
print(f"Repo root: {REPO_ROOT}")
wheel = find_local_pygount_wheel()
if not wheel:
print("Could not locate a local pygount wheel in this environment.")
print("Please download a pygount wheel (pygount-<ver>-py3-none-any.whl) into your environment or site-packages.")
sys.exit(2)
print(f"Found pygount wheel: {wheel}")
dest = copy_wheel_to_internal(wheel)
print(f"Copied wheel to: {dest}")
# wheel_rel_path relative to project root (use forward slashes)
wheel_rel = f"pyucc/_internal/{dest.name}"
if not SPEC_PATH.exists():
print(f"Spec file not found at {SPEC_PATH}; please run this script from project root.")
sys.exit(3)
changed = patch_spec_add_datas(SPEC_PATH, wheel_rel)
if changed:
print("Specification updated. Rebuild using: pyinstaller pyucc.spec")
else:
print("Specification unchanged.")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,9 @@
import sys, importlib
sys.path.insert(0, r'dist\\PyUcc')
from pyucc.core import countings_impl as c
print('HAS_PYGOUNT=', getattr(c, '_HAS_PYGOUNT', 'UNKNOWN'))
try:
m = importlib.import_module('pygount')
print('pygount import ok, version=', getattr(m, '__version__', '?'))
except Exception as e:
print('pygount import failed:', repr(e))