Skip to content

Commit

Permalink
Automatic pypi deployment and linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jupfi committed Apr 23, 2024
1 parent 76cf2fb commit 57e968c
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 18 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog

### Version 0.0.4 (23-04-2024)
- Automatic PyPi deployment

### Version 0.0.3 (15-04-2024)
- Initial release
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Julia Pfitzer
Copyright (c) 2023 jupfi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@ Ideally you should install the module in a virtual environment. You can create a
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
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
The module is used together with the NQRduck [pulseprogrammer](htpps://github.com/nqrduck-pulseprogrammer) module.

Expand Down
35 changes: 30 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ allow-direct-references = true

[project]
name = "nqrduck-spectrometer-limenqr"
version = "0.0.3"
version = "0.0.4"
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."
Expand All @@ -20,16 +20,41 @@ requires-python = ">=3.8"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Operating System :: POSIX :: Linux",
]

dependencies = [
"limedriver @ git+https://github.com/nqrduck/LimeDriverBindings",
"limedriver",
"nqrduck-spectrometer",
"pyqt6",
"h5py",
"pyserial",
]

[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"]
26 changes: 15 additions & 11 deletions src/nqrduck_spectrometer_limenqr/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from limedriver.binding import PyLimeConfig
from limedriver.hdf_reader import HDF

from nqrduck.module.module_controller import ModuleController
from nqrduck_spectrometer.base_spectrometer_controller import BaseSpectrometerController
from nqrduck_spectrometer.measurement import Measurement
from nqrduck_spectrometer.pulseparameters import TXPulse, RXReadout
Expand Down Expand Up @@ -166,7 +165,8 @@ def find_evaluation_range_indices(self, hdf, rx_begin, rx_stop):
rx_stop (float): The stop time of the RX event in µs
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]

def extract_measurement_data(self, lime, hdf, indices):
Expand All @@ -190,7 +190,8 @@ def get_fft_shift(self):
"""This method returns the FFT shift value from the settings.
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
return self.module.model.if_frequency if fft_shift_enabled else 0

Expand Down Expand Up @@ -237,8 +238,8 @@ def update_settings(self, lime):
lime (PyLimeConfig): The PyLimeConfig object that is used to communicate with the pulseN driver
Returns:
lime: The updated limr object"""

lime: The updated limr object
"""
logger.debug(
"Updating settings for spectrometer: %s for measurement",
self.module.model.name,
Expand Down Expand Up @@ -352,13 +353,12 @@ def translate_pulse_sequence(self, lime):
return lime

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.
Returns:
int: The number of pulses in the pulse sequence
"""

events = self.fetch_pulse_sequence_events()
num_pulses = 0
for event in events:
Expand Down Expand Up @@ -390,7 +390,8 @@ def is_translatable_tx_parameter(self, parameter):
"""This method checks if a parameter a pulse with a transmit pulse shape (amplitude nonzero)
Args:
parameter (Parameter): The parameter to check"""
parameter (Parameter): The parameter to check
"""
return (parameter.name == self.module.model.TX and
parameter.get_option_by_name(TXPulse.RELATIVE_AMPLITUDE).value > 0)

Expand All @@ -402,7 +403,8 @@ def prepare_pulse_amplitude(self, event, parameter):
parameter (Parameter): The parameter that contains the pulse shape and amplitude
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_amplitude = abs(pulse_shape.get_pulse_amplitude(event.duration)) * \
parameter.get_option_by_name(TXPulse.RELATIVE_AMPLITUDE).value
Expand Down Expand Up @@ -433,7 +435,8 @@ def unwrap_phase(self, phase):
"""This method unwraps the phase of the pulse.
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)

def initialize_pulse_lists(self, lime, pulse_amplitude, pulse_shape, modulated_phase):
Expand Down Expand Up @@ -624,7 +627,8 @@ def set_averages(self, value: int):
"""This method sets the number of averages for the spectrometer.
Args:
value (int): The number of averages"""
value (int): The number of averages
"""
logger.debug("Setting averages to: %s", value)
try:
self.module.model.averages = int(value)
Expand Down

0 comments on commit 57e968c

Please sign in to comment.