Skip to content

Commit

Permalink
Maintenance (#418)
Browse files Browse the repository at this point in the history
* usb: improve logging for quirky messages

* usbtmc: formatting

* move coverage config to pyproject.toml

* update pre-commit-hook config

* fix formatting
  • Loading branch information
MatthieuDartiailh authored Mar 7, 2024
1 parent 8e8c1a1 commit 7286a6c
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 49 deletions.
16 changes: 0 additions & 16 deletions .coveragerc

This file was deleted.

21 changes: 8 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3.7
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: flake8
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.3.0
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: '' # Use the sha / tag you want to point at
hooks:
Expand Down
25 changes: 25 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,28 @@ __version__ = "{version}"
[[tool.mypy.overrides]]
module = ["usb.*", "serial.*", "gpib.*", "Gpib.*", "gpib_ctypes.*", "pyvicp.*"]
ignore_missing_imports = true

[tool.coverage]
[tool.coverage.run]
branch = true
source = ["pyvisa_py"]

[tool.coverage.report]
# Regexes for lines to exclude from consideration
exclude_lines = [
# Have to re-enable the standard pragma
"pragma: no cover",

# Don't complain if tests don't hit defensive assertion code:
"raise NotImplementedError",
"pass",

# Don't complain about abstract methods, they aren't run:
"@(abc\\.)?abstractmethod",

# Don't complain about type checking
"if TYPE_CHECKING:",

# Don't complain about ellipsis in overload
"\\.\\.\\.",
]
1 change: 1 addition & 0 deletions pyvisa_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:license: MIT, see LICENSE for more details.
"""

import sys

if sys.version_info >= (3, 8):
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:license: MIT, see LICENSE for more details.
"""

import logging
from typing import Iterator, Optional

Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/gpib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:license: MIT, see LICENSE for more details.
"""

import ctypes # Used for missing bindings not ideal
from bisect import bisect
from typing import Any, Iterator, List, Tuple, Union
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:license: MIT, see LICENSE for more details.
"""

import random
from collections import OrderedDict
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, cast
Expand Down
4 changes: 2 additions & 2 deletions pyvisa_py/protocols/hislip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Python implementation of HiSLIP protocol. Based on the HiSLIP spec:
Python implementation of HiSLIP protocol. Based on the HiSLIP spec:
http://www.ivifoundation.org/downloads/Class%20Specifications/IVI-6.1_HiSLIP-1.1-2011-02-24.pdf
http://www.ivifoundation.org/downloads/Class%20Specifications/IVI-6.1_HiSLIP-1.1-2011-02-24.pdf
"""

import socket
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/protocols/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
:license: MIT, see LICENSE for more details.
"""

import enum
import select
import socket
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/protocols/usbraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:license: MIT, see LICENSE for more details.
"""

from .usbtmc import USBRaw as USBRaw
from .usbutil import find_devices, find_interfaces

Expand Down
7 changes: 5 additions & 2 deletions pyvisa_py/protocols/usbtmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
:license: MIT, see LICENSE for more details.
"""

import enum
import struct
import time
Expand Down Expand Up @@ -97,7 +98,7 @@ def build_array(btag, eom, chunk):
class BulkInMessage(
namedtuple(
"BulkInMessage",
"msgid btag btaginverse " "transfer_size transfer_attributes data",
"msgid btag btaginverse transfer_size transfer_attributes data",
)
):
"""The Host uses the Bulk-IN endpoint to read USBTMC response messages from
Expand All @@ -113,7 +114,9 @@ def from_bytes(cls, data):
msgid, btag, btaginverse = struct.unpack_from("BBBx", data)
if msgid != MsgID.dev_dep_msg_in:
warnings.warn(
"Unexpected MsgID format. Consider updating the device's firmware. See https://github.com/pyvisa/pyvisa-py/issues/20"
"Unexpected MsgID format. Consider updating the device's firmware. "
"See https://github.com/pyvisa/pyvisa-py/issues/20"
f"Expected message id was {MsgID.dev_dep_msg_in}, got {msgid}."
)
return BulkInMessage.from_quirky(data)

Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/protocols/usbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:license: MIT, see LICENSE for more details.
"""

from fnmatch import fnmatch

import usb
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/protocols/vxi11.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:license: MIT, see LICENSE for more details.
"""

import enum
import socket

Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:license: MIT, see LICENSE for more details.
"""

import sys
from typing import Any, List, Tuple

Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:license: MIT, see LICENSE for more details.
"""

import abc
import time
from typing import (
Expand Down
25 changes: 13 additions & 12 deletions pyvisa_py/tcpip.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:license: MIT, see LICENSE for more details.
"""

import ipaddress
import random
import select
Expand Down Expand Up @@ -147,9 +148,9 @@ def after_parsing(self) -> None:
self.attrs[ResourceAttribute.interface_instrument_name] = "TCPIP0 (HiSLIP)"
self.attrs[ResourceAttribute.interface_number] = 0
self.attrs[ResourceAttribute.io_prot] = constants.VI_PROT_NORMAL
self.attrs[
ResourceAttribute.read_buffer_operation_mode
] = constants.VI_FLUSH_DISABLE
self.attrs[ResourceAttribute.read_buffer_operation_mode] = (
constants.VI_FLUSH_DISABLE
)
self.attrs[ResourceAttribute.resource_lock_state] = constants.VI_NO_LOCK
self.attrs[ResourceAttribute.send_end_enabled] = constants.VI_TRUE
self.attrs[ResourceAttribute.suppress_end_enabled] = constants.VI_FALSE
Expand All @@ -163,9 +164,9 @@ def after_parsing(self) -> None:
self.attrs[ResourceAttribute.tcpip_port] = port
self.attrs[ResourceAttribute.termchar] = ord("\n")
self.attrs[ResourceAttribute.termchar_enabled] = constants.VI_FALSE
self.attrs[
ResourceAttribute.write_buffer_operation_mode
] = constants.VI_FLUSH_WHEN_FULL
self.attrs[ResourceAttribute.write_buffer_operation_mode] = (
constants.VI_FLUSH_WHEN_FULL
)

# configure the variable attributes
self.attrs[ResourceAttribute.tcpip_hislip_max_message_kb] = (
Expand Down Expand Up @@ -857,19 +858,19 @@ def after_parsing(self) -> None:
self.attrs[ResourceAttribute.interface_instrument_name] = "TCPIP0 (VICP)"
self.attrs[ResourceAttribute.interface_number] = 0
self.attrs[ResourceAttribute.io_prot] = constants.VI_PROT_NORMAL
self.attrs[
ResourceAttribute.read_buffer_operation_mode
] = constants.VI_FLUSH_DISABLE
self.attrs[ResourceAttribute.read_buffer_operation_mode] = (
constants.VI_FLUSH_DISABLE
)
self.attrs[ResourceAttribute.resource_lock_state] = constants.VI_NO_LOCK
self.attrs[ResourceAttribute.suppress_end_enabled] = constants.VI_FALSE
self.attrs[ResourceAttribute.tcpip_address] = self.parsed.host_address
self.attrs[ResourceAttribute.tcpip_hostname] = self.parsed.host_address
self.attrs[ResourceAttribute.tcpip_is_hislip] = constants.VI_FALSE
self.attrs[ResourceAttribute.tcpip_nodelay] = constants.VI_TRUE
self.attrs[ResourceAttribute.tcpip_port] = port
self.attrs[
ResourceAttribute.write_buffer_operation_mode
] = constants.VI_FLUSH_WHEN_FULL
self.attrs[ResourceAttribute.write_buffer_operation_mode] = (
constants.VI_FLUSH_WHEN_FULL
)

# configure the variable attributes
self.attrs[ResourceAttribute.tcpip_keepalive] = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Test the Resource manager.
"""Test the Resource manager."""

"""
import pytest

from pyvisa.rname import ResourceName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
"""Test the TCPIP based resources.
"""Test the TCPIP based resources."""

"""
import socket

import pytest
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/testsuite/test_highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:license: MIT, see LICENSE for more details.
"""

from pyvisa.highlevel import list_backends
from pyvisa.testsuite import BaseTestCase
from pyvisa_py import highlevel
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/testsuite/test_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:license: MIT, see LICENSE for more details.
"""

import pytest

from pyvisa import ResourceManager
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/testsuite/test_sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:license: MIT, see LICENSE for more details.
"""

import ctypes

from pyvisa.constants import InterfaceType
Expand Down
1 change: 1 addition & 0 deletions pyvisa_py/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
:license: MIT, see LICENSE for more details.
"""

import errno
from typing import Any, List, Tuple, Type, Union

Expand Down

0 comments on commit 7286a6c

Please sign in to comment.