From 638d3024cad73f06251e8f0b902730daa8cf5eb2 Mon Sep 17 00:00:00 2001 From: Spencer Chang Date: Sat, 25 Feb 2023 11:30:31 -0800 Subject: [PATCH] add pre-commit to project --- .flake8 | 2 - .gitignore | 2 +- .pre-commit-config.yaml | 24 ++++++++++ COPYING | 2 +- MANIFEST.in | 1 - README.md | 4 +- cocotbext/spi/spi.py | 2 +- pyproject.toml | 46 +++++++------------ tests/spi/Makefile | 2 +- tests/spi/test_spi.py | 2 +- tests/spi_devices/TI/ads8028/Makefile | 2 +- tests/spi_devices/TI/ads8028/test_ads8028.v | 2 +- tests/spi_devices/TI/drv8304/Makefile | 2 +- tests/spi_devices/TI/drv8304/test_drv8304.py | 1 - tests/spi_devices/TI/drv8304/test_drv8304.v | 2 +- tests/spi_devices/Trinamic/tmc4671/Makefile | 2 +- .../Trinamic/tmc4671/test_tmc4671.v | 2 +- tox.ini | 29 ++++++++++++ 18 files changed, 84 insertions(+), 45 deletions(-) delete mode 100644 .flake8 create mode 100644 .pre-commit-config.yaml create mode 100644 tox.ini diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 79a16af..0000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -max-line-length = 120 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7637166..b0e3975 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ tests/**/.pytest_cache *~ cocotbext/spi/_version.py -.pdm.toml \ No newline at end of file +.pdm.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..31c2d7b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,24 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: debug-statements +- repo: https://github.com/PyCQA/flake8 + rev: 6.0.0 + hooks: + - id: flake8 +- repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade + args: [--py37-plus] +- repo: https://github.com/tox-dev/pyproject-fmt + rev: "0.8.0" + hooks: + - id: pyproject-fmt diff --git a/COPYING b/COPYING index 73ab4a6..69a9cbd 100644 --- a/COPYING +++ b/COPYING @@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/MANIFEST.in b/MANIFEST.in index a18c999..8f72694 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,3 @@ include LICENSE include README.md recursive-include tests Makefile test_*.py test_*.v - diff --git a/README.md b/README.md index aa2f51f..538fdd5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # SPI Interface for Cocotb [![Regression Tests](https://github.com/schang412/cocotbext-spi/actions/workflows/regression-tests.yml/badge.svg)](https://github.com/schang412/cocotbext-spi/actions/workflows/regression-tests.yml) +[![pdm-managed](https://img.shields.io/badge/pdm-managed-blueviolet)](https://pdm.fming.dev) +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) GitHub repository: https://github.com/schang412/cocotbext-spi @@ -62,7 +64,7 @@ spi_config = SpiConfig( cpol = False, # clock idle polarity cpha = True, # clock phase (CPHA=True means data sampled on second edge) msb_first = True, # the order that bits are clocked onto the wire - data_output_idle = 1, # the idle value of the MOSI or MISO line + data_output_idle = 1, # the idle value of the MOSI or MISO line frame_spacing_ns = 1, # the spacing between frames that the master waits for or the slave obeys # the slave should raise SpiFrameError if this is not obeyed. ignore_rx_value = None # MISO value that should be ignored when received diff --git a/cocotbext/spi/spi.py b/cocotbext/spi/spi.py index a396d8d..8aab6ae 100644 --- a/cocotbext/spi/spi.py +++ b/cocotbext/spi/spi.py @@ -86,7 +86,7 @@ def __init__(self, signals, config): self._sclk.setimmediatevalue(int(self._config.cpol)) self._mosi.setimmediatevalue(self._config.data_output_idle) - self._cs.setimmediatevalue((1 if self._cs_active_low else 0)) + self._cs.setimmediatevalue(1 if self._cs_active_low else 0) self._SpiClock = _SpiClock(signal=self._sclk, period=(1 / self._config.sclk_freq), diff --git a/pyproject.toml b/pyproject.toml index 8d40e15..5b92b1c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,20 @@ [build-system] -requires = ["setuptools>=61", "wheel", "setuptools_scm[toml]>=6.2"] build-backend = "setuptools.build_meta" +requires = [ + "setuptools>=61", + "setuptools_scm[toml]>=6.2", + "wheel", +] [project] name = "cocotbext-spi" description = "SPI modules for cocotb" +readme = "README.md" +license = {text = "MIT"} authors = [ {name = "Spencer Chang", email = "spencer@sycee.xyz"}, ] -dependencies = [ - "cocotb>=1.6", -] +requires-python = ">=3.7" classifiers = [ "Development Status :: 3 - Alpha", "Programming Language :: Python :: 3", @@ -18,10 +22,15 @@ classifiers = [ "Operating System :: OS Independent", "Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)", ] -requires-python = ">=3.7" -readme = "README.md" -license = {text = "MIT"} -dynamic = ["version"] +dynamic = [ + "version", +] +dependencies = [ + "cocotb>=1.6", +] +[project.urls] +repository = "https://github.com/schang412/cocotbext-spi" + [tool.setuptools_scm] write_to = "cocotbext/spi/_version.py" @@ -32,27 +41,6 @@ testpaths = [ ] addopts = "--import-mode importlib" -[tool.tox] -legacy_tox_ini = """ -[tox] -isolated_build = true -envlist = py{37,38,39},lint - -[testenv] -setenv = - PDM_IGNORE_SAVED_PYTHON="1" -deps = pdm -commands = - pdm install --dev - pytest tests -n auto - -[testenv:lint] -deps = pdm -commands = - pdm install -G lint - flake8 cocotbext/ tests/ -""" - [tool.pdm] [tool.pdm.dev-dependencies] test = [ diff --git a/tests/spi/Makefile b/tests/spi/Makefile index 3694413..de73674 100644 --- a/tests/spi/Makefile +++ b/tests/spi/Makefile @@ -35,4 +35,4 @@ iverilog_dump.v: clean:: @rm -rf iverilog_dump.v @rm -rf dump.fst $(TOPLEVEL).fst - @rm -rf results.xml \ No newline at end of file + @rm -rf results.xml diff --git a/tests/spi/test_spi.py b/tests/spi/test_spi.py index 7055012..959e9bf 100644 --- a/tests/spi/test_spi.py +++ b/tests/spi/test_spi.py @@ -91,7 +91,7 @@ async def run_test(dut, payload_lengths, payload_data, word_width=16, spi_mode=1 filtered_sink = [sink_content] if sink_content != ignore_rx_value else [] tb.log.info("Read data: %s", ','.join(['0x%02x' % x for x in rx_data])) - tb.log.info("In register: 0x{:02x}".format(sink_content)) + tb.log.info(f"In register: 0x{sink_content:02x}") assert list(rx_data[1:]) + filtered_sink == filtered_test_data await Timer(100, 'us') diff --git a/tests/spi_devices/TI/ads8028/Makefile b/tests/spi_devices/TI/ads8028/Makefile index 9cc2e4b..ff161ba 100644 --- a/tests/spi_devices/TI/ads8028/Makefile +++ b/tests/spi_devices/TI/ads8028/Makefile @@ -35,4 +35,4 @@ iverilog_dump.v: clean:: @rm -rf iverilog_dump.v @rm -rf dump.fst $(TOPLEVEL).fst - @rm -rf results.xml \ No newline at end of file + @rm -rf results.xml diff --git a/tests/spi_devices/TI/ads8028/test_ads8028.v b/tests/spi_devices/TI/ads8028/test_ads8028.v index e4744d4..1b71ba0 100644 --- a/tests/spi_devices/TI/ads8028/test_ads8028.v +++ b/tests/spi_devices/TI/ads8028/test_ads8028.v @@ -8,4 +8,4 @@ module test_ads8028 inout wire ncs ); -endmodule // test_ads8028 \ No newline at end of file +endmodule // test_ads8028 diff --git a/tests/spi_devices/TI/drv8304/Makefile b/tests/spi_devices/TI/drv8304/Makefile index e817261..21d96b7 100644 --- a/tests/spi_devices/TI/drv8304/Makefile +++ b/tests/spi_devices/TI/drv8304/Makefile @@ -35,4 +35,4 @@ iverilog_dump.v: clean:: @rm -rf iverilog_dump.v @rm -rf dump.fst $(TOPLEVEL).fst - @rm -rf results.xml \ No newline at end of file + @rm -rf results.xml diff --git a/tests/spi_devices/TI/drv8304/test_drv8304.py b/tests/spi_devices/TI/drv8304/test_drv8304.py index 98623a9..f4bf0c1 100644 --- a/tests/spi_devices/TI/drv8304/test_drv8304.py +++ b/tests/spi_devices/TI/drv8304/test_drv8304.py @@ -1,4 +1,3 @@ - """ Copyright (c) 2021 Spencer Chang diff --git a/tests/spi_devices/TI/drv8304/test_drv8304.v b/tests/spi_devices/TI/drv8304/test_drv8304.v index 4e83cde..22ca99f 100644 --- a/tests/spi_devices/TI/drv8304/test_drv8304.v +++ b/tests/spi_devices/TI/drv8304/test_drv8304.v @@ -8,4 +8,4 @@ module test_drv8304 inout wire ncs ); -endmodule // test_drv8304 \ No newline at end of file +endmodule // test_drv8304 diff --git a/tests/spi_devices/Trinamic/tmc4671/Makefile b/tests/spi_devices/Trinamic/tmc4671/Makefile index 805026e..d65ec48 100644 --- a/tests/spi_devices/Trinamic/tmc4671/Makefile +++ b/tests/spi_devices/Trinamic/tmc4671/Makefile @@ -35,4 +35,4 @@ iverilog_dump.v: clean:: @rm -rf iverilog_dump.v @rm -rf dump.fst $(TOPLEVEL).fst - @rm -rf results.xml \ No newline at end of file + @rm -rf results.xml diff --git a/tests/spi_devices/Trinamic/tmc4671/test_tmc4671.v b/tests/spi_devices/Trinamic/tmc4671/test_tmc4671.v index fc6a724..ee58601 100644 --- a/tests/spi_devices/Trinamic/tmc4671/test_tmc4671.v +++ b/tests/spi_devices/Trinamic/tmc4671/test_tmc4671.v @@ -8,4 +8,4 @@ module test_tmc4671 inout wire ncs ); -endmodule // test_tmc4671 \ No newline at end of file +endmodule // test_tmc4671 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..42d6663 --- /dev/null +++ b/tox.ini @@ -0,0 +1,29 @@ +[tox] +isolated_build = true +envlist = py{37,38,39},lint,check-dist + +[flake8] +max-line-length = 120 + +[testenv] +setenv = + PDM_IGNORE_SAVED_PYTHON="1" +deps = pdm +commands = + pdm install --dev + pytest tests -n auto + +[testenv:lint] +deps = pdm +commands = + pdm install -G lint + flake8 cocotbext/ tests/ + +[testenv:check-dist] +skip_install = true +deps = + pdm + twine +commands = + pdm build + twine check dist/*