Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static Code Analysis changes #12

Merged
merged 7 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-api-for-breaking-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ on:
branches: [main]
jobs:
check-api-for-breaking-changes:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-check-api-for-breaking-changes.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-check-api-for-breaking-changes.yml@v1.3.0
with:
package-name: tekhsi # griffe requires the package name in lowercase
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- cron: 17 16 * * 4
jobs:
analyze:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-codeql-analysis.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-codeql-analysis.yml@v1.3.0
with:
languages-array: '["python", "javascript"]'
codeql-queries: security-extended,security-and-quality
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/enforce-community-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ on:
branches: [main]
jobs:
enforce-community-standards:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-enforce-community-standards.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-enforce-community-standards.yml@v1.3.0
2 changes: 1 addition & 1 deletion .github/workflows/package-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
package-build:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-package-build.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-package-build.yml@v1.3.0
with:
package-name: TekHSI
python-versions-array: '["3.8", "3.9", "3.10", "3.11", "3.12"]' # when updating this, make sure to update all workflows that use this strategy
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/package-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:
group: pypi
jobs:
package-release:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-package-release.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-package-release.yml@v1.3.0
with:
package-name: TekHSI
repo-name: tektronix/TekHSI
Expand All @@ -36,3 +36,5 @@ jobs:
checkout-token: ${{ secrets.TEK_OPENSOURCE_TOKEN }}
ssh-signing-key-private: ${{ secrets.TEK_OPENSOURCE_SSH_SIGNING_KEY_PRIVATE }}
ssh-signing-key-public: ${{ secrets.TEK_OPENSOURCE_SSH_SIGNING_KEY_PUBLIC }}
pypi-api-token: ${{ secrets.PYPI_API_TOKEN }}
test-pypi-api-token: ${{ secrets.TEST_PYPI_API_TOKEN }}
4 changes: 3 additions & 1 deletion .github/workflows/package-testpypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ concurrency:
group: pypi
jobs:
package-testpypi:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-package-testpypi.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-package-testpypi.yml@v1.3.0
with:
package-name: TekHSI
repo-name: tektronix/TekHSI
permissions:
contents: read
id-token: write
attestations: write
secrets:
test-pypi-api-token: ${{ secrets.TEST_PYPI_API_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/publish-api-comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [completed]
jobs:
publish-api-comparison:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-publish-api-comparison.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-publish-api-comparison.yml@v1.3.0
permissions:
checks: write
pull-requests: write
2 changes: 1 addition & 1 deletion .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [completed]
jobs:
publish-test-results:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-publish-test-results.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-publish-test-results.yml@v1.3.0
with:
operating-systems-array: '["ubuntu", "windows", "macos"]'
permissions:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sbom-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
types: [published]
jobs:
sbom-scan:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-sbom-scan.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-sbom-scan.yml@v1.3.0
permissions:
security-events: write
contents: write
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
test-code:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-test-code.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-test-code.yml@v1.3.0
with:
repo-name: tektronix/TekHSI
operating-systems-array: '["ubuntu", "windows", "macos"]'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ concurrency:
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
test-docs:
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-test-docs.yml@v1.2.0
uses: tektronix/python-package-ci-cd/.github/workflows/_reusable-test-docs.yml@v1.3.0
with:
node-version: 20 # The node version needs to stay in sync with .readthedocs.yml
python-version: '3.11' # This needs to stay in sync with .readthedocs.yml and the tox config in pyproject.toml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
branches: [main]
jobs:
update-python-and-pre-commit-dependencies:
uses: tektronix/python-package-ci-cd/.github/workflows/[email protected]
if: ${{ github.actor == 'dependabot[bot]' && contains(github.head_ref, '/pip/') }}
uses: tektronix/python-package-ci-cd/.github/workflows/[email protected]
with:
commit-user-name: ${{ vars.TEK_OPENSOURCE_NAME }}
commit-user-email: ${{ vars.TEK_OPENSOURCE_EMAIL }}
Expand Down
5 changes: 2 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ repos:
types: [python]
pass_filenames: true
args: [-sn]
exclude: ^tests/.* # TODO: include
# - id: pyright # TODO: enable
# name: pyright
# entry: pyright
Expand Down Expand Up @@ -147,8 +146,8 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 24d039e647a08707e6cb31e75e01844eeff925e7 # frozen: v0.6.2
hooks:
# - id: ruff # TODO: enable
# args: [--fix, --exit-non-zero-on-fix]
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/PyCQA/docformatter
rev: dfefe062799848234b4cd60b04aa633c0608025e # frozen: v1.7.5
Expand Down
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ Valid subsections within a version are:

Things to be included in the next release go here.

---

## v0.1.0

### Added

- First release of `TekHSI`!

---
8 changes: 4 additions & 4 deletions docs/basic_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,14 @@ running and then only consider the change when it arrives. It reduces the need f
start and '\*OPC?'.

```python
def any_horizontal_change(prevheader, currentheader):
def any_horizontal_change(previous_header, current_header):
"""Prebuilt acq acceptance filter that accepts only acqs with
changes to horizontal settings.
"""
for key, cur in currentheader.items():
if key not in prevheader:
for key, cur in current_header.items():
if key not in previous_header:
return True
prev = prevheader[key]
prev = previous_header[key]
if prev is None and cur != None:
return True
if prev is not None and (
Expand Down
3 changes: 2 additions & 1 deletion docs/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def define_env(env: MacrosPlugin) -> None:
"""
# Read in the current package version number to use in templates and files
with open(
pathlib.Path(f"{pathlib.Path(__file__).parents[1]}") / "pyproject.toml", "rb"
pathlib.Path(f"{pathlib.Path(__file__).parents[1]}") / "pyproject.toml",
"rb",
) as file_handle:
pyproject_data = tomli.load(file_handle)
package_version = "v" + pyproject_data["tool"]["poetry"]["version"]
Expand Down
11 changes: 5 additions & 6 deletions examples/create_sine_waveform.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""An example script for creating a sine waveform and saving it to a file."""

from tm_data_types import write_file, AnalogWaveform
import numpy as np
import math

import numpy as np

from tm_data_types import AnalogWaveform, write_file

length = 1000 # Record length of the waveform
frequency = 40.0e-10 # Frequency of the sinewave
cycles = 10 # Number of cycles of the sinewave in the waveform
Expand All @@ -30,7 +32,4 @@
# waveform.y_axis_values = np.sin(2 * np.pi
# * x_points) * amplitude / 2.0

try:
write_file("sample_waveforms/test_sine.wfm", waveform)
except Exception as e:
print(e)
write_file("sample_waveforms/test_sine.wfm", waveform)
16 changes: 9 additions & 7 deletions examples/custom_filter.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
"""An example script to connect to a scope, apply a custom filter to waveform data, and save to files."""
"""A script to connect to a scope, apply a custom filter to waveform data, and save to files."""

from tekhsi import TekHSIConnect, WaveformHeader
from tm_data_types import AnalogWaveform, write_file
from typing import Dict, List

from tm_data_types import AnalogWaveform, write_file

from tekhsi import TekHSIConnect, WaveformHeader

addr = "192.168.0.1" # Replace with the IP address of your instrument


def custom_filter(prevheader: Dict[WaveformHeader], currentheader: List[WaveformHeader]):
def custom_filter(previous_header: Dict[WaveformHeader], current_header: List[WaveformHeader]):
"""A custom criterion for deciding when to consider an acquisition for acceptance."""
for key, cur in currentheader.items():
if key not in prevheader:
for key, cur in current_header.items():
if key not in previous_header:
return True
prev = prevheader[key]
prev = previous_header[key]
if prev is not None and (
prev.verticalspacing != cur.verticalspacing
or prev.horizontalspacing != cur.horizontalspacing
Expand Down
6 changes: 4 additions & 2 deletions examples/plot_example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""An example script for connecting to a scope, retrieving waveform data, and plotting it."""

from tekhsi import TekHSIConnect
from tm_data_types import AnalogWaveform
import matplotlib.pyplot as plt
import numpy as np

from tm_data_types import AnalogWaveform

from tekhsi import TekHSIConnect

source = "ch1"
address = "192.168.0.1" # Replace with the IP address of your instrument

Expand Down
6 changes: 4 additions & 2 deletions examples/plot_iq.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""An example script for connecting to a Tek instrument, retrieving IQ waveform data, and plotting it."""

from tekhsi import TekHSIConnect, AcqWaitOn
from tm_data_types import IQWaveform
import matplotlib.pyplot as plt
import numpy as np

from tm_data_types import IQWaveform

from tekhsi import AcqWaitOn, TekHSIConnect

source = "ch1_iq"
address = "192.168.0.1" # Replace with the IP address of your instrument
decimate_count = 150
Expand Down
6 changes: 4 additions & 2 deletions examples/simple_plot.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""An example script for connecting to a scope, retrieving waveform data from multiple channels, and plotting it."""

from tekhsi import TekHSIConnect
from tm_data_types import AnalogWaveform
import matplotlib.pyplot as plt

from tm_data_types import AnalogWaveform

from tekhsi import TekHSIConnect

address = "192.168.0.1" # Replace with the IP address of your instrument

# Open connection to the instrument
Expand Down
3 changes: 2 additions & 1 deletion examples/simple_read.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""An example script for demonstrating reading waveform files and plotting the data."""

from tm_data_types import read_file, AnalogWaveform, IQWaveform, DigitalWaveform
import matplotlib.pyplot as plt
import numpy as np

from tm_data_types import AnalogWaveform, DigitalWaveform, IQWaveform, read_file

# Read the waveform file
file = read_file("sample_waveforms/test_sine.wfm")

Expand Down
Loading
Loading