r/learnpython • • 1d ago

How do you centralize tool configurations (ty, ruff, pytest, ...) between multiple repositories?

In our software department we have a few dozen python libraries that different teams maintain, some open source, some closed source. I'm trying to centralize commonalities between them so that all pipelines run the same stages, that all pre-commit hooks are the same, and so on. I got most of it working, except that I don't have a good way to centralize configurations. For example I want all repos to use a common set of ruff linter rules, all documentation builds to use the same template and plugins, pin the most of the [dev] dependencies to the same versions..

Was wondering if anyone has experience with this :) I've been back and forth with Claude for quite a while, but I wasn't a fan of its ideas (using templates, copier, custom scripts, monorepo)

6 Upvotes

16 comments sorted by

3

u/SCD_minecraft 1d ago

Solution for that i saw (but not used personally) is monorepo

Basically, multiple repositories in one acual repository plus some dedicated tool to manage that

1

u/Baner-Fournadet 7h ago

does that still work well when half the repos are public and the other half are private though?

3

u/seanv507 1d ago

Would submodules help?

1

u/duane11583 1d ago

I hate submodules very much but am sort of forced to use them 

1

u/neural_dataops 1d ago

Since you want to avoid a monorepo and template drift across dozens of repos, the cleanest native pattern in Python is publishing a lightweight internal meta-package (like company-dev-tools) to your private PyPI or artifact registry.

Put ruff, ty, pytest, and pre-commit with exact pinned versions inside that meta-package's pyproject.toml. Every repo then declares just a single dev dependency on company-dev-tools, so Renovate or Dependabot updates all of them across every repo with one version bump.

For sharing Ruff and docs configs without copying files around, Ruff supports extend in pyproject.toml. You can either ship a base ruff.toml inside your internal wheel and point repos to it, or use a reusable CI workflow (GitHub Actions or GitLab CI) that injects the central ruff.toml and Sphinx/MkDocs config at pipeline runtime while still letting individual repos override specific rules locally. For pre-commit, pointing repo in .pre-commit-config.yaml to an internal pre-commit-hooks git tag lets you update hook versions everywhere with a standard pre-commit autoupdate PR.

Which CI platform are you running? That usually decides whether injecting configs in the CI pipeline or bundling them inside the dev wheel feels cleaner.

2

u/PhilosopherNext1448 1d ago

We have repos both on gitlab and github (we collaborate a lot with other companies/institutes). The extends keyword from ruff.toml only works with local paths, no? Then i'm not sure how to point to specific wheels.

2

u/neural_dataops 1d ago

Good catch, Ruff's extend only accepts local file paths, not package imports directly. If you ship ruff.base.toml inside your internal wheel, every repo can run a one-line pre-build/CI step (or Makefile target) to resolve its path inside the active virtual environment and pass --config directly.  The other option that works identically across both GitHub Actions and GitLab CI without touching local pyproject.toml paths is putting the base ruff.toml in a central public/internal Git repo and having CI pull it down or pass --config at lint time, while keeping a thin local ruff.toml in each repo for project-specific overrides.

2

u/Atmosck 1d ago

At my company we technically allow different projects to have different configurations, but we have an internal CLI tool with a command for setting up projects that creates a standardized pyproject.toml with ruff+ty+pytest configuration, among other things (like a standard dockerfile, makefile with a setup command that includes pre-commit hooks, and terraform changes). The configuration that sets up only gets changed on a per-project basis if there's a good reason.

We're not super concerned about keeping linting rules in sync - maintainers have some freedom to set rules for their own code. But this does include somethings we do care about standardizing, like our exclude-newer policy for dependencies, and well-optimized dockerfiles.

1

u/duane11583 1d ago

We check them into a sub git module if the app

And we create virtual envs via a script in a very automated way

All of this is checked into git

When any checks out  the top level project out they must run a setup script that does the basic project setup including the venv setup

That process also creates an env var called PROJ_ROOT_DIR that points at the top of the project

The python venv and the env file lives at the root of the project

Simplifies many things 

1

u/brocketships 1d ago

Template repository using Copier. Versioned releases propagate changed into users of the template using Renovate.

•

u/HallucinationDr 31m ago

We went with a shared config repo and each project extends it. Ruff has `extend` in pyproject so base rules live in one place, then a bot opens bump PRs. Monorepo would be simpler honestly but nobody ever agrees to that.

0

u/Due-Mortgage-6854 1d ago

publish a company-dev-tools meta-package

  • pin ruff, ty, pytest, and your doc plugins to their exact versions inside this single package.

  • every repo just adds company-dev-tools to its dev dependencies, then bumping one version updates the whole toolchain everywhere.

2

u/PhilosopherNext1448 1d ago

That solves pinning the dependencies, but how can we centralize the configurations as well?

2

u/Due-Mortgage-6854 1d ago

you can bundle your ruff.toml, ty.toml, and pytest.ini as package data inside company-dev-tools, then expose thin CLI entrypoints (company-lint, company-typecheck, company-test) that resolve those files via importlib.resources and pass --config / --config-file / -c under the hood

as for ur IDE support, add a company-sync-configs command in the package that copies the base configs into the repo root (and lets local ruff.toml use extend if a repo needs overrides).

i didnt experiment much on these but you can find more on google