Skip to content

Commit

Permalink
build: Enable things needed for public package. (#8)
Browse files Browse the repository at this point in the history
* build: Enable things needed for public package.

* ci: update pre-commit and fix issues

* ci: skip local pre-commit checks in pre-commit.ci runs

* ci: skip local pre-commit checks in pre-commit.ci runs

* docs: Only show badge for main branch on readme.

* docs: fix codecov badge url

* ci: Update name of workflow

* ci: increase security scanning

* test: Update doctests with newest code.

* test: Update doctest to skip to remove false failures.

* ci: Require admin approval to merge PRs.

* ci: Add app settings to auto-add reviewers to PRs.
  • Loading branch information
nfelt14 authored Sep 22, 2023
1 parent c57bedb commit e07fb57
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence they
# will be requested for review when someone opens a pull request.
* @tektronix/tm-devices-maintainers
* @tektronix/tm-devices-admin

# Protect the configuration files
.github/ @tektronix/tm-devices-admin
8 changes: 8 additions & 0 deletions .github/auto_assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
addReviewers: true
addAssignees: author
reviewers:
- tektronix/tm-devices-maintainers
# Number of reviewers has no impact on GitHub teams
# Set 0 to add all the reviewers (default: 0)
numberOfReviewers: 0
11 changes: 1 addition & 10 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
- cron: 17 16 * * 4
release:
jobs:
# REMEMBER TO CHECK `LANGUAGE` MATRIX FOR CORRECT LANGUAGE SETTINGS
analyze:
name: Analyze
runs-on: ubuntu-latest
Expand All @@ -22,22 +21,14 @@ jobs:
fail-fast: false
matrix:
language: [python]
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality
queries: security-extended,security-and-quality
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
Expand Down
93 changes: 48 additions & 45 deletions .github/workflows/package-build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Package build & Upload
name: Package Build & Upload
on:
push:
branches: [main]
Expand All @@ -25,47 +25,50 @@ jobs:
with:
fetch-depth: 0
- uses: hynek/build-and-inspect-python-package@v1.5
# # 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.repository == 'tektronix/tm_devices' && 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/gh-action-pypi-publish@v1.8.8
# 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.repository == 'tektronix/tm_devices' && 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/gh-action-pypi-publish@v1.8.8
# - 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.repository == 'tektronix/tm_devices' && 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/gh-action-pypi-publish@v1.8.8
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.repository == 'tektronix/tm_devices' && github.event_name == 'release'
&& 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/gh-action-pypi-publish@v1.8.8
- 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: 8 additions & 8 deletions .github/workflows/test-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest] # TODO: add "macos-latest" back to the platform list
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v3
Expand All @@ -44,7 +44,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os_name: [ubuntu, windows] # TODO: add "macos" back to the os_name list
os_name: [ubuntu, windows, macos]
steps:
- uses: actions/checkout@v3
- name: Set up Python
Expand All @@ -64,12 +64,12 @@ jobs:
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
- 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()
Expand Down
13 changes: 10 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ default_stages: [pre-commit]
ci:
autofix_prs: false
autoupdate_schedule: quarterly
skip:
- check-poetry
- toml-sort
- pylint
- pyright
- pyright-verifytypes
- pyroma
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
Expand Down Expand Up @@ -34,7 +41,7 @@ repos:
- id: check-github-actions
- id: check-github-workflows
- repo: https://github.com/commitizen-tools/commitizen
rev: 3.7.0
rev: 3.9.0
hooks:
- id: commitizen
stages: [commit-msg]
Expand Down Expand Up @@ -114,12 +121,12 @@ repos:
always_run: true
args: [., --min=10]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.287
rev: v0.0.290
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.9.1
hooks:
- id: black
- repo: https://github.com/PyCQA/docformatter
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<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/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/actions/workflows/codeql-analysis.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?branch=main"></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?branch=main"></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?branch=main"></a>
<a href="https://codecov.io/gh/tektronix/tm_devices"><img alt="Coverage status" src="https://codecov.io/gh/tektronix/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/actions/workflows/codeql-analysis.yml/badge.svg?branch=main"></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>
Expand Down
7 changes: 3 additions & 4 deletions src/tm_devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
Examples:
>>> from tm_devices import DeviceManager
>>> with DeviceManager() as dm: # doctest: +ELLIPSIS
>>> with DeviceManager() as dm: # doctest: +SKIP
... print(dm.is_open)
2... - Opening DeviceManager
2023-09-21 01:50:16.031 - Opening DeviceManager
True
<BLANKLINE>
2... - DeviceManager Closed
2023-09-21 01:50:16.031 - DeviceManager Closed
"""
from importlib.metadata import version

Expand Down
3 changes: 2 additions & 1 deletion src/tm_devices/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
from tm_devices.drivers.pi.pi_device import PIDevice
from tm_devices.helpers import (
AliasDict,
check_for_update,
ConnectionTypes,
create_visa_connection,
detect_visa_resource_expression,
Expand Down Expand Up @@ -272,7 +273,7 @@ def __init__(
(updates the current configuration options).
external_device_drivers: An optional dict for passing in additional device drivers.
"""
# TODO: # check_for_update() # import and uncomment this helper once the package is on PyPI
check_for_update()
self._suppress_protection = False
# Set up the DeviceManager
self.__is_open = False
Expand Down
4 changes: 3 additions & 1 deletion src/tm_devices/drivers/api/rest_api/rest_api_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ def _send_request( # noqa: PLR0913,PLR0912,C901
status_code = response.status_code
except AttributeError:
try:
status_code = error.response.status_code
status_code = (
error.response.status_code # pyright: ignore[reportOptionalMemberAccess]
)
except AttributeError:
status_code = 503
return False, retval, status_code, error
Expand Down
1 change: 0 additions & 1 deletion tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def test_docs_html(self) -> None:
"""Test creating html documentation."""
subprocess.check_call(shlex.split("make html")) # noqa: S603

@pytest.mark.xfail(reason="tm_devices GitHub links don't work currently")
@pytest.mark.order(2)
def test_docs_linkcheck(self) -> None:
"""Run the linkcheck test for the documentation."""
Expand Down

0 comments on commit e07fb57

Please sign in to comment.