Skip to content

Commit

Permalink
Show used libs (#767)
Browse files Browse the repository at this point in the history
* feat: lib versions

* feat: show version in an About dialog

* feat: simplify version handling

* feat: embed libs metadata

* feat: print version to the debug logs
  • Loading branch information
redrathnure authored Jan 21, 2025
1 parent 1d54d74 commit 80e20df
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion build-macos-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pip install PyInstaller==6.11.0

python3 setup.py -V

pyinstaller --onedir -p src -n NanoVNASaver nanovna-saver.py --window --clean -y -i icon_48x48.icns
pyinstaller --onedir -p src -n NanoVNASaver nanovna-saver.py --recursive-copy-metadata NanoVNASaver --window --clean -y -i icon_48x48.icns --add-data "icon_48x48.png:." --recursive-copy-metadata NanoVNASaver
tar -C dist -zcf ./dist/NanoVNASaver.app-`uname -m`.tar.gz NanoVNASaver.app

deactivate
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ where = ["src"]
# check out https://github.com/pypa/setuptools_scm
root='.'
version_scheme = 'no-guess-dev'
write_to = 'src/NanoVNASaver/_version.py'



Expand All @@ -104,9 +103,9 @@ clean_py = "python -Bc \"import pathlib; [p.unlink() for p in pathlib.Path('.').
clean_logs = "python -Bc \"import pathlib; [p.unlink() for p in pathlib.Path('.').rglob('*.log')]\""
clean_pycache = " python -Bc \"import pathlib; [p.rmdir() for p in pathlib.Path('.').rglob('__pycache__')]\""

build-pkg-win = "pyinstaller --onefile -p src -n nanovna-saver.exe nanovna-saver.py --noconsole -i icon_48x48.ico --add-data \"icon_48x48.png:.\""
build-pkg-linux = "pyinstaller --onefile -p src -n nanovna-saver nanovna-saver.py --add-data \"icon_48x48.png:.\""
build-pkg-macos = "pyinstaller --onedir -p src -n NanoVNASaver nanovna-saver.py --window --clean -y -i icon_48x48.icns --add-data \"icon_48x48.png:.\" && tar -C dist -zcf ./dist/NanoVNASaver.app-`uname -m`.tar.gz NanoVNASaver.app"
build-pkg-win = "pyinstaller --onefile -p src -n nanovna-saver.exe nanovna-saver.py --recursive-copy-metadata NanoVNASaver --noconsole -i icon_48x48.ico --add-data \"icon_48x48.png:.\""
build-pkg-linux = "pyinstaller --onefile -p src -n nanovna-saver nanovna-saver.py --recursive-copy-metadata NanoVNASaver --add-data \"icon_48x48.png:.\""
build-pkg-macos = "pyinstaller --onedir -p src -n NanoVNASaver nanovna-saver.py --recursive-copy-metadata NanoVNASaver --window --clean -y -i icon_48x48.icns --add-data \"icon_48x48.png:.\" && tar -C dist -zcf ./dist/NanoVNASaver.app-`uname -m`.tar.gz NanoVNASaver.app"



Expand Down
7 changes: 3 additions & 4 deletions src/NanoVNASaver/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

from .app_version import APP_VERSION
from .utils import get_app_version


VERSION = APP_VERSION
VERSION = get_app_version()
INFO_URL = "https://github.com/NanoVNA-Saver/nanovna-saver"
INFO = f"""NanoVNASaver {APP_VERSION}
INFO = f"""NanoVNASaver {VERSION}
Copyright (C) 2019, 2020 Rune B. Broberg
Copyright (C) 2020ff NanoVNA-Saver Authors
Expand Down
9 changes: 8 additions & 1 deletion src/NanoVNASaver/Windows/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from NanoVNASaver.About import INFO_URL, LATEST_URL, TAGS_KEY, TAGS_URL
from NanoVNASaver.Windows.Defaults import make_scrollable

from ..utils import Version
from ..utils import Version, get_lib_versions

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -109,6 +109,13 @@ def __init__(self, app: QtWidgets.QWidget):
)
lower_layout.addWidget(self.versionLabel)

self.libs_title = QtWidgets.QLabel("Used libs:")
lower_layout.addWidget(self.libs_title)
self.libs_list = QtWidgets.QTextEdit()
self.libs_list.setReadOnly(True)
self.libs_list.setText("\n".join(get_lib_versions()))
lower_layout.addWidget(self.libs_list)

lower_layout.addStretch()

btn_ok = QtWidgets.QPushButton("Ok")
Expand Down
6 changes: 6 additions & 0 deletions src/NanoVNASaver/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from PyQt6 import QtWidgets

from NanoVNASaver.About import INFO, VERSION
from NanoVNASaver.utils import get_lib_versions
from NanoVNASaver.NanoVNASaver import NanoVNASaver
from NanoVNASaver.Touchstone import Touchstone

Expand Down Expand Up @@ -92,6 +93,11 @@ def main():
fh.setFormatter(formatter)
logger.addHandler(fh)

# Print diagnostic data
logger.debug("Used packages:")
for lib in get_lib_versions():
logger.debug(" - %s", lib)

logger.info("Startup...")

app = QtWidgets.QApplication(sys.argv)
Expand Down
11 changes: 0 additions & 11 deletions src/NanoVNASaver/app_version.py

This file was deleted.

3 changes: 2 additions & 1 deletion src/NanoVNASaver/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .app_versions import get_app_version, get_lib_versions
from .version import Version

__all__ = ["Version"]
__all__ = ["Version", "get_lib_versions", "get_app_version"]
17 changes: 17 additions & 0 deletions src/NanoVNASaver/utils/app_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

from functools import cache
from importlib.metadata import PackageNotFoundError, distributions, version

UNKNOWN_VERSION = "unknown"

@cache
def get_app_version() -> str:
try:
# Change here if project is renamed and does not equal the package name
return version("NanoVNASaver")
except PackageNotFoundError: # pragma: no cover
return UNKNOWN_VERSION

@cache
def get_lib_versions() -> list[str]:
return [f"{dist.name}: {dist.version}" for dist in distributions()]
16 changes: 16 additions & 0 deletions tests/utils/test_app_versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


from NanoVNASaver.utils import get_app_version, get_lib_versions


def test_get_app_version() -> None:
result = get_app_version()

assert result
assert result != "unknown"

def test_get_lib_versions() -> None:
result1 = get_lib_versions()

# at least 2xQt, numpy, scipy and NanoVNASaver itself
assert len(result1) > 6 # noqa: PLR2004

0 comments on commit 80e20df

Please sign in to comment.