Automatic pypi deployment and linting.

This commit is contained in:
jupfi 2024-04-23 18:06:12 +02:00
parent 76cf2fb2d3
commit 57e968cabd
6 changed files with 99 additions and 18 deletions

44
.github/workflows/python-publish.yml vendored Normal file
View file

@ -0,0 +1,44 @@
name: Build, Test, and Upload Python Package
on:
push:
tags:
- "v*.*.*"
workflow_dispatch:
permissions:
contents: read
jobs:
# test:
# uses: ./.github/workflows/ubuntu-python-package.yml # use the callable tests job to run tests
deploy:
runs-on: ubuntu-latest
# needs: [test]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install dependencies
run: |
sudo apt-get update
python -m pip install --upgrade pip
- name: Publish to PyPI
run: |
python -m venv venv
. ./venv/bin/activate
pip install -U twine build
python -m build .
python -m twine upload --repository pypi --username __token__ --password ${{ secrets.PYPI }} dist/*
env:
PYPI: ${{ secrets.PYPI }}

View file

@ -1,4 +1,7 @@
# Changelog # Changelog
### Version 0.0.4 (23-04-2024)
- Automatic PyPi deployment
### Version 0.0.3 (15-04-2024) ### Version 0.0.3 (15-04-2024)
- Initial release - Initial release

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2023 Julia Pfitzer Copyright (c) 2023 jupfi
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -27,11 +27,16 @@ Ideally you should install the module in a virtual environment. You can create a
python -m venv nqrduck python -m venv nqrduck
``` ```
You can install this module and the dependencies by running the following command in the terminal: You can install this module and the dependencies by running the following command in the terminal after cloning the repositor and navigating to the module directory:
```bash ```bash
pip install . pip install .
``` ```
Alternatively you can install the module via the PyPi package manager by running the following command in the terminal:
```bash
pip install nqrduck-spectrometer-limenqr
```
## Usage ## Usage
The module is used together with the NQRduck [pulseprogrammer](htpps://github.com/nqrduck-pulseprogrammer) module. The module is used together with the NQRduck [pulseprogrammer](htpps://github.com/nqrduck-pulseprogrammer) module.

View file

@ -7,9 +7,9 @@ allow-direct-references = true
[project] [project]
name = "nqrduck-spectrometer-limenqr" name = "nqrduck-spectrometer-limenqr"
version = "0.0.3" version = "0.0.4"
authors = [ authors = [
{ name="Julia Pfitzer", email="git@jupfi.me" }, { name="jupfi", email="support@nqrduck.cool" },
] ]
description = "A submodule for the nqrduck-spectrometer module which implements the functionality for the LimeNQR spectrometer." description = "A submodule for the nqrduck-spectrometer module which implements the functionality for the LimeNQR spectrometer."
@ -20,11 +20,11 @@ requires-python = ">=3.8"
classifiers = [ classifiers = [
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License", "License :: OSI Approved :: MIT License",
"Operating System :: OS Independent", "Operating System :: POSIX :: Linux",
] ]
dependencies = [ dependencies = [
"limedriver @ git+https://github.com/nqrduck/LimeDriverBindings", "limedriver",
"nqrduck-spectrometer", "nqrduck-spectrometer",
"pyqt6", "pyqt6",
"h5py", "h5py",
@ -32,4 +32,29 @@ dependencies = [
] ]
[project.entry-points."nqrduck"] [project.entry-points."nqrduck"]
"nqrduck-spectrometer-limenqr" = "nqrduck_spectrometer_limenqr.limenqr:LimeNQR" "nqrduck-spectrometer-limenqr" = "nqrduck_spectrometer_limenqr.limenqr:LimeNQR"
[tool.ruff]
exclude = [
"widget.py",
]
[tool.ruff.lint]
extend-select = [
"UP", # pyupgrade
"D", # pydocstyle
]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
[tool.ruff.lint.pydocstyle]
convention = "google"
[project.urls]
"Homepage" = "https://nqrduck.cool"
"Bug Tracker" = "https://github.com/nqrduck/nqrduck-spectrometer-limenqr/issues"
"Source Code" = "https://github.com/nqrduck/nqrduck-spectrometer-limenqr"
[tool.hatch.build.targets.wheel]
packages = ["src/nqrduck_spectrometer_limenqr"]

View file

@ -7,7 +7,6 @@ from decimal import Decimal
from limedriver.binding import PyLimeConfig from limedriver.binding import PyLimeConfig
from limedriver.hdf_reader import HDF from limedriver.hdf_reader import HDF
from nqrduck.module.module_controller import ModuleController
from nqrduck_spectrometer.base_spectrometer_controller import BaseSpectrometerController from nqrduck_spectrometer.base_spectrometer_controller import BaseSpectrometerController
from nqrduck_spectrometer.measurement import Measurement from nqrduck_spectrometer.measurement import Measurement
from nqrduck_spectrometer.pulseparameters import TXPulse, RXReadout from nqrduck_spectrometer.pulseparameters import TXPulse, RXReadout
@ -166,7 +165,8 @@ class LimeNQRController(BaseSpectrometerController):
rx_stop (float): The stop time of the RX event in µs rx_stop (float): The stop time of the RX event in µs
Returns: Returns:
list: The indices of the evaluation range in the measurement data""" list: The indices of the evaluation range in the measurement data
"""
return np.where((hdf.tdx > rx_begin) & (hdf.tdx < rx_stop))[0] return np.where((hdf.tdx > rx_begin) & (hdf.tdx < rx_stop))[0]
def extract_measurement_data(self, lime, hdf, indices): def extract_measurement_data(self, lime, hdf, indices):
@ -190,7 +190,8 @@ class LimeNQRController(BaseSpectrometerController):
"""This method returns the FFT shift value from the settings. """This method returns the FFT shift value from the settings.
Returns: Returns:
int: The FFT shift value""" int: The FFT shift value
"""
fft_shift_enabled = self.module.model.get_setting_by_name(self.module.model.FFT_SHIFT).value fft_shift_enabled = self.module.model.get_setting_by_name(self.module.model.FFT_SHIFT).value
return self.module.model.if_frequency if fft_shift_enabled else 0 return self.module.model.if_frequency if fft_shift_enabled else 0
@ -237,8 +238,8 @@ class LimeNQRController(BaseSpectrometerController):
lime (PyLimeConfig): The PyLimeConfig object that is used to communicate with the pulseN driver lime (PyLimeConfig): The PyLimeConfig object that is used to communicate with the pulseN driver
Returns: Returns:
lime: The updated limr object""" lime: The updated limr object
"""
logger.debug( logger.debug(
"Updating settings for spectrometer: %s for measurement", "Updating settings for spectrometer: %s for measurement",
self.module.model.name, self.module.model.name,
@ -352,13 +353,12 @@ class LimeNQRController(BaseSpectrometerController):
return lime return lime
def get_number_of_pulses(self): def get_number_of_pulses(self):
""" This method calculates the number of pulses in the pulse sequence before the LimeDriverBinding is initialized. """This method calculates the number of pulses in the pulse sequence before the LimeDriverBinding is initialized.
This makes sure it"s initialized with the correct size of the pulse lists. This makes sure it"s initialized with the correct size of the pulse lists.
Returns: Returns:
int: The number of pulses in the pulse sequence int: The number of pulses in the pulse sequence
""" """
events = self.fetch_pulse_sequence_events() events = self.fetch_pulse_sequence_events()
num_pulses = 0 num_pulses = 0
for event in events: for event in events:
@ -390,7 +390,8 @@ class LimeNQRController(BaseSpectrometerController):
"""This method checks if a parameter a pulse with a transmit pulse shape (amplitude nonzero) """This method checks if a parameter a pulse with a transmit pulse shape (amplitude nonzero)
Args: Args:
parameter (Parameter): The parameter to check""" parameter (Parameter): The parameter to check
"""
return (parameter.name == self.module.model.TX and return (parameter.name == self.module.model.TX and
parameter.get_option_by_name(TXPulse.RELATIVE_AMPLITUDE).value > 0) parameter.get_option_by_name(TXPulse.RELATIVE_AMPLITUDE).value > 0)
@ -402,7 +403,8 @@ class LimeNQRController(BaseSpectrometerController):
parameter (Parameter): The parameter that contains the pulse shape and amplitude parameter (Parameter): The parameter that contains the pulse shape and amplitude
Returns: Returns:
tuple: A tuple containing the pulse shape and the pulse amplitude""" tuple: A tuple containing the pulse shape and the pulse amplitude
"""
pulse_shape = parameter.get_option_by_name(TXPulse.TX_PULSE_SHAPE).value pulse_shape = parameter.get_option_by_name(TXPulse.TX_PULSE_SHAPE).value
pulse_amplitude = abs(pulse_shape.get_pulse_amplitude(event.duration)) * \ pulse_amplitude = abs(pulse_shape.get_pulse_amplitude(event.duration)) * \
parameter.get_option_by_name(TXPulse.RELATIVE_AMPLITUDE).value parameter.get_option_by_name(TXPulse.RELATIVE_AMPLITUDE).value
@ -433,7 +435,8 @@ class LimeNQRController(BaseSpectrometerController):
"""This method unwraps the phase of the pulse. """This method unwraps the phase of the pulse.
Args: Args:
phase (float): The phase of the pulse""" phase (float): The phase of the pulse
"""
return (np.unwrap(phase) + 2 * np.pi) % (2 * np.pi) return (np.unwrap(phase) + 2 * np.pi) % (2 * np.pi)
def initialize_pulse_lists(self, lime, pulse_amplitude, pulse_shape, modulated_phase): def initialize_pulse_lists(self, lime, pulse_amplitude, pulse_shape, modulated_phase):
@ -624,7 +627,8 @@ class LimeNQRController(BaseSpectrometerController):
"""This method sets the number of averages for the spectrometer. """This method sets the number of averages for the spectrometer.
Args: Args:
value (int): The number of averages""" value (int): The number of averages
"""
logger.debug("Setting averages to: %s", value) logger.debug("Setting averages to: %s", value)
try: try:
self.module.model.averages = int(value) self.module.model.averages = int(value)