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

Workflow Updates #3

Merged
merged 18 commits into from
Aug 18, 2023
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
89 changes: 44 additions & 45 deletions .github/workflows/package-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,47 @@ jobs:
with:
fetch-depth: 0
- uses: hynek/[email protected]

# Upload to Test PyPI on every push to main
test-pypi:
name: Publish package to test.pypi.org
environment:
name: test-pypi
url: https://test.pypi.org/p/tm_devices
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build-package
steps:
- name: Download built package
uses: actions/download-artifact@v3
with:
name: Package
path: dist
- name: Upload package to Test PyPI
uses: pypa/[email protected]
with:
repository-url: https://test.pypi.org/legacy/

# Upload to PyPI and create a tag in the repo after a GitHub Release is published
pypi:
name: Publish released package to pypi.org and create new tag in repo
environment:
name: pypi
url: https://pypi.org/p/tm_devices
if: github.event.action == 'published'
runs-on: ubuntu-latest
needs: build-package
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- name: Download built package
uses: actions/download-artifact@v3
with:
name: Package
path: dist
- name: Upload package to PyPI
uses: pypa/[email protected]
- name: Create and push tag
run: |-
git tag --annotate v${{ github.event.release.tag_name }} --message="${{ github.event.release.name }}"
git push --tags
# # Upload to Test PyPI on every push to main
# test-pypi:
# name: Publish package to test.pypi.org
# environment:
# name: test-pypi
# url: https://test.pypi.org/p/tm_devices
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# runs-on: ubuntu-latest
# needs: build-package
# steps:
# - name: Download built package
# uses: actions/download-artifact@v3
# with:
# name: Package
# path: dist
# - name: Upload package to Test PyPI
# uses: pypa/[email protected]
# with:
# repository-url: https://test.pypi.org/legacy/
#
# # Upload to PyPI and create a tag in the repo after a GitHub Release is published
# pypi:
# name: Publish released package to pypi.org and create new tag in repo
# environment:
# name: pypi
# url: https://pypi.org/p/tm_devices
# if: github.event.action == 'published'
# runs-on: ubuntu-latest
# needs: build-package
# permissions:
# contents: write
# steps:
# - uses: actions/checkout@v3
# - name: Download built package
# uses: actions/download-artifact@v3
# with:
# name: Package
# path: dist
# - name: Upload package to PyPI
# uses: pypa/[email protected]
# - name: Create and push tag
# run: |-
# git tag --annotate v${{ github.event.release.tag_name }} --message="${{ github.event.release.name }}"
# git push --tags
16 changes: 16 additions & 0 deletions .github/workflows/tek-repo-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
branches: [main]
release:
workflow_dispatch:
# IMPORTANT: Any new jobs need to be added to the check-repo-lint-passed job to ensure they correctly gate code changes
jobs:
check-for-codeowners-file:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -98,3 +99,18 @@ jobs:
- name: codeql-analysis file does not exist
if: steps.codeql-analysis_file.outputs.file_exists == 'false'
run: echo codeql-analysis file does not exist!
# Check that all jobs passed
check-repo-lint-passed:
if: always()
needs:
- check-for-codeowners-file
- check-for-readme-file
- check-for-license
- check-for-dependabot-file
- check-for-codeql-file
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
35 changes: 31 additions & 4 deletions .github/workflows/test-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# IMPORTANT: Any new jobs need to be added to the check-tests-passed job to ensure they correctly gate code changes
jobs:
# Basic testing & linting
test-general:
Expand All @@ -25,31 +26,57 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
check-latest: true
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-gh-actions
- name: Run tox
run: tox -v
- uses: actions/upload-artifact@v3
if: '!cancelled()'
with:
name: artifact_${{ matrix.platform }}_${{ matrix.python-version }}_tests_and_linting
path: .results_*/**
# Quick testing with coverage (no linting)
test-fast:
runs-on: ${{ matrix.os_name }}-latest
strategy:
fail-fast: false
matrix:
os_name: [ubuntu, macos, windows]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: x # any version
check-latest: true
- name: Install tox
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox
- name: Test
run: tox -ve tests
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
- uses: actions/upload-artifact@v3
if: '!cancelled()'
with:
name: artifact_${{ matrix.os_name }}_tests
path: .results_*/**
# TODO: look into using https://github.com/mikepenz/action-junit-report for a junit report
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# files: ./.coverage.tests
# name: codecov-${{ matrix.os_name }}
# fail_ci_if_error: true
# Check that all jobs passed
check-tests-passed:
if: always()
needs: [test-general, test-fast]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
name: codecov-${{ matrix.os_name }}
fail_ci_if_error: true
jobs: ${{ toJSON(needs) }}
16 changes: 16 additions & 0 deletions .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# IMPORTANT: Any new jobs need to be added to the check-docs-passed job to ensure they correctly gate code changes
jobs:
# Test building the docs (html, linkcheck, doctest, coverage)
test-docs:
Expand All @@ -35,3 +36,18 @@ jobs:
python -m pip install --upgrade tox
- name: Test
run: tox -ve ${{ matrix.tox_env }}
- uses: actions/upload-artifact@v3
if: '!cancelled()'
with:
name: artifact_${{ matrix.tox_env }}
path: .results_${{ matrix.tox_env }}/**
# Check that all jobs passed
check-docs-passed:
if: always()
needs: [test-docs]
runs-on: ubuntu-latest
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ repos:
- id: pretty-format-json
args: [--autofix, --indent=4]
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.1
rev: v1.5.4
hooks:
- id: remove-tabs
- id: forbid-tabs
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.23.3
rev: 0.24.1
hooks:
- id: check-readthedocs
- id: check-dependabot
Expand All @@ -39,7 +39,7 @@ repos:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/asottile/blacken-docs
rev: 1.15.0
rev: 1.16.0
hooks:
- id: blacken-docs
- repo: https://github.com/lyz-code/yamlfix/
Expand Down Expand Up @@ -112,7 +112,7 @@ repos:
always_run: true
args: [., --min=10]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.282
rev: v0.0.285
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ recommended IDE for package development is
````

- To run full static code analysis, tests, and documentation validation
(running this prior to opening a pull request is highly recommended, but it is very slow):
(running this prior to opening a pull request is highly recommended, but it is **very slow**):

```console
tox -p
```

- To run just the tests and static code analysis (much quicker):
- To run just the tests and static code analysis (**much quicker**):

```console
tox -p -m basic
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<p style="text-align: center;">
<a href="https://github.com/tektronix/tm_devices/actions/workflows/test-code.yml"><img alt="Code testing status" src="https://github.com/tektronix/tm_devices/workflows/test-code.yml/badge.svg"></a>
<a href="https://github.com/tektronix/tm_devices/actions/workflows/test-docs.yml"><img alt="Docs testing status" src="https://github.com/tektronix/tm_devices/workflows/test-docs.yml/badge.svg"></a>
<a href="https://github.com/tektronix/tm_devices/actions/workflows/package-build.yml"><img alt="Package build status" src="https://github.com/tektronix/tm_devices/workflows/test-package-build.yml/badge.svg"></a>
<a href="https://github.com/tektronix/tm_devices/actions/workflows/test-code.yml"><img alt="Code testing status" src="https://github.com/tektronix/tm_devices/actions/workflows/test-code.yml/badge.svg"></a>
<a href="https://github.com/tektronix/tm_devices/actions/workflows/test-docs.yml"><img alt="Docs testing status" src="https://github.com/tektronix/tm_devices/actions/workflows/test-docs.yml/badge.svg"></a>
<a href="https://github.com/tektronix/tm_devices/actions/workflows/package-build.yml"><img alt="Package build status" src="https://github.com/tektronix/tm_devices/actions/workflows/package-build.yml/badge.svg"></a>
<a href="https://codecov.io/gh/tm_devices"><img alt="Coverage status" src="https://codecov.io/gh/tm_devices/branch/main/graph/badge.svg"></a>
<a href="https://github.com/tektronix/tm_devices/actions/workflows/codeql-analysis.yml"><img alt="CodeQL status" src="https://github.com/tektronix/tm_devices/workflows/codeql-analysis.yml/badge.svg"></a>
<a href="https://github.com/tektronix/tm_devices/actions/workflows/codeql-analysis.yml"><img alt="CodeQL status" src="https://github.com/tektronix/tm_devices/actions/workflows/codeql-analysis.yml/badge.svg"></a>
<a href="https://github.com/pre-commit/pre-commit"><img alt="pre-commit enabled" src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit"></a>
<a href="https://results.pre-commit.ci/latest/github/tektronix/tm_devices/main"><img alt="pre-commit status" src="https://results.pre-commit.ci/badge/github/tektronix/tm_devices/main.svg"></a>
<a href="https://tm_devices.readthedocs.io/en/stable/?badge=stable"><img alt="Documentation status" src="https://readthedocs.org/projects/tm_devices/badge/?version=stable"></a>
<a href="https://github.com/tektronix/tm_devices/blob/main/LICENSE.md"><img alt="License: Apache 2.0" src="https://img.shields.io/hexpm/l/tm_devices"></a>
<a href="https://github.com/tektronix/tm_devices/blob/main/LICENSE.md"><img alt="License: Apache 2.0" src="https://img.shields.io/pypi/l/tm_devices"></a>
<a href="https://pypi.org/project/tm_devices/"><img alt="PyPI: Package status" src="https://img.shields.io/pypi/status/tm_devices?logo=pypi"></a>
<a href="https://pypi.org/project/tm_devices/"><img alt="PyPI: Latest release version" src="https://img.shields.io/pypi/v/tm_devices?logo=pypi"></a>
<a href="https://pypi.org/project/tm_devices/"><img alt="PyPI: Supported Python versions" src="https://img.shields.io/pypi/pyversions/tm_devices?logo=python"></a>
Expand Down
5 changes: 4 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
extlinks_detect_hardcoded_links = True
extlinks = {
"repo_url": (
("https://github.com/tektronix/tm_devices/blob/main/%s"),
"https://github.com/tektronix/tm_devices/blob/main/%s",
"%s",
)
}
Expand Down Expand Up @@ -170,6 +170,9 @@ def prep_jinja_env(jinja_env: JinjaEnvironment) -> None:
"https://pyvisa.readthedocs.io/projects/pyvisa-py/en/latest/",
"https://pyvisa.readthedocs.io/en/latest/",
"https://python-semantic-release.readthedocs.io/en/latest/",
"https://docs.pytest.org/en/latest/",
"https://pytest-cov.readthedocs.io/en/latest/",
"https://pyvisa.readthedocs.io/projects/pyvisa-sim/en/latest/",
]
tippy_anchor_parent_selector = "div.document"

Expand Down
17 changes: 10 additions & 7 deletions docs/contributing/add_driver_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@ device drivers.
Because of the inheritance structure of the device drivers (see the
[architecture diagrams](../advanced/architecture.md#main-device-types)), new
methods should be added to the highest applicable class in the tree. All methods
for each type of device (Scope, AFG, SMU, etc.) need to be defined in that
device type's abstract class, or higher up the tree, to enable accurate type
hinting for each different device type tree. Unless the implementation is the
same for all subclasses of that device type, the abstract class's implementation
should simply `raise NotImplementedError`.
for each family of device (TekScope, SMU2600, PSU2200, etc.) need to be defined in that
device family's abstract class, or higher up the tree, to enable accurate type
hinting for each different device family tree. Unless the implementation is the
same for all subclasses of that device family, the abstract class's implementation
should be decorated as an `@abstractmethod`.

## New method addition example

```python
from abc import abstractmethod


# scope.py
# Abstract class
class Scope(...):
@abstractmethod
def new_method(self):
# Abstract class raises an error.
raise NotImplementedError
"""Abstract class raises an error."""


# tekscope.py
Expand Down
6 changes: 3 additions & 3 deletions docs/contributing/add_new_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ This guide will walk through the steps needed to add a new device driver.
[add a new device type](./add_new_device_type.md) subpackage
02. Create the new device driver python file and class that inherits the
appropriate device type/series base class
1. If the new device(s) are part of a series, add a new series subpackage
for theme (e.g. `power_supplies/psu2200/`)
1. If the new device(s) are part of a series (also referred to as a family),
add a new series subpackage for them (e.g. `power_supplies/psu2200/`)
2. Create the device driver python file, create a class that inherits from
the abstracted device type (or series) base class, see
[example](#example-of-adding-a-new-device-series-parent-driver-class).
Expand Down Expand Up @@ -63,7 +63,7 @@ from tm_devices.drivers.pi.power_supplies.power_supply import PowerSupplyUnit
from tm_devices.drivers.device import family_base_class


@family_base_class
@family_base_class # Mark the base class for the new family of devices
class BaseFancyPSU(PowerSupplyUnit, ABC):
"""Base Fancy PSU device driver."""

Expand Down
1 change: 1 addition & 0 deletions docs/contributing/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ maxdepth: 1
add_driver_methods.md
add_new_driver.md
add_new_device_type.md
unit_tests.md
```
Loading