From 396a4c9816e0f9c7481fb38a49df70c386ec12bd Mon Sep 17 00:00:00 2001 From: Psynosaur Date: Wed, 4 Sep 2019 18:12:38 +0200 Subject: [PATCH] Prep for pip packaging - Moved files into project folder named "NanoVNASaver" - Added requirements --- Calibration.py => NanoVNASaver/Calibration.py | 3 +- Chart.py => NanoVNASaver/Chart.py | 2 +- LogMagChart.py => NanoVNASaver/LogMagChart.py | 4 +- Marker.py => NanoVNASaver/Marker.py | 2 +- .../NanoVNASaver.py | 14 ++--- SmithChart.py => NanoVNASaver/SmithChart.py | 4 +- SweepWorker.py => NanoVNASaver/SweepWorker.py | 9 +-- Touchstone.py => NanoVNASaver/Touchstone.py | 7 ++- NanoVNASaver/__init__.py | 0 nanovna-saver.py => NanoVNASaver/__main__.py | 9 ++- README.md | 14 +++++ setup.cfg | 2 + setup.py | 55 +++++++++++++++++++ 13 files changed, 102 insertions(+), 23 deletions(-) rename Calibration.py => NanoVNASaver/Calibration.py (99%) rename Chart.py => NanoVNASaver/Chart.py (98%) rename LogMagChart.py => NanoVNASaver/LogMagChart.py (99%) rename Marker.py => NanoVNASaver/Marker.py (98%) rename NanoVNASaver.py => NanoVNASaver/NanoVNASaver.py (99%) rename SmithChart.py => NanoVNASaver/SmithChart.py (99%) rename SweepWorker.py => NanoVNASaver/SweepWorker.py (92%) rename Touchstone.py => NanoVNASaver/Touchstone.py (96%) create mode 100644 NanoVNASaver/__init__.py rename nanovna-saver.py => NanoVNASaver/__main__.py (95%) create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/Calibration.py b/NanoVNASaver/Calibration.py similarity index 99% rename from Calibration.py rename to NanoVNASaver/Calibration.py index 9477aa8..d7e07eb 100644 --- a/Calibration.py +++ b/NanoVNASaver/Calibration.py @@ -13,6 +13,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . + import collections from PyQt5 import QtWidgets from typing import List @@ -25,7 +26,7 @@ class CalibrationWindow(QtWidgets.QWidget): def __init__(self, app): super().__init__() - from NanoVNASaver import NanoVNASaver + from .NanoVNASaver import NanoVNASaver self.app: NanoVNASaver = app diff --git a/Chart.py b/NanoVNASaver/Chart.py similarity index 98% rename from Chart.py rename to NanoVNASaver/Chart.py index 8ae9adf..96c314b 100644 --- a/Chart.py +++ b/NanoVNASaver/Chart.py @@ -18,7 +18,7 @@ from typing import List from PyQt5 import QtWidgets, QtGui, QtCore -from Marker import Marker +from .Marker import Marker Datapoint = collections.namedtuple('Datapoint', 'freq re im') diff --git a/LogMagChart.py b/NanoVNASaver/LogMagChart.py similarity index 99% rename from LogMagChart.py rename to NanoVNASaver/LogMagChart.py index 4022cec..827d7cf 100644 --- a/LogMagChart.py +++ b/NanoVNASaver/LogMagChart.py @@ -32,8 +32,8 @@ from typing import List from PyQt5 import QtWidgets, QtGui, QtCore -from Chart import Chart -from Marker import Marker +from .Chart import Chart +from .Marker import Marker Datapoint = collections.namedtuple('Datapoint', 'freq re im') diff --git a/Marker.py b/NanoVNASaver/Marker.py similarity index 98% rename from Marker.py rename to NanoVNASaver/Marker.py index ef2cd87..65a5aec 100644 --- a/Marker.py +++ b/NanoVNASaver/Marker.py @@ -50,7 +50,7 @@ class Marker(QtCore.QObject): self.layout.addWidget(self.btnColorPicker) def setFrequency(self, frequency): - from NanoVNASaver import NanoVNASaver + from .NanoVNASaver import NanoVNASaver f = NanoVNASaver.parseFrequency(frequency) if f > 0: self.frequency = f diff --git a/NanoVNASaver.py b/NanoVNASaver/NanoVNASaver.py similarity index 99% rename from NanoVNASaver.py rename to NanoVNASaver/NanoVNASaver.py index 2ad393d..d5c9707 100644 --- a/NanoVNASaver.py +++ b/NanoVNASaver/NanoVNASaver.py @@ -24,13 +24,13 @@ import serial from PyQt5 import QtWidgets, QtCore, QtGui from serial.tools import list_ports -import Chart -from Calibration import CalibrationWindow, Calibration -from Marker import Marker -from SmithChart import SmithChart -from SweepWorker import SweepWorker -from LogMagChart import LogMagChart -from Touchstone import Touchstone +from .Chart import Chart +from .Calibration import CalibrationWindow, Calibration +from .Marker import Marker +from .SmithChart import SmithChart +from .SweepWorker import SweepWorker +from .LogMagChart import LogMagChart +from .Touchstone import Touchstone Datapoint = collections.namedtuple('Datapoint', 'freq re im') diff --git a/SmithChart.py b/NanoVNASaver/SmithChart.py similarity index 99% rename from SmithChart.py rename to NanoVNASaver/SmithChart.py index cdb473f..2301219 100644 --- a/SmithChart.py +++ b/NanoVNASaver/SmithChart.py @@ -18,8 +18,8 @@ from typing import List from PyQt5 import QtWidgets, QtGui, QtCore -from Chart import Chart -from Marker import Marker +from .Chart import Chart +from .Marker import Marker Datapoint = collections.namedtuple('Datapoint', 'freq re im') diff --git a/SweepWorker.py b/NanoVNASaver/SweepWorker.py similarity index 92% rename from SweepWorker.py rename to NanoVNASaver/SweepWorker.py index 0a0356c..6915ac9 100644 --- a/SweepWorker.py +++ b/NanoVNASaver/SweepWorker.py @@ -43,6 +43,7 @@ class SweepWorker(QtCore.QRunnable): @pyqtSlot() def run(self): + global obj self.percentage = 0 if not self.app.serial.is_open: return @@ -55,9 +56,9 @@ class SweepWorker(QtCore.QRunnable): sweepFrom = 1000000 sweepTo = 800000000 else: - from NanoVNASaver import NanoVNASaver - sweepFrom = NanoVNASaver.parseFrequency(self.app.sweepStartInput.text()) - sweepTo = NanoVNASaver.parseFrequency(self.app.sweepEndInput.text()) + from NanoVNASaver import NanoVNASaver as obj + sweepFrom = obj.NanoVNASaver.parseFrequency(self.app.sweepStartInput.text()) + sweepTo = obj.NanoVNASaver.parseFrequency(self.app.sweepEndInput.text()) if sweepFrom < 0 or sweepTo < 0: print("Can't sweep from " + self.app.sweepStartInput.text() + " to " + self.app.sweepEndInput.text()) self.signals.finished.emit() @@ -85,7 +86,7 @@ class SweepWorker(QtCore.QRunnable): self.saveData(frequencies, values, values12) # Reset the device to show the full range - self.app.setSweep(NanoVNASaver.parseFrequency(self.app.sweepStartInput.text()), NanoVNASaver.parseFrequency(self.app.sweepEndInput.text())) + self.app.setSweep(obj.NanoVNASaver.parseFrequency(self.app.sweepStartInput.text()), obj.NanoVNASaver.parseFrequency(self.app.sweepEndInput.text())) else: self.app.setSweep(sweepFrom, sweepTo) sleep(0.8) diff --git a/Touchstone.py b/NanoVNASaver/Touchstone.py similarity index 96% rename from Touchstone.py rename to NanoVNASaver/Touchstone.py index 9c36e7d..2d3106f 100644 --- a/Touchstone.py +++ b/NanoVNASaver/Touchstone.py @@ -15,12 +15,13 @@ # along with this program. If not, see . import collections from typing import List + Datapoint = collections.namedtuple('Datapoint', 'freq re im') class Touchstone: - s11data : List[Datapoint] = [] - s21data : List[Datapoint] = [] + s11data: List[Datapoint] = [] + s21data: List[Datapoint] = [] filename = "" @@ -79,4 +80,4 @@ class Touchstone: return def setFilename(self, filename): - self.filename = filename \ No newline at end of file + self.filename = filename diff --git a/NanoVNASaver/__init__.py b/NanoVNASaver/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nanovna-saver.py b/NanoVNASaver/__main__.py similarity index 95% rename from nanovna-saver.py rename to NanoVNASaver/__main__.py index b5f322a..1e7b653 100644 --- a/nanovna-saver.py +++ b/NanoVNASaver/__main__.py @@ -18,11 +18,12 @@ from PyQt5 import QtWidgets -from NanoVNASaver import NanoVNASaver +from .NanoVNASaver import NanoVNASaver version = "0.0.4" -if __name__ == '__main__': + +def main(): print("NanoVNASaver " + version) print("Copyright (C) 2019 Rune B. Broberg") print("This program comes with ABSOLUTELY NO WARRANTY") @@ -34,3 +35,7 @@ if __name__ == '__main__': window = NanoVNASaver() window.show() app.exec_() + + +if __name__ == '__main__': + main() diff --git a/README.md b/README.md index 3b2ef3d..e2df579 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,20 @@ In order to run this app in Linux environment, you'll need the following package python3 nanovna-saver.py ``` +### Installation and Use with pip + +1. Clone repo and cd into the directory + - `git clone https://github.com/mihtjel/nanovna-saver` + - `cd nanovna-saver` + +2. Run the pip installation + + `pip install .` + +2. Once completed run with the following command + + `NanoVNASaver` + ### Using the software Connect your NanoVNA to a serial port, and enter this serial port in the serial port box. Click "Open serial" to connect. diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..224a779 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..927f5ca --- /dev/null +++ b/setup.py @@ -0,0 +1,55 @@ +# NanoVNASaver - a python program to view and export Touchstone data from a NanoVNA +# Copyright (C) 2019. Rune B. Broberg +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import sys + +if sys.version_info < (3, 7): + print("You need at least Python 3.7 for this application!") + if sys.version_info[0] < 3: + print("try running with python3 {}".format(" ".join(sys.argv))) + sys.exit(1) + +try: + from setuptools import setup, find_packages +except ImportError: + print("Could not find setuptools") + print("Try installing them with pip install setuptools") + sys.exit(1) + +with open("README.md", "r") as fh: + long_description = fh.read() + +setup( + name='NanoVNASaver', + url='https://github.com/mihtjel/nanovna-saver', + version='0.0.4', + author='Rune B. Broberg', + author_email='', + packages=find_packages(), + long_description=long_description, + long_description_content_type="text/markdown", + license='LICENSE.txt', + entry_points={ + 'console_scripts': [ + 'NanoVNASaver = NanoVNASaver.__main__:main' + ], + }, + install_requires=[ + 'pyserial', + 'PyQt5', + 'numpy', + ], +) \ No newline at end of file