Skip to content

modernize repo tooling: ruff, pre-commit, CI, ty (astral type checker), uv#272

Open
vlordier wants to merge 3 commits intoeasyw:masterfrom
vlordier:modernize-linting-ci
Open

modernize repo tooling: ruff, pre-commit, CI, ty (astral type checker), uv#272
vlordier wants to merge 3 commits intoeasyw:masterfrom
vlordier:modernize-linting-ci

Conversation

@vlordier
Copy link
Copy Markdown

@vlordier vlordier commented Apr 29, 2026

Summary

Modernise the repository toolchain with the astral-sh ecosystem (ruff, uv, ty), pre-commit hooks, and GitHub Actions CI.

How to review this PR

Commit What Size Review priority
c5307c6 Manual semantic fixes — SIM103, SIM115, PERF402, Copilot comments, dead code removal +1,520 / -2,755 (18 files) Start here
7cb8760 ruff format + auto-fixes — Pure formatting, no semantic changes +23,712 / -19,114 (23 files) ⬇️ Low (auto-generated)
97650dd Config files — pyproject.toml, pre-commit, CI, editorconfig +274 / -18 (8 files) ⭐ Review once

💡 Use git blame --ignore-revs-file .git-blame-ignore-revs to skip the formatting commit during blame.
💡 Append ?w=1 to the diff URL to hide whitespace in GitHub.

New files

File Purpose
pyproject.toml Ruff config (120 cols, py311, 20 rule sets), ty type checker, uv
.pre-commit-config.yaml Ruff lint/fix + ruff-format + ty + standard pre-commit hooks
.github/workflows/ci.yml 3 jobs: ruff lint + format, pre-commit, ty type check
.github/dependabot.yml Weekly auto-updates for GitHub Actions and pip
.editorconfig 4-space indent, LF, UTF-8
.git-blame-ignore-revs Records formatting commit hash for git blame --ignore-revs-file

Changes applied

Auto-fixes (commit 2 — formatting only)

ruff format + ruff check --fix: import sorting, f-strings, unicode prefix removal, trailing whitespace, useless semicolons, comprehension simplifications, trailing commas, collapsible else-if.

Semantic fixes (commit 3 — manual)

  • 5× SIM103: if cond: return True/Falsereturn cond
  • 1× SIM101: isinstance(x, A) or isinstance(x, B)isinstance(x, (A, B))
  • 11× PERF402: for x in y: list.append(x)list.extend(y) / list()
  • 7× SIM115: open()/close()with open() context manager
  • 5× SIM113: manual index counters → enumerate()
  • 5× UP031: %s printf-style → f-strings
  • 2× YTT201: == 3>= 3 for Python 4 compat
  • 1× TRY: logger.exception(f"...{ex}")logger.exception("...")
  • 3× RUF003: fix ambiguous unicode chars in comments
  • makefacedxf.py: re-encoded ISO-8859 → UTF-8

Copilot review fixes

  • TranslateUtils.py: define translate() fallback when FreeCAD has no Qt
  • Init.py: restore import FreeCAD (removed by ruff F401 pass)
  • commits_num.py: add import requests inside latestCommitInfo()
  • ZipStepImport.py / _DXF_Import.py: add from TranslateUtils import translate
  • makefacedxf.py: fix undefined f.Name in except Part.OCCError
  • explode.py: comment out dead/disconnected expression
  • utf8test.py: remove unreachable Python 2 dead code

Third-party submodules excluded

fcad_parser/ and dxf_parser/ (git submodules) are excluded from all tooling. The only change is a 2-line flake8 comment removal from dxf_parser/_importDXF.py.

Ruff rules still silenced (future cleanup)

Complexity (PLR09xx), magic numbers (PLR2004), globals (PLW06xx), line length (E501), bare except (E722), lazy imports (E402), star imports (F403/405), undefined names (F821), ambiguous var names (E741), private access (SLF001), print (T201).

Local dev workflow

uv tool install ruff pre-commit
pre-commit install
ruff check .
ruff format --check .
uvx ty check
pre-commit run --all-files

