From 13c9273d4d182bb865a08d9a88b1c5837c886c7b Mon Sep 17 00:00:00 2001 From: Peter Kraus Date: Sun, 31 Mar 2024 18:07:49 +0200 Subject: [PATCH] Move linting to ruff. (#140) * Ruff. * test commit to see linter fail. * add format check * Test 2 * Remove setup.cfg and fix text_xrdtrace * Tidy up devdocs. --- .github/workflows/lint-every-pr.yml | 12 +++--------- docs/source/devdocs.rst | 19 +++++-------------- pyproject.toml | 2 ++ setup.cfg | 3 --- src/yadg/dgutils/pintutils.py | 2 +- src/yadg/extractors/fhimcpt/csv.py | 1 - 6 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 setup.cfg diff --git a/.github/workflows/lint-every-pr.yml b/.github/workflows/lint-every-pr.yml index 04b5962c..52a927a2 100644 --- a/.github/workflows/lint-every-pr.yml +++ b/.github/workflows/lint-every-pr.yml @@ -8,13 +8,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 + - uses: chartboost/ruff-action@v1 with: - fetch-depth: 0 - - uses: github/super-linter/slim@v4 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DEFAULT_BRANCH: master - VALIDATE_ALL_CODEBASE: false - VALIDATE_PYTHON_BLACK: true - VALIDATE_PYTHON_FLAKE8: true - VALIDATE_PYTHON_PYLINT: true \ No newline at end of file + args: "format --check" \ No newline at end of file diff --git a/docs/source/devdocs.rst b/docs/source/devdocs.rst index 3ef6843f..48ff464f 100644 --- a/docs/source/devdocs.rst +++ b/docs/source/devdocs.rst @@ -1,7 +1,7 @@ Developer documentation ----------------------- -The project follows fairly standard developer practices. Every new feature should be associated with a test, and every PR requires linting using ``flake8`` and formatting using ``black``. +The project follows fairly standard developer practices. Every new feature should be associated with a test, and every PR requires linting and formatting using ``ruff``. Testing ``````` @@ -11,23 +11,14 @@ If a new test requires additional data (input files, schemas, etc.), they can be Formatting `````````` -All files should be formatted by ``black``. Lines containing text fields, including docstrings, should be between 80-88 characters in length. Imports of functions should be absolute, that is including the ``yadg.`` prefix. +All files should be formatted by ``ruff format``. Lines containing text fields, including docstrings, should be between 80-88 characters in length. Imports of functions should be absolute, that is including the ``yadg.`` prefix. Implementing new features `````````````````````````` -**New parsers** should be implemented by: +**New extractors** should be implemented by: - adding their schema into :class:`dgbowl_schemas.yadg.dataschema.DataSchema` -- adding their implementation in a separate Python package under :mod:`yadg.parsers` +- adding their implementation in a separate Python package under :mod:`yadg.extractors` -Each `parser` should be documented by adding a structured docstring into the ``__init__.py`` file of each new sub-module of :mod:`yadg.parsers`. This documentation should describe the application and usage of the `parser`, and refer to the Pydantic audotocs via :class:`~dgbowl_schemas.yadg.dataschema.DataSchema` to discuss the features exposed via the parameters dictionary. Generally, code implementing the parsing of specific `filetypes` should be kept separate from the main `parser` function in the module. - -**New filetypes** should be implemented as sub-modules of their `parser`. They should be documented using a top-level docstring in the relevant sub-module. If the `filetype` is binary, a description of the file structure should be provided in the docstring. Every new `filetype` will have to be added into the :mod:`~dgbowl_schemas.yadg.dataschema.filetype` module as well. - -**New extractors** can be registered using a shim in the :mod:`yadg.extractors` module, referring to the `filetype`. The ``__init__.py`` of each `extractor` should expose: - -- an :func:`extract` function which returns an :class:`xarray.Dataset`, -- a :class:`set` named :obj:`supports`, enumerating all `filetypes` that can be extracted by the new `extractor.` - -Note that a new `extractor` requires its `filetype` to be added in the :mod:`~dgbowl_schemas.yadg.dataschema.filetype` module as well. \ No newline at end of file +Each extractor should be documented by adding a structured docstring at the top of the file. This documentation should describe the application and usage of the extractor, and refer to the Pydantic audotocs via :obj:`~dgbowl_schemas.yadg.dataschema` to discuss the features exposed via the parameters dictionary. If the filetype extracted is binary, a description of the file structure should be provided in the docstring. Every new filetype will have to be added into the :mod:`~dgbowl_schemas.yadg.dataschema.filetype` module as well. \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 62dc678f..f7b3a1db 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,3 +60,5 @@ yadg = "yadg:run_with_arguments" enabled = true dev_template = "{tag}.dev{ccount}" dirty_template = "{tag}.dev{ccount}" + +[tool.ruff] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index e0ea542f..00000000 --- a/setup.cfg +++ /dev/null @@ -1,3 +0,0 @@ -[flake8] -max-line-length = 88 -extend-ignore = E203 \ No newline at end of file diff --git a/src/yadg/dgutils/pintutils.py b/src/yadg/dgutils/pintutils.py index 99d1b245..aabb50cb 100644 --- a/src/yadg/dgutils/pintutils.py +++ b/src/yadg/dgutils/pintutils.py @@ -49,7 +49,7 @@ def _sanitize_helper(unit: str) -> str: def sanitize_units( - units: Union[str, dict[str, str], list[str]] + units: Union[str, dict[str, str], list[str]], ) -> Union[str, dict[str, str], list[str]]: """ Unit sanitizer. diff --git a/src/yadg/extractors/fhimcpt/csv.py b/src/yadg/extractors/fhimcpt/csv.py index f61c66d1..008ab57e 100644 --- a/src/yadg/extractors/fhimcpt/csv.py +++ b/src/yadg/extractors/fhimcpt/csv.py @@ -61,7 +61,6 @@ def extract( parameters: BaseModel, **kwargs: dict, ) -> Dataset: - with open(fn, "r", encoding=encoding) as infile: lines = [i.strip() for i in infile.readlines()]