From 21ba0ef6651ce949e52d6d5d5766a24016210883 Mon Sep 17 00:00:00 2001 From: Name Date: Mon, 17 Jul 2023 14:21:16 +0200 Subject: [PATCH] Simplify the in-source launcher script (#660) The nanovna-saver.py script is ignored by setup.cfg, its only purpose is to test the version in the source directory. According to https://setuptools.pypa.io/en/latest/history.html, pkg_resources.py2warn has been removed from setuptools in 2020 --- nanovna-saver.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/nanovna-saver.py b/nanovna-saver.py index 3445c4f..ee4a537 100755 --- a/nanovna-saver.py +++ b/nanovna-saver.py @@ -16,23 +16,23 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from contextlib import suppress -import os +# This launcher is ignored by setuptools. Its only purpose is direct +# execution from a source tree. -# noinspection PyUnresolvedReferences -with suppress(ImportError): - # pylint: disable=no-name-in-module,import-error,unused-import - # pyright: reportMissingImports=false - import pkg_resources.py2_warn +import os.path +import sys -try: - from NanoVNASaver.__main__ import main -except ModuleNotFoundError: - import sys +# Ignore the current working directory. +src = os.path.join(os.path.dirname(__file__), "src") - sys.path.append(os.path.join(os.path.dirname(__file__), "src")) - from NanoVNASaver.__main__ import main +# Ignore previously installed versions. +sys.path.insert(0, src) +assert os.path.exists(src) +# pylint: disable-next=wrong-import-position +import NanoVNASaver.__main__ -if __name__ == "__main__": - main() +# The traditional test does not make sense here. +assert __name__ == '__main__' + +NanoVNASaver.__main__.main()