Skip to content

Commit

Permalink
fix flake8 complains
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthieuDartiailh committed Dec 13, 2022
1 parent a6fd752 commit 434a4cf
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 94 deletions.
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
exclude =
.git,
__pycache__,
docs/source/conf.py,
old,
build,
dist,
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
22 changes: 10 additions & 12 deletions pyvisa_sim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim
~~~~~~~~~~
"""Simulated backend for PyVISA.
Simulated backend for PyVISA.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import pkg_resources
from importlib.metadata import PackageNotFoundError, version

from .highlevel import SimVisaLibrary


__version__ = "unknown"
try: # pragma: no cover
__version__ = pkg_resources.get_distribution("pyvisa-sim").version
except: # pragma: no cover
pass # we seem to have a local copy without any repository control or installed without setuptools
# so the reported version will be __unknown__
try:
__version__ = version(__name__)
except PackageNotFoundError:
# package is not installed
pass


WRAPPER_CLASS = SimVisaLibrary
9 changes: 3 additions & 6 deletions pyvisa_sim/channels.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.channel
~~~~~~~~~~~~~~~~~~
"""Classes to enable the use of channels in devices.
Classes to enable the use of channels in devices.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
from collections import defaultdict

Expand Down
16 changes: 7 additions & 9 deletions pyvisa_sim/common.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.common
~~~~~~~~~~~~~~~~~
"""Common tools.
This code is currently taken from PyVISA-py.
Do not edit here.
This code is currently taken from PyVISA-py.
Do not edit here.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import logging
import sys

from pyvisa import logger

logger = logging.LoggerAdapter(logger, {"backend": "sim"})
logger = logging.LoggerAdapter(logger, {"backend": "sim"}) # type: ignore


class NamedObject(object):
Expand Down
9 changes: 3 additions & 6 deletions pyvisa_sim/component.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.component
~~~~~~~~~~~~~~~~~~~~
"""Base classes for devices parts.
Base classes for devices parts.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import stringparser

Expand Down
13 changes: 5 additions & 8 deletions pyvisa_sim/devices.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.devices
~~~~~~~~~~~~~~~~~~
"""Classes to simulate devices.
Classes to simulate devices.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
from pyvisa import constants, rname

Expand Down Expand Up @@ -221,12 +218,12 @@ def write(self, data):

self._input_buffer.extend(data)

l = len(self._query_eom)
le = len(self._query_eom)
if not self._input_buffer.endswith(self._query_eom):
return

try:
message = bytes(self._input_buffer[:-l])
message = bytes(self._input_buffer[:-le])
queries = message.split(self.delimiter) if self.delimiter else [message]
for query in queries:
response = self._match(query)
Expand Down
10 changes: 3 additions & 7 deletions pyvisa_sim/gpib.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.gpib
~~~~~~~~~~~~~~~
"""GPIB simulated session.
GPIB simulated session.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import queue
import time

from pyvisa import constants
Expand Down
11 changes: 4 additions & 7 deletions pyvisa_sim/highlevel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.highlevel
~~~~~~~~~~~~~~~~~~~~
"""Simulated VISA Library.
Simulated VISA Library.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""

import random
Expand All @@ -18,7 +15,7 @@
from pyvisa.util import LibraryPath

# This import is required to register subclasses
from . import gpib, parser, serial, sessions, tcpip, usb
from . import gpib, parser, serial, sessions, tcpip, usb # noqa


class SimVisaLibrary(highlevel.VisaLibraryBase):
Expand Down
19 changes: 8 additions & 11 deletions pyvisa_sim/parser.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.parser
~~~~~~~~~~~~~~~~~
"""Parser function
Parser function
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import os
from contextlib import closing
from io import StringIO, open
from traceback import format_exc

import pkg_resources
import pkg_resources # XXX use importlib.resources instead
import yaml

from .channels import Channels
Expand Down Expand Up @@ -85,16 +82,16 @@ def _load(content_or_fp):

try:
ver = data["spec"]
except:
raise ValueError("The file does not specify a spec version")
except Exception as e:
raise ValueError("The file does not specify a spec version") from e

try:
ver = tuple(map(int, (ver.split("."))))
except:
except Exception as e:
raise ValueError(
"Invalid spec version format. Expect 'X.Y'"
" (X and Y integers), found %s" % ver
)
) from e

if ver > SPEC_VERSION_TUPLE:
raise ValueError(
Expand Down
10 changes: 3 additions & 7 deletions pyvisa_sim/serial.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.serial
~~~~~~~~~~~~~~~~~
"""ASRL (Serial) simulated session class.
ASRL (Serial) simulated session class.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import queue
import time

from pyvisa import constants
Expand Down
11 changes: 3 additions & 8 deletions pyvisa_sim/sessions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.sessions
~~~~~~~~~~~~~~~~~~~
"""Base session class.
Base session class.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import queue

from pyvisa import attributes, constants, rname

from .common import logger
Expand Down
9 changes: 3 additions & 6 deletions pyvisa_sim/tcpip.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.tcpip
~~~~~~~~~~~~~~~~
"""TCPIP simulated session class.
TCPIP simulated session class.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import time

Expand Down
10 changes: 3 additions & 7 deletions pyvisa_sim/usb.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# -*- coding: utf-8 -*-
"""
pyvisa-sim.usb
~~~~~~~~~~~~~~
"""USB simulated session class.
USB simulated session class.
:copyright: 2014-2022 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
:copyright: 2014 by PyVISA-sim Authors, see AUTHORS for more details.
:license: MIT, see LICENSE for more details.
"""
import queue
import time

from pyvisa import constants
Expand Down

0 comments on commit 434a4cf

Please sign in to comment.