Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure and run taplo in CI for formatting .toml #646

Closed
dangotbanned opened this issue Dec 13, 2024 · 2 comments · Fixed by #647
Closed

Configure and run taplo in CI for formatting .toml #646

dangotbanned opened this issue Dec 13, 2024 · 2 comments · Fixed by #647

Comments

@dangotbanned
Copy link
Member

Originally posted by @dangotbanned in #643 (comment)

I should've explained this better in the description for (1ea2812)

That commit uses automatic formatting via taplo.
The two non-default configuration options applied were:

align_entries=true

Align entries vertically. Entries that have table headers, comments, or blank lines between them are not aligned.

allowed_blank_lines=1

The maximum amount of consecutive blank lines allowed.


taplo can be used via its CLI and as a VSCode extension (Even Better TOML)

I haven't used it in CI before, but it is available on PyPI - so we could run it with uvx?
https://github.com/tamasfe/taplo/blob/a8bc571ee28775e7d5ad84c2ea87cf5b61ab42f5/.github/workflows/releases.yaml#L503-L504

NPM is another option for install


@domoritz

If we have a formatter, it should run on the ci as well.

@domoritz
Copy link
Member

I haven't heard of it but sounds good. I'd recommend uvx since it's for python.

@dangotbanned
Copy link
Member Author

dangotbanned commented Dec 14, 2024

I haven't heard of it but sounds good. I'd recommend uvx since it's for python.

Great, that sounds like something I can take a stab at

@domoritz would it be worth opening a separate issue for a pyproject.toml?

I've been using one locally for ruff & pyright e.g. (2b1be70), (fbd1be5), (5e779e6)
It would probably be easier to manage uv as a project, and naturally provides a home for other tool configs

Local pyproject.toml

Based on https://github.com/vega/altair/blob/9002472d65875a8486de920e4cc585420efdd276/pyproject.toml#L198-L447

[project]
name = "vega-datasets"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
    "frictionless[json,parquet]>=5.18.0",
    "niquests>=3.11.2",
    "polars>=1.17.1",
]

[dependency-groups]
dev = ["ruff>=0.8.2"]

[tool.ruff]
target-version = "py312"
extend-exclude = [
    "scripts/budget.py",
    "scripts/flights.py",
    "scripts/github.py",
    "scripts/make-unemployment-across-industries.py",
    "scripts/update_countries_json.py",
    "scripts/update_gapminder.py",
    "scripts/weather.py",
    ".venv",
    # TEMPORARY
    # "scripts/build_datapackage.py",
]

[tool.ruff.format]
preview                    = true
docstring-code-format      = true
docstring-code-line-length = 88

[tool.ruff.lint]
preview = true
extend-safe-fixes = [
    # unnecessary-comprehension-in-call
    "C419",
    # unnecessary-dict-comprehension-for-iterable
    "C420",
    # literal-membership
    "PLR6201",
    # unsorted-dunder-all
    "RUF022",
    # trailing-whitespace
    "W291",
    # blank line contains whitespace
    "W293",
    # annotations #
    # ----------- #
    "ANN204",
    "TC",
    "UP006",
    "UP008",
    # pydocstyle #
    # ---------- #
    # fits-on-one-line
    "D200",
    # escape-sequence-in-docstring
    "D301",
    # ends-in-period
    "D400",
    # assign exception msg to variable #
    # -------------------------------- #
    "EM101",
    "EM102",
]
extend-select = [
    # root-logger-call
    "LOG015",
    # refurb
    "FURB",
    # pylint (preview) autofix #
    # ------------------------ #
    # unnecessary-dunder-call 
    "PLC2801",
    # unnecessary-dict-index-lookup
    "PLR1733",
    # unnecessary-list-index-lookup
    "PLR1736",
    # literal-membership
    "PLR6201",
    # unspecified-encoding
    "PLW1514",
]
select = [
    # flake8-annotations
    "ANN",
    # flake8-bugbear
    "B",
    # flake8-comprehensions
    "C4",
    # complex-structure
    "C901",
    # pydocstyle
    "D",
    # multi-line-summary-second-line
    "D213",
    # pycodestyle-error
    "E",
    # flake8-errmsg
    "EM",
    # pyflakes
    "F",
    # flake8-future-annotations
    "FA",
    # flynt
    "FLY",
    # logging-f-string
    "G004",
    # unsorted-imports
    "I001",
    # flake8-logging
    "LOG",
    # flake8-pie
    "PIE",
    # pylint (Convention)
    "PLC",
    # flake8-use-pathlib
    "PTH",
    # unnecessary-type-union
    "PYI055",
    # unnecessary-assign
    "RET504",
    # superfluous-else-return
    "RET505",
    # Ruff-specific rules
    "RUF",
    # flake8-simplify
    "SIM",
    # flake8-type-checking
    "TC",
    # flake8-tidy-imports
    "TID",
    # pyupgrade
    "UP",
    # pycodestyle-warning
    "W",
    # pylint (stable) autofix #
    # ----------------------- #
    # manual-from-import
    "PLR0402",
    # useless-return
    "PLR1711",
    # repeated-equality-comparison
    "PLR1714",
    # collapsible-else-if
    "PLR5501",
    # useless-else-on-loop
    "PLW0120",
    # subprocess-run-without-check
    "PLW1510",
    # nested-min-max
    "PLW3301",
]
ignore = [
    # Whitespace before ':'
    "E203",
    # Line too long
    "E501",
    # mutable-class-default
    "RUF012",
    # pydocstyle/ https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules #
    # ------------------------------------------------------------------------- #
    # undocumented-public-module
    "D100",
    # undocumented-public-class
    "D101",
    # undocumented-public-method  
    "D102",
    # undocumented-public-function  
    "D103",
    # undocumented-public-package   
    "D104",
    # undocumented-magic-method 
    "D105",
    # undocumented-public-init  
    "D107",
    # indent-with-spaces
    "D206",
    # multi-line-summary-first-line ((D213) is the opposite of this)
    "D212",
    # Imperative mood   
    "D401",
    # Blank line after last section 
    "D413",
    # doc-line-too-long
    "W505",
    # Any as annotation
    "ANN401",
]
pydocstyle = { convention = "numpy" }

[tool.ruff.lint.per-file-ignores]
"*/**/*.ipynb" = ["ANN", "F401", "W391"]
"*.ipynb"      = ["ANN", "F401", "W391"]

[tool.ruff.lint.isort]
extra-standard-library  = ["typing_extensions"]
split-on-trailing-comma = false

[tool.pyright]
enableExperimentalFeatures = true
include                    = ["./scripts/build_datapackage.py", "./scripts/flights2.py"]
ignore                     = [".venv", "../../../**/Lib"]
pythonPlatform             = "All"
pythonVersion              = "3.12"
reportUnusedExpression     = "none"
typeCheckingMode           = "basic"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants