Giter VIP home page Giter VIP logo

ruff-sync's Introduction

codecov pre-commit.ci status Wily Ruff

ruff-sync

CLI tool for keeping multiple project in sync with a single ruff config.

Quick start

VCS Install

pip install git+https://github.com/Kilo59/ruff-sync

Or with pipx (recommended for isolated installations)

pipx install git+https://github.com/Kilo59/ruff-sync
$ ruff-sync --help
usage: ruff-sync [-h] [--source SOURCE] [--exclude EXCLUDE [EXCLUDE ...]] upstream

positional arguments:
  upstream              The URL to download the pyproject.toml file from.

optional arguments:
  -h, --help            show this help message and exit
  --source SOURCE       The directory to sync the pyproject.toml file to. Default: .
  --exclude EXCLUDE [EXCLUDE ...]
                        Exclude certain ruff configs. Default: per-file-ignores

ruff-sync's People

Contributors

dependabot[bot] avatar dustinbowers avatar kilo59 avatar pre-commit-ci[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

ruff-sync's Issues

Work for `ruff.toml`

Currently ruff-sync expects all config files to be pyproject.toml, ruff.toml is not supported.

Either file should work.

Fix Whitespace Issues

Updated to pypoject.toml introduces extra whitespace and/or remove too much whitespace.

[tool.ruff]
target-version = "py310"
line-length = 120
lint.select = ["F", "ASYNC", "RUFF", "B", "S", "PTH", "W", "E"]
lint.ignore = ["W191", "E111"]
# 1 too many newlines


[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
    "F401", # unused import
    "F403", # star imports
] # should be a newline after this table
[tool.coverage.run]
include = [
    "foo.py",
    "bar.py"
    ]

This is almost certainly introduced by trying to operate on individual Table items and then re-inserting them into the TOMLDocument rather than always just operating on the full document.
See get_ruff_tool_table() & merge_ruff_toml().

Pull config from ` tool.ruff-sync` `pyproject.toml`

Allow ruff-sync to pull upstream & exclude parameters from a pyproject.toml section.

Implementation Notes

I started this work by adding a get_config() method, but it isn't being used yet.
We would need to resolve the config pulled here with any CLI arguments and raise errors if any required arguments cannot be resolved.

ruff-sync/ruff_sync.py

Lines 45 to 61 in 791a3c3

@lru_cache(maxsize=1)
def get_config(
source: pathlib.Path,
) -> Mapping[Literal["upstream", "source", "exclude"], str | list[str]]:
local_toml = source / "pyproject.toml"
# TODO: use pydantic to validate the toml file
cfg_result = {}
if local_toml.exists():
toml = tomlkit.parse(local_toml.read_text())
config = toml.get("tool", {}).get("ruff-sync")
if config:
for arg, value in config.items():
if arg in Arguments.fields():
cfg_result[arg] = value
else:
warnings.warn(f"Unknown ruff-sync configuration: {arg}", stacklevel=2)
return cfg_result

Use pydantic_settings

If we don't care about pulling in extra dependences we should use the new pydantic_settings.TomlConfigSetttingSource base class for pulling and validating toml config.

https://docs.pydantic.dev/latest/api/pydantic_settings/#pydantic_settings.TomlConfigSettingsSource

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.