@vlordier vlordier changed the title modernize repo tooling: ruff, pre-commit, CI, pyright, uv modernize repo tooling: ruff, pre-commit, CI, ty (astral type checker), uv Apr 29, 2026
@vlordier vlordier marked this pull request as ready for review April 30, 2026 08:24
Copilot AI review requested due to automatic review settings April 30, 2026 08:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Modernizes the repository’s Python/tooling workflow around the Astral ecosystem (ruff/uv/ty), adding pre-commit and GitHub Actions CI, and applies broad automated formatting/cleanup across the codebase to align with the new tooling.

Changes:

  • Added pyproject.toml configuration for ruff (lint/format), uv, and ty.
  • Added pre-commit hooks, CI workflow, dependabot updates, and editor settings for consistent automation.
  • Applied repo-wide Python formatting/cleanup and adjusted various scripts/modules accordingly.

Reviewed changes

Copilot reviewed 34 out of 39 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
pyproject.toml Adds ruff/uv/ty configuration and excludes selected paths from lint/type analysis.
.pre-commit-config.yaml Adds ruff + standard pre-commit hooks.
.github/workflows/ci.yml Adds CI jobs for ruff lint/format, pre-commit, and ty.
.github/dependabot.yml Enables weekly Dependabot updates for actions and pip.
.editorconfig Standardizes editor defaults (indent, LF, UTF-8, trimming, etc.).
.gitattributes Enforces LF normalization and sets diff/binary attributes for common file types.
.gitignore Adds ignores for Python/tooling/editor caches.
utf8test.py Refactors string/encoding helpers and applies formatting (but introduces unreachable/py2-era remnants).
test-mb.py Formatting and minor import cleanup in test UI script.
step_amend.py Formatting and minor refactor of gzip/step transparency rewrite helper.
selection2edges.py Formatting and import cleanup; minor refactor of view-direction logic and placement operations.
makefacedxf.py Formatting + import cleanup; refactors DXF import paths and related logic.
ksu_locator.py Formatting and import cleanup.
hlp.py Formatting and import cleanup.
fcad_parser/test.py Formatting and modernization (but keeps an argparse filename indexing bug).
fcad_parser/sexp_parser/test.py Formatting and modernization (but keeps an argparse filename indexing bug).
fcad_parser/kicad_pcb.py Docstring normalization and formatting; minor tuple/list refactors.
explode.py Formatting and light refactors; introduces a dead/no-op expression in geometry placement helper.
expTree.py Formatting and minor boolean simplification.
dxf_parser/_dxfReader.py Large formatting pass and py3 simplification (but now misses an import needed at runtime).
dxf_parser/_dxfColorMap.py Pure formatting of color map literal.
constrainator.py Formatting and refactors for readability (loops/conditions); keeps legacy branches.
commits_num.py Formatting and modernization; refactors request URL building (but introduces requests scoping bug).
_DXF_Import.py Formatting/import cleanup; DXF import wrapper adjustments (but introduces missing translate dependency).
ZipStepImport.py Formatting/import cleanup; zip import wrapper adjustments (but introduces missing translate dependency).
TranslateUtils.py Formatting; changes translation fallback behavior (but removes a required fallback).
SaveSettings.py Formatting and reload helper simplification.
InitGui.py Large formatting/refactor pass across workbench initialization and UI setup.
Init.py Formatting (but removes import FreeCAD causing import-time failure).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TranslateUtils.py Outdated
Comment thread _DXF_Import.py
decodedName = name.decode("latin1")
except UnicodeDecodeError:
FreeCAD.Console.PrintError(translate("Zip import","Error: Couldn't determine character encoding"))
FreeCAD.Console.PrintError(translate("Zip import", "Error: Couldn't determine character encoding"))
Comment thread makefacedxf.py
Comment on lines +259 to 263
f = Part.makeFace(w, "Part::FaceMakerBullseye")
except Part.OCCError: # Exception: #
# FreeCAD.Console.PrintError('Error in source %s (%s)' % (faceobj.Name,faceobj.Label)+"\n")
FreeCAD.Console.PrintError('Error in source %s (%s)' % (f.Name,f.Label)+"\n")
FreeCAD.Console.PrintError("Error in source %s (%s)" % (f.Name, f.Label) + "\n")

Comment thread explode.py Outdated
Comment thread dxf_parser/_dxfReader.py Outdated
Comment thread Init.py
Comment on lines +18 to +21
FreeCAD.addImportType("Kicad pcb board File Type (*.kicad_pcb)", "kicadStepUptools")
FreeCAD.addImportType("Kicad pcb mod File Type (*.kicad_mod)", "kicadStepUptools")

FreeCAD.addImportType("zip of STEP/FCStd File Type (*.zip)","ZipStepImport")
FreeCAD.addImportType("zip of STEP/FCStd File Type (*.zip)", "ZipStepImport")
Comment thread ZipStepImport.py
decodedName = name.decode("latin1")
except UnicodeDecodeError:
FreeCAD.Console.PrintError(translate("Zip import","Error: Couldn't determine character encoding"))
FreeCAD.Console.PrintError(translate("Zip import", "Error: Couldn't determine character encoding"))
Comment thread commits_num.py
Comment on lines 52 to +57
def latestCommitInfo(u, r):
""" Get info about the latest commit of a GitHub repo """
response = requests.get('https://api.github.com/repos/{}/{}/commits?per_page=1'.format(u, r))
commit = response.json()[0]; commit['number'] = re.search(r'\d+$', response.links['last']['url']).group()
return commit
"""Get info about the latest commit of a GitHub repo"""
response = requests.get(f"https://api.github.com/repos/{u}/{r}/commits?per_page=1")
commit = response.json()[0]
commit["number"] = re.search(r"\d+$", response.links["last"]["url"]).group()
return commit
Comment thread utf8test.py Outdated
Comment thread utf8test.py Outdated
@vlordier vlordier marked this pull request as draft April 30, 2026 08:32
@vlordier
Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

@vlordier vlordier force-pushed the modernize-linting-ci branch from 25d2082 to 370ae98 Compare April 30, 2026 09:29
@vlordier
Copy link
Copy Markdown
Author

@copilot apply changes based on the comments in this thread

vlordier added 3 commits May 1, 2026 01:28
…, editorconfig

- pyproject.toml: ruff lint + format (py311, 120 cols, 20 rule sets),
  ty type checker, uv config
- .pre-commit-config.yaml: ruff lint/fix + ruff-format + ty + standard hooks
- .github/workflows/ci.yml: 3 jobs (ruff lint+format, pre-commit, ty)
- .github/dependabot.yml: weekly updates for actions and pip
- .editorconfig: 4-space indent, LF, UTF-8
- .gitattributes: LF normalization, binary file markers
- .gitignore: ruff_cache, __pycache__, uv, editor temp files
- .git-blame-ignore-revs: record formatting commit for git blame skip
Apply ruff format (4-space indent, double quotes, 120 cols) and
ruff check --fix + --unsafe-fixes across all 23 first-party .py files.
Includes: import sorting, f-strings, trailing whitespace, useless
semicolons, comprehension simplifications (C416/C419), needless-bool
(SIM103), isinstance merges (SIM101), manual-list-copy (PERF402),
trailing commas (COM812), and more.

Third-party submodules (fcad_parser/, dxf_parser/) excluded.
…, etc.)

Manual fixes across 19 files:
- SIM103: inline boolean returns (kicadStepUpCMD, kicadStepUptools)
- SIM115: with statements for file handles (exchangePositions, fps,
  kicadStepUptools, kicad_parser)
- SIM113: enumerate() replaces manual counters (kicadStepUptools, tracks)
- PERF402: .extend() replaces manual list copy loops (constrainator,
  kicadStepUpCMD, kicadStepUptools, kicad_parser)
- UP031: printf-style to f-strings (kicadStepUptools)
- RUF003: unicode chars in comments (kicadStepUptools, tracks)
- YTT201: sys.version_info == 3 -> >= 3 (kicadStepUptools, kicad_parser)
- TRY: logger.exception redundant exception arg (kicad_parser)
- Copilot review fixes: import FreeCAD (Init.py), translate fallback
  (TranslateUtils.py), import scope (commits_num.py, ZipStepImport.py,
  _DXF_Import.py), dead expression (explode.py), dead Py2 code
  (utf8test.py), except block (makefacedxf.py)
@vlordier vlordier force-pushed the modernize-linting-ci branch from fa87e85 to c5307c6 Compare April 30, 2026 23:53
@vlordier vlordier marked this pull request as ready for review May 1, 2026 00:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants