Skip to content

Commit

Permalink
refactor(code-style): Switch to ruff format instead of black for …
Browse files Browse the repository at this point in the history
…code formatting. (tektronix#117)

Signed-off-by: v12ganesh [email protected]
  • Loading branch information
nfelt14 authored Dec 12, 2023
1 parent 2c5c6a1 commit 36b9518
Show file tree
Hide file tree
Showing 35 changed files with 116 additions and 93 deletions.
5 changes: 5 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
# will be requested for review when someone opens a pull request.
* @tektronix/tm-devices-admin

/docs/ @tektronix/tm-devices-maintainers
/examples/ @tektronix/tm-devices-maintainers
/src/ @tektronix/tm-devices-maintainers
/tests/ @tektronix/tm-devices-maintainers

# Protect the configuration files
.github/ @tektronix/tm-devices-admin
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ repos:
- id: remove-tabs
- id: forbid-tabs
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.27.2
rev: 0.27.3
hooks:
- id: check-readthedocs
- id: check-dependabot
Expand Down Expand Up @@ -121,15 +121,12 @@ repos:
pass_filenames: false
always_run: true
args: [., --min=10]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.6
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.7
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 23.11.0
hooks:
- id: black
- id: ruff-format
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.0 # can't update due to https://github.com/PyCQA/docformatter/issues/174
hooks:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ ______________________________________________________________________

Things to be included in the next release go here.

### Changed

- Switched to ruff's formatter instead of black's formatter for python code

______________________________________________________________________

## v1.1.0 (2023-12-07)
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* - Documentation
- |GitHub Pages status|
* - Code Style
- |Test style: pytest| |Code style: black| |Imports: isort| |Docstring style: google|
- |Test style: pytest| |Code style: ruff| |Imports: isort| |Docstring style: google|
* - Linting
- |pre-commit enabled| |Docstring formatter: docformatter| |Type Checker: pyright| |Linter: pylint| |Linter: Ruff|

Expand Down Expand Up @@ -74,8 +74,8 @@
.. |PyPI: Downloads| image:: https://pepy.tech/badge/tm-devices
:target: https://pepy.tech/project/tm_devices

.. |Code style: black| image:: https://img.shields.io/badge/code%20style-black-black
:target: https://github.com/psf/black
.. |Code style: ruff| image:: https://img.shields.io/badge/code%20style-ruff-black
:target: https://docs.astral.sh/ruff/formatter/

.. |Imports: isort| image:: https://img.shields.io/badge/imports-isort-black
:target: https://pycqa.github.io/isort/
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ def skip_member(
if (
what == "module" # pylint: disable=too-many-boolean-expressions
or (
what == "package"
and obj.short_name not in _package_set # pyright: ignore [reportUnknownMemberType]
what == "package" and obj.short_name not in _package_set # pyright: ignore [reportUnknownMemberType]
)
or f"{os.path.sep}commands{os.path.sep}" in obj.pathname
or obj.pathname.endswith(f"{os.path.sep}commands")
Expand Down
4 changes: 1 addition & 3 deletions examples/miscellaneous/custom_device_driver_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def custom_method(self, value: str) -> None:
# Add a scope that is currently supported by the package
mso5: MSO5 = device_manager.add_scope("192.168.0.1") # pyright: ignore[reportGeneralTypeIssues]
# Add the custom scope
custom_scope: CustomScope = device_manager.add_scope(
"192.168.0.2"
) # pyright: ignore[reportGeneralTypeIssues]
custom_scope: CustomScope = device_manager.add_scope("192.168.0.2") # pyright: ignore[reportGeneralTypeIssues]

# Custom drivers inherit all methods
custom_scope.expect_esr(0) # check for no errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
device_manager.visa_library = PYVISA_PY_BACKEND

# Creating one 7K/70K/SX Scope driver object by providing ip address.
scope: MSO70KDX = device_manager.add_scope(
"127.0.0.1"
) # pyright: ignore[reportGeneralTypeIssues]
scope: MSO70KDX = device_manager.add_scope("127.0.0.1") # pyright: ignore[reportGeneralTypeIssues]

# Starting DPOJET
scope.commands.dpojet.activate.write()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

# Main code starts here with instantiation of the device manager and the SMU instrument connection.
devmgr = DeviceManager(verbose=True)
smu2400: SMU2450 = devmgr.add_smu(
"192.168.0.1", alias="my2450"
) # pyright: ignore[reportGeneralTypeIssues]
smu2400: SMU2450 = devmgr.add_smu("192.168.0.1", alias="my2450") # pyright: ignore[reportGeneralTypeIssues]
smu2400.enable_verification = False

# Capture the path to the script file and load it to working memory.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
from tm_devices.drivers import SMU2450

with DeviceManager(verbose=False) as device_manager:
inst: SMU2450 = device_manager.add_smu(
"192.168.1.4", alias="my2450"
) # pyright: ignore[reportGeneralTypeIssues]
inst: SMU2450 = device_manager.add_smu("192.168.1.4", alias="my2450") # pyright: ignore[reportGeneralTypeIssues]

# Reset the instrument, which also clears the buffer.
inst.commands.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
with DeviceManager() as device_manager:
print(device_manager.get_available_devices())

inst: SMU2450 = device_manager.add_smu(
"192.168.4.74", alias="my2450"
) # pyright: ignore[reportGeneralTypeIssues]
inst: SMU2450 = device_manager.add_smu("192.168.4.74", alias="my2450") # pyright: ignore[reportGeneralTypeIssues]

# Configure the Simple Loop trigger model template to make 100 readings.
inst.commands.trigger.model.load_simple_loop(100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
with DeviceManager() as device_manager:
print(device_manager.get_available_devices())

inst: SMU2450 = device_manager.add_smu(
"192.168.4.74", alias="my2450"
) # pyright: ignore[reportGeneralTypeIssues]
inst: SMU2450 = device_manager.add_smu("192.168.4.74", alias="my2450") # pyright: ignore[reportGeneralTypeIssues]

# Clear the buffer.
inst.commands.buffer_var["defbuffer1"].clear()
Expand Down
4 changes: 1 addition & 3 deletions examples/source_measure_units/2400/smu_2450_solar_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
with DeviceManager() as device_manager:
print(device_manager.get_available_devices())

inst: SMU2450 = device_manager.add_smu(
"192.168.4.74", alias="my2450"
) # pyright: ignore[reportGeneralTypeIssues]
inst: SMU2450 = device_manager.add_smu("192.168.4.74", alias="my2450") # pyright: ignore[reportGeneralTypeIssues]

# Define the number of points in the sweep.
POINTS = 56
Expand Down
3 changes: 2 additions & 1 deletion examples/source_measure_units/2400/smu_2460_pulse_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
inst.commands.trigger.model.setblock_trigger_block_wait(3, "trigger.EVENT_TIMER1")
inst.commands.trigger.model.setblock_trigger_block_config_recall(4, "OutputList")
inst.commands.trigger.model.setblock_trigger_block_delay_constant(
5, MEASURE_DELAY # type: ignore
5,
MEASURE_DELAY, # type: ignore
)
inst.commands.trigger.model.setblock_trigger_block_measure_digitize(6)
inst.commands.trigger.model.setblock_trigger_block_wait(7, "trigger.EVENT_TIMER2")
Expand Down
4 changes: 1 addition & 3 deletions examples/source_measure_units/2400/smu_2461_1kw_pulsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
with DeviceManager() as device_manager:
print(device_manager.get_available_devices())

smu2461: SMU2461 = device_manager.add_smu(
"TCPIP::0.0.0.0::inst0::INSTR", alias="my2461"
) # pyright: ignore[reportGeneralTypeIssues]
smu2461: SMU2461 = device_manager.add_smu("TCPIP::0.0.0.0::inst0::INSTR", alias="my2461") # pyright: ignore[reportGeneralTypeIssues]

# Reset the instrument
smu2461.commands.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
from tm_devices.drivers import SMU2470

with DeviceManager(verbose=False) as device_manager:
smu2470: SMU2470 = device_manager.add_smu(
"TCPIP::0.0.0.0::inst0::INSTR", alias="my2470"
) # pyright: ignore[reportGeneralTypeIssues]
smu2470: SMU2470 = device_manager.add_smu("TCPIP::0.0.0.0::inst0::INSTR", alias="my2470") # pyright: ignore[reportGeneralTypeIssues]

# Reset the instrument, which also clears the buffer.
smu2470.commands.reset()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

with DeviceManager() as device_manager:
# Create a SMU and type hint it as a 2601B
smu: SMU2601B = device_manager.add_smu(
"192.168.0.1"
) # pyright: ignore[reportGeneralTypeIssues]
smu: SMU2601B = device_manager.add_smu("192.168.0.1") # pyright: ignore[reportGeneralTypeIssues]

# Create a buffer
BUFFER_NAME = "mybuffer"
Expand Down
20 changes: 4 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ requires = ["poetry-core>=1.0.0"]

[tool]

[tool.bandit]
skips = [
'B101', # allow the use of raw asserts, we don't compile to optimized byte code
'B404' # allow the use of the subprocess module
]

[tool.black]
line-length = 100

[tool.coverage.report]
exclude_lines = [
"if TYPE_CHECKING:",
Expand All @@ -38,9 +29,6 @@ recursive = true
wrap-descriptions = 100
wrap-summaries = 0

[tool.mypy]
mypy_path = "./src/"

[tool.poetry]
authors = [
"Tektronix <[email protected]>",
Expand Down Expand Up @@ -100,7 +88,6 @@ zeroconf = ">=0.54.0"

# Development dependencies
[tool.poetry.group.dev.dependencies]
black = ">=22.6.0"
coverage = {extras = ["toml"], version = ">=7.2.2"}
docformatter = {extras = ["tomli"], version = ">=1.6.5,<1.7.1"} # upper bound is due to https://github.com/PyCQA/docformatter/issues/174
flask = ">=2.2.2"
Expand All @@ -123,7 +110,7 @@ pytest-html = ">=4.0"
pytest-order = ">=1.0.1"
pytest-profiling = ">=1.7.0"
python-semantic-release = ">=8.0"
ruff = ">=0.1.4"
ruff = ">=0.1.7"
safety = ">=2.1.1"
sphinx-autoapi = ">=2.0.0"
sphinx-copybutton = ">=0.5.1"
Expand Down Expand Up @@ -288,6 +275,7 @@ ignore = [
"FA100", # Missing `from __future__ import annotations`, but uses ... # TODO: enable this later
"FBT", # flake8-boolean-trap
"FIX002", # Line contains TODO
"ISC001", # single-line-implicit-string-concatenation (handled by formatter)
"PGH003", # Use specific rule codes when ignoring type issues # TODO: enable this later
"PTH", # flake8-use-pathlib # TODO: enable this later
"PYI021", # Docstrings should not be included in stubs
Expand Down Expand Up @@ -416,13 +404,13 @@ deps =
setenv =
DOC_PYTHON_VERSION = python3.11 # Keep this in sync with .readthedocs.yml and any CI scripts
# Skip pre-commit checks that are explicitly performed by tox
SKIP = black,docformatter,ruff,pylint,pyright,pyright-verifytypes,pyroma
SKIP = ruff-format,docformatter,ruff,pylint,pyright,pyright-verifytypes,pyroma
PYRIGHT_PYTHON_GLOBAL_NODE = False # This will cause python-pyright to use nodeenv to install node rather than use the system node
commands_pre =
poetry install --no-root
commands =
!tests: safety check
!tests: black --check --diff --color .
!tests: ruff format --check --diff .
!tests: docformatter --check --diff .
!tests: ruff check .
!tests: pylint --report=y .
Expand Down
8 changes: 6 additions & 2 deletions src/tm_devices/commands/_smu2601b_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,9 @@ def pulse_i_measure_v(
f"PulseIMeasureV({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function."
)
raise NoDeviceProvidedError(msg) from error

def pulse_v_measure_i(
Expand Down Expand Up @@ -2063,7 +2065,9 @@ def pulse_v_measure_i(
f"PulseVMeasureI({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function."
)
raise NoDeviceProvidedError(msg) from error

def query_pulse_config(self, tag: int) -> str:
Expand Down
8 changes: 6 additions & 2 deletions src/tm_devices/commands/_smu2602b_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,9 @@ def pulse_i_measure_v(
f"PulseIMeasureV({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function."
)
raise NoDeviceProvidedError(msg) from error

def pulse_v_measure_i(
Expand Down Expand Up @@ -2169,7 +2171,9 @@ def pulse_v_measure_i(
f"PulseVMeasureI({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function."
)
raise NoDeviceProvidedError(msg) from error

def query_pulse_config(self, tag: int) -> str:
Expand Down
8 changes: 6 additions & 2 deletions src/tm_devices/commands/_smu2604b_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1917,7 +1917,9 @@ def pulse_i_measure_v(
f"PulseIMeasureV({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function."
)
raise NoDeviceProvidedError(msg) from error

def pulse_v_measure_i(
Expand Down Expand Up @@ -1951,7 +1953,9 @@ def pulse_v_measure_i(
f"PulseVMeasureI({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function."
)
raise NoDeviceProvidedError(msg) from error

def query_pulse_config(self, tag: int) -> str:
Expand Down
8 changes: 6 additions & 2 deletions src/tm_devices/commands/_smu2606b_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,9 @@ def pulse_i_measure_v(
f"PulseIMeasureV({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function."
)
raise NoDeviceProvidedError(msg) from error

def pulse_v_measure_i(
Expand Down Expand Up @@ -2136,7 +2138,9 @@ def pulse_v_measure_i(
f"PulseVMeasureI({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function."
)
raise NoDeviceProvidedError(msg) from error

def query_pulse_config(self, tag: int) -> str:
Expand Down
8 changes: 6 additions & 2 deletions src/tm_devices/commands/_smu2611b_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2026,7 +2026,9 @@ def pulse_i_measure_v(
f"PulseIMeasureV({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function."
)
raise NoDeviceProvidedError(msg) from error

def pulse_v_measure_i(
Expand Down Expand Up @@ -2060,7 +2062,9 @@ def pulse_v_measure_i(
f"PulseVMeasureI({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function."
)
raise NoDeviceProvidedError(msg) from error

def query_pulse_config(self, tag: int) -> str:
Expand Down
8 changes: 6 additions & 2 deletions src/tm_devices/commands/_smu2612b_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,7 +2132,9 @@ def pulse_i_measure_v(
f"PulseIMeasureV({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseIMeasureV()`` function."
)
raise NoDeviceProvidedError(msg) from error

def pulse_v_measure_i(
Expand Down Expand Up @@ -2166,7 +2168,9 @@ def pulse_v_measure_i(
f"PulseVMeasureI({smu}, {bias}, {level}, {ton}, {toff}, {points})"
)
except AttributeError as error:
msg = "No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function." # noqa: E501
msg = (
"No TSPDevice object was provided, unable to run the ``PulseVMeasureI()`` function."
)
raise NoDeviceProvidedError(msg) from error

def query_pulse_config(self, tag: int) -> str:
Expand Down
Loading

0 comments on commit 36b9518

Please sign in to comment.