Skip to content

Commit

Permalink
Merge pull request #600 from pyvisa/deprecation
Browse files Browse the repository at this point in the history
Remove deprecated features planned for removal in 1.12
  • Loading branch information
MatthieuDartiailh committed May 10, 2022
2 parents 645c1c6 + 08714bf commit 09a4bf8
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 541 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ exclude_lines =
pragma: no cover

# Don't complain if tests don't hit defensive assertion code:
raise NotImplementedError
raise NotImplementedError()
pass
19 changes: 19 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[flake8]
exclude =
.git,
__pycache__,
docs/source/conf.py,
old,
build,
dist,
pyvisa/thirdparty/*,
visa.py,
ignore = E203, E266, E501, W503, E731
# line length is intentionally set to 80 here because pyvisa uses Bugbear
# See https://github.com/psf/black/blob/master/README.md#line-length for more details
max-line-length = 80
max-complexity = 18
select = B,C,E,F,W,T4,B9
per-file-ignores =
pyvisa/__init__.py:E402
pyvisa/constants.py:E221
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.5.3
rev: v5.10.1
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.9.2
hooks:
- id: flake8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.782 # Use the sha / tag you want to point at
rev: v0.950 # Use the sha / tag you want to point at
hooks:
- id: mypy
additional_dependencies: [numpy, typing_extensions]
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ PyVISA Changelog
1.12.0 (unreleased)
-------------------

- remove deprecated feature planned for removal PR #600
This include the visa.py module. `
import visa` should be replaced by `import pyvisa as visa` and usage of
`python -m visa info` by `pyvisa-info` and `python -m visa shell` by `pyvisa-shell`
- optimize write_binary_values when passing in bytes, bytearray or numpy arrays PR #668
We avoid going through the struct module which can cause large memory overheads.
- fix collection of debug info on the ctypes wrapper PR #598
Expand Down
102 changes: 101 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,105 @@
[project]
name = "PyVISA"
description = "Python VISA bindings for GPIB, RS232, TCPIP and USB instruments"
readme = "README.rst"
requires-python = ">=3.7"
license = {file = "LICENSE"}
authors = [
{name = "Torsten Bronger", email = "bronger@physik.rwth-aachen.de"},
{name = "Gregor Thalhammer"}
]
maintainers = [
{name = "Matthieu C. Dartiailh", email = "m.dartiailh@gmail.com"}
]
keywords = [
"VISA",
"GPIB",
"USB",
"serial",
"RS232",
"measurement",
"acquisition",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX :: Linux",
"Operating System :: MacOS :: MacOS X",
"Programming Language :: Python",
"Topic :: Scientific/Engineering :: Interface Engine/Protocol Translator",
"Topic :: Software Development :: Libraries :: Python Modules",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
]
dependencies = [
"typing_extensions",
"importlib-metadata; python_version<'3.8'",
"dataclasses; python_version<'3.7'",
]
dynamic=["version"]


[project.urls]
homepage = "https://github.com/pyvisa/pyvisa"
documentation = "https://pyvisa.readthedocs.io/en/latest/"
repository = "https://github.com/pyvisa/pyvisa"
changelog = "https://github.com/pyvisa/pyvisa/blob/main/doc/CHANGES"

[project.scripts]
pyvisa-shell = "pyvisa.cmd_line_tools:visa_shell"
pyvisa-info = "pyvisa.cmd_line_tools:visa_info"

[build-system]
requires = ["setuptools>=42", "wheel", "setuptools_scm[toml]>=3.4.3"]
requires = ["setuptools>=61.2", "wheel", "setuptools_scm[toml]>=3.4.3"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
write_to = "pyvisa/version.py"
write_to_template = """
# This file is auto-generated by setuptools-scm do NOT edit it.
from collections import namedtuple
#: A namedtuple of the version info for the current release.
_version_info = namedtuple("_version_info", "major minor micro status")
parts = "{version}".split(".", 3)
version_info = _version_info(
int(parts[0]),
int(parts[1]),
int(parts[2]),
parts[3] if len(parts) == 4 else "",
)
# Remove everything but the 'version_info' from this module.
del namedtuple, _version_info, parts
__version__ = "{version}"
"""

[tool.black]
line-length = 88 # Enforce the default value

[tool.pytest.ini_options]
minversion = "6.0"

[tool.mypy]
follow_imports = "normal"
strict_optional = true

[[tool.mypy.overrides]]
module = [
"pyvisa.thirdparty.*",
]
ignore_errors = true

[tool.isort]
profile = "black"
skip = ["pyvisa/thirdparty/prettytable.py", "pyvisa/__init__.py"]

39 changes: 0 additions & 39 deletions pyvisa/ctwrapper/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"""
import ctypes
import logging
import warnings
from collections import OrderedDict
from typing import (
Any,
Expand Down Expand Up @@ -361,41 +360,3 @@ def get_buffer_from_id(self, job_id: typing.VISAJobID) -> Optional[SupportsBytes
return buffer

return None


class NIVisaLibrary(IVIVisaLibrary): # pragma: no cover
"""Deprecated name for IVIVisaLibrary.
This class will be removed in 1.12
"""

@staticmethod
def get_library_paths() -> Tuple[LibraryPath, ...]:
"""Return a tuple of possible library paths."""
warnings.warn(
"NIVisaLibrary is deprecated and will be removed in 1.12. "
"Use IVIVisaLibrary instead.",
FutureWarning,
)
return IVIVisaLibrary.get_library_paths()

@classmethod
def get_debug_info(cls) -> DebugInfo:
"""Return a list of lines with backend info."""
warnings.warn(
"NIVisaLibrary is deprecated and will be removed in 1.12. "
"Use IVIVisaLibrary instead.",
FutureWarning,
)
return IVIVisaLibrary.get_debug_info()

def __new__( # type: ignore
cls: Type["NIVisaLibrary"], library_path: str = ""
) -> highlevel.VisaLibraryBase:
warnings.warn(
"NIVisaLibrary is deprecated and will be removed in 1.12. "
"Use IVIVisaLibrary instead.",
FutureWarning,
)
return IVIVisaLibrary.__new__(cls, library_path)
47 changes: 0 additions & 47 deletions pyvisa/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
:license: MIT, see LICENSE for more details.
"""
import warnings
from typing import Any, Tuple

from . import typing, util
Expand Down Expand Up @@ -737,49 +736,3 @@ def from_wrong_arch(cls, filename: str) -> "LibraryError":
s += " bitness: %s\n" % visalib.bitness

return cls("Error while accessing %s: %s" % (filename, s))


# TODO remove when removing return handler
def _args_to_str(args: tuple, kwargs: dict) -> str: # pragma: no cover
return "args=%s, kwargs=%s" % (args, kwargs)


def return_handler(module_logger, first_is_session=True): # pragma: no cover
"""Decorate a VISA library function returning an error code."""
warnings.warn("return_handler will be removed in 1.12", FutureWarning)

def _outer(visa_library_method):
def _inner(self, session, *args, **kwargs):

ret_value = visa_library_method(*args, **kwargs)
module_logger.debug(
"%s%s -> %r",
visa_library_method.__name__,
_args_to_str(args, kwargs),
ret_value,
)

try:
ret_value = StatusCode(ret_value)
except ValueError:
pass

if first_is_session:
self._last_status = ret_value
self._last_status_in_session[session] = ret_value

if ret_value < 0:
raise VisaIOError(ret_value)

if ret_value in self.issue_warning_on:
if (
session
and ret_value not in self._ignore_warning_in_session[session]
):
module_logger.warn(VisaIOWarning(ret_value), stacklevel=2)

return ret_value

return _inner

return _outer
79 changes: 3 additions & 76 deletions pyvisa/highlevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2806,26 +2806,14 @@ class PyVISAModule(ModuleType):


def get_wrapper_class(backend_name: str) -> Type[VisaLibraryBase]:
"""Return the WRAPPER_CLASS for a given backend.
backend_name == 'ni' is used for backwards compatibility
and will be removed in 1.12.
"""
"""Return the WRAPPER_CLASS for a given backend."""
try:
return _WRAPPERS[backend_name]
except KeyError:
if backend_name == "ivi" or backend_name == "ni":
if backend_name == "ivi":
from .ctwrapper import IVIVisaLibrary

_WRAPPERS["ivi"] = IVIVisaLibrary
if backend_name == "ni":
warnings.warn(
"@ni backend name is deprecated and will be "
"removed in 1.12. Use @ivi instead. "
"Check the documentation for details",
FutureWarning,
)
return IVIVisaLibrary

pkg: PyVISAModule
Expand All @@ -2834,20 +2822,7 @@ def get_wrapper_class(backend_name: str) -> Type[VisaLibraryBase]:
_WRAPPERS[backend_name] = cls = pkg.WRAPPER_CLASS
return cls
except ImportError:
try:
pkg = cast(PyVISAModule, import_module("pyvisa-" + backend_name))
_WRAPPERS[backend_name] = cls = pkg.WRAPPER_CLASS
warnings.warn(
"Backends packages should use an _ rather than a - ."
"Project can/should keep using a - (like pytest plugins)."
"Support for backends with - will be removed in 1.12",
FutureWarning,
)
return cls
except ImportError:
raise ValueError(
"Wrapper not found: No package named pyvisa_%s" % backend_name
)
raise ValueError("Wrapper not found: No package named pyvisa_%s" % backend_name)


def _get_default_wrapper() -> str:
Expand Down Expand Up @@ -3314,51 +3289,3 @@ def open_resource(
self._created_resources.add(res)

return res

def get_instrument(
self,
resource_name: str,
access_mode: constants.AccessModes = constants.AccessModes.no_lock,
open_timeout: int = constants.VI_TMO_IMMEDIATE,
resource_pyclass: Type["Resource"] = None,
**kwargs: Any,
) -> "Resource":
"""Return an instrument for the resource name.
.. warning::
get_instrument is deprecated and will be removed in 1.12,
use open_resource instead."
Parameters
----------
resource_name : str
Name or alias of the resource to open.
access_mode : constants.AccessModes, optional
Specifies the mode by which the resource is to be accessed,
by default constants.AccessModes.no_lock
open_timeout : int, optional
If the ``access_mode`` parameter requests a lock, then this
parameter specifies the absolute time period (in milliseconds) that
the resource waits to get unlocked before this operation returns an
error, by default constants.VI_TMO_IMMEDIATE.
resource_pyclass : Optional[Type[Resource]], optional
Resource Python class to use to instantiate the Resource.
Defaults to None: select based on the resource name.
kwargs : Any
Keyword arguments to be used to change instrument attributes
after construction.
Returns
-------
Resource
Subclass of Resource matching the resource.
"""
warnings.warn(
"get_instrument is deprecated and will be removed in "
"1.12, use open_resource instead.",
FutureWarning,
)
return self.open_resource(
resource_name, access_mode, open_timeout, resource_pyclass, **kwargs
)

0 comments on commit 09a4bf8

Please sign in to comment.