Skip to content

Commit d3b24d4

Browse files
talgalilimeta-codesync[bot]
authored andcommitted
Sync GitHub linting with Meta's internal pyfmt configuration (#154)
Summary: This change synchronizes the GitHub Actions linting workflow with Meta's internal pyfmt configuration to ensure consistent code formatting between internal and external development environments. Previously, the GitHub workflow used `black` directly for formatting checks, which caused discrepancies with Meta's internal linting that uses `ruff-api` (via ufmt). This led to situations where code would pass Meta's `pyfmt` checks but fail GitHub CI, or vice versa. This diff adds: 1. **Configuration files** matching Meta's internal setup: - `.flake8` - Flake8 configuration with Black-compatible ignore rules - `pyproject.toml` - ufmt configuration using ruff-api formatter and usort - `requirements-fmt.txt` - Pinned versions from Meta's internal tools/lint/pyfmt/reqs/requirements-fmt.txt - `.pre-commit-config.yaml` - Pre-commit hooks for ufmt and flake8 2. **GitHub workflow updates**: - Replaced `black --check .` with `ufmt check .` - Added all required dependencies (black==24.4.2, ruff-api==0.1.0, ufmt==2.8.0, usort==1.0.8.post1) - Fixed flake8 invocation to use explicit path 3. **Documentation updates**: - Updated CONTRIBUTING.md with comprehensive linting and formatting instructions - Documented the new workflow for contributors - Explained configuration files and their purposes The versions are pinned to exactly match Meta's internal setup, ensuring 100% consistency between environments. Pull Request resolved: #154 Reviewed By: atavory Differential Revision: D87183125 Pulled By: talgalili fbshipit-source-id: 1445a9af1f093cb9d103d914c5eedb65fce569a8
1 parent 09a30b9 commit d3b24d4

File tree

6 files changed

+91
-5
lines changed

6 files changed

+91
-5
lines changed

.flake8

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,19 @@
44
# W503: Line break before binary operator
55
# E203: Whitespace before ':'
66
ignore = E501, W503, E203
7+
8+
# Match Black's default line length
9+
max-line-length = 88
10+
11+
# Exclude common directories
12+
exclude =
13+
.git,
14+
__pycache__,
15+
.venv,
16+
venv,
17+
build,
18+
dist,
19+
*.egg-info,
20+
.github,
21+
website/node_modules,
22+
sphinx/_build

.github/workflows/build-and-test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ jobs:
4646
python-version: 3.9
4747
- name: Install dependencies
4848
run: |
49-
pip install flake8
49+
pip install flake8 black==24.4.2 ruff-api==0.1.0 ufmt==2.8.0 usort==1.0.8.post1
5050
- name: Flake8
5151
run: |
52-
flake8
52+
flake8 .
53+
- name: ufmt (formatting check)
54+
run: |
55+
ufmt check .
5356
5457
test-deploy-website:
5558
name: Test website build

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/omnilib/ufmt
5+
rev: v2.8.0
6+
hooks:
7+
- id: ufmt
8+
additional_dependencies:
9+
- black==24.4.2
10+
- ruff-api==0.1.0
11+
- usort==1.0.8.post1
12+
- stdlibs
13+
14+
- repo: https://github.com/pycqa/flake8
15+
rev: 7.0.0
16+
hooks:
17+
- id: flake8
18+
additional_dependencies: []

CONTRIBUTING.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,41 @@ outlined on that page and do not file a public issue.
3030

3131
### Coding Style
3232
* 4 spaces for indentation rather than tabs
33-
* 80 character line length
33+
* 88 character line length
3434

35-
### Linting
36-
Run the linter via `flake8` (`pip install flake8`) from the root of the Ax repository. Note that we have a [custom flake8 configuration](https://github.com/facebookresearch/balance/blob/main/.flake8).
35+
### Linting and Code Formatting
36+
37+
We use **ufmt** (µfmt) for code formatting and **flake8** for linting. This matches Meta's internal pyfmt tooling and ensures consistency between internal and external development.
38+
39+
**Installation:**
40+
```bash
41+
pip install -r requirements-fmt.txt
42+
```
43+
44+
**Running formatters and linters:**
45+
```bash
46+
# Check formatting (doesn't modify files)
47+
ufmt check .
48+
49+
# Auto-format code
50+
ufmt format .
51+
52+
# Run flake8 linter
53+
flake8 .
54+
```
55+
56+
**Pre-commit hooks (optional but recommended):**
57+
```bash
58+
pip install pre-commit
59+
pre-commit install
60+
```
61+
62+
After installing pre-commit hooks, formatting and linting will run automatically on every commit.
63+
64+
**Configuration files:**
65+
- `.flake8` - Custom flake8 configuration
66+
- `pyproject.toml` - Configuration for ufmt, black, and usort
67+
- `requirements-fmt.txt` - Pinned versions of formatting tools matching Meta's internal setup
3768

3869
### Static Type Checking
3970
We use [Pyre](https://pyre-check.org/) for static type checking and require code to be fully type annotated.

pyproject.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[tool.ufmt]
2+
formatter = "ruff-api"
3+
sorter = "usort"
4+
5+
[tool.black]
6+
line-length = 88
7+
target-version = ["py39", "py310", "py311", "py312", "py313"]
8+
9+
[tool.usort]
10+
first_party_detection = false

requirements-fmt.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Generated from Meta's internal pyfmt requirements
2+
# Keep these versions in sync with Meta's internal
3+
# tools/lint/pyfmt/reqs/requirements-fmt.txt
4+
black==24.4.2
5+
ruff-api==0.1.0
6+
stdlibs==2024.1.28
7+
ufmt==2.8.0
8+
usort==1.0.8.post1

0 commit comments

Comments
 (0)