Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

21 changes: 21 additions & 0 deletions .github/workflows/check-copyright-year.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Check copyright end year

on: [pull_request, workflow_dispatch]

jobs:
copyright-year:
runs-on: 'ubuntu-latest'

steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Compare the configured copyright end year with the current year
run: |
current=$(date --utc +%Y)
configured=$(grep -o 'Copyright 2007-[0-9]\{4\}' pyproject.toml \
| grep -o '[0-9]\{4\}$')
echo "Configured end year: ${configured:-none}; current year: ${current}"
if [ "${configured}" != "${current}" ]; then
echo "::error::Copyright end year is ${configured:-unreadable}, but the current year is ${current}."
echo "Update the end year in pyproject.toml and in every source file header."
exit 1
fi
19 changes: 0 additions & 19 deletions .github/workflows/check-style-strict.yml

This file was deleted.

4 changes: 1 addition & 3 deletions .github/workflows/check-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ jobs:
enable-cache: true
cache-suffix: style
- run: |
uv run --locked --only-group style -m black --check --diff .
uv run --locked --only-group style -m isort --check --diff .
uv run --locked --only-group style -m flake8 .
uv run --locked --only-group style -m ruff check .
51 changes: 27 additions & 24 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ uv sync
Runtime: `traits>=6.2`, `apptools[preferences]>=5.3`, `pyface`, `traitsui`.

Development requirements are dependency groups in `pyproject.toml`:
`test` (pytest), `gui` (PySide6), `style` (Black, isort, flake8) and
`docs`. The default `dev` group includes the first three, so it covers
everything but `docs`.
`test` (pytest), `gui` (PySide6), `style` (ruff) and `docs`. The default
`dev` group includes the first three, so it covers everything but `docs`.

Exact versions are pinned in the tracked `uv.lock`, which `uv run` and
`uv sync` install from. After changing anything in `pyproject.toml`, run
Expand All @@ -51,35 +50,38 @@ to run headless.

## Linting and Formatting

Style is enforced by Black, isort, and flake8, all provided by the `dev`
group. Run all three checks:
Style is enforced by ruff, provided by the `dev` group. Run both checks:

```bash
uv run -m black --check --diff .
uv run -m isort --check --diff .
uv run -m flake8 .
uv run -m ruff check .
uv run -m ruff format --check --diff .
```
Comment on lines +53 to 58

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not a concern - the reformat PR will be merged almost immediately after this one.


To auto-fix formatting:
To auto-fix:

```bash
uv run -m black .
uv run -m isort .
uv run -m ruff check --fix .
uv run -m ruff format .
```

### Key style settings

- **Line length**: 79 (Black, isort, flake8 all configured to 79)
- **Black**: default settings with `line-length = 79`
- **isort**: `profile = "black"`, custom `ENTHOUGHT` import section
- **flake8**: ignores `E203`, `E266`, `W503`; `F401` suppressed in `*/api.py`
- **Line length**: 88, ruff's default
- **Lint rules**: `CPY001` (copyright header), `E`, `F`, `I`, `W`;
`F401` suppressed in `*/api.py`
- **Import sorting**: ruff's `I` rules, with a custom `enthought` section
- **ruff version**: upper-bounded to `~= 0.16.0`, because ruff changes
formatting in minor releases. Raising the bound means reformatting the
codebase in the same change.

## Code Style Guidelines

### Copyright Header

Every `.py` file must start with the standard copyright header. Use whatever
end year is present in the existing files (currently 2026):
Every non-empty `.py` file must start with the standard copyright header,
enforced by ruff's `CPY001` rule. The authoritative text, including the year
range, is the `notice-rgx` setting in `pyproject.toml`; that copy is a regular
expression, so unescape it rather than pasting it verbatim:

```python
# (C) Copyright 2007-2026 Enthought, Inc., Austin, TX
Expand All @@ -95,7 +97,7 @@ end year is present in the existing files (currently 2026):

### Import Ordering

Imports are sorted by isort into six sections with labeled comment headers:
Imports are sorted by ruff into six sections with labeled comment headers:

```python
# Standard library imports.
Expand All @@ -110,12 +112,13 @@ from .extension_point import ExtensionPoint
from .i_application import IApplication
```

The sections are: `FUTURE`, `STDLIB`, `THIRDPARTY`, `ENTHOUGHT`
(apptools, pyface, traits, traitsui), `FIRSTPARTY` (envisage), `LOCALFOLDER`
(relative imports). Always import from `.api` submodules for Enthought
packages (e.g., `from traits.api import ...`, not `from traits.has_traits
import ...`). Use relative imports for intra-package references in library
code; use absolute imports (`from envisage.xxx`) in tests.
The sections are: `future`, `standard-library`, `third-party`, `enthought`
(apptools, pyface, traits, traitsui), `first-party` (envisage) and
`local-folder` (relative imports). Always import from `.api` submodules for
Enthought packages (e.g., `from traits.api import ...`, not `from
traits.has_traits import ...`). Use relative imports for intra-package
references in library code; use absolute imports (`from envisage.xxx`) in
tests.

### Type System

Expand Down
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Build
* The ``envisage`` package now lives in ``src/envisage`` in the repository,
so that an ``import envisage`` from the repository root can't accidentally
pick up an uninstalled source tree. The wheel is unchanged. (#635)
* Style checks now use ``ruff`` in place of ``black``, ``isort``, ``flake8``
and ``flake8-ets``. (#636)

Version 8.0.0
=============
Expand Down
59 changes: 45 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ docs = [
{include-group = 'gui'},
]
style = [
'black ~= 24.3',
'flake8',
'flake8-ets >= 1.1.0',
'isort',
'ruff ~= 0.16.0',
]
test = [
'pytest',
Expand All @@ -71,23 +68,57 @@ dev = [
{include-group = 'test'},
]

[tool.black]
line-length = 79

[tool.isort]
profile = 'black'
line_length = 79
order_by_type = false
sections = ['FUTURE', 'STDLIB', 'THIRDPARTY', 'ENTHOUGHT', 'FIRSTPARTY', 'LOCALFOLDER']
known_enthought = ['apptools', 'pyface', 'traits', 'traitsui']

[tool.pytest.ini_options]
filterwarnings = [
'error',
# Ignore TraitsUI's import-time warning when numpy isn't installed.
'ignore:ArrayEditor is not available:ImportWarning',
]

[tool.ruff]
line-length = 88

[tool.ruff.lint]
select = ['CPY001', 'E', 'F', 'I', 'W']

[tool.ruff.lint.per-file-ignores]
'*/api.py' = ['F401']

[tool.ruff.lint.flake8-copyright]
# Empty files don't need a copyright header.
min-file-size = 1
# The copyright header, as a regular expression: hence the escaped parentheses
# and periods, and the leading \A anchoring the match to the start of the file.
# The end year here is the single source of truth: CPY001 holds every source
# file to it, and the check-copyright-year workflow holds it to the current
# year.
notice-rgx = '''\A# \(C\) Copyright 2007-2026 Enthought, Inc\., Austin, TX
# All rights reserved\.
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE\.txt and may be redistributed only under
# the conditions described in the aforementioned license\. The license
# is also available online at http://www\.enthought\.com/licenses/BSD\.txt
#
# Thanks for using Enthought open source!'''

[tool.ruff.lint.isort]
order-by-type = false
# Demo applications that are run from their own directory, so their absolute
# imports aren't imports of Envisage itself.
known-third-party = ['acme', 'attractors']
section-order = [
'future',
'standard-library',
'third-party',
'enthought',
'first-party',
'local-folder',
]

[tool.ruff.lint.isort.sections]
enthought = ['apptools', 'pyface', 'traits', 'traitsui']

[tool.uv.dependency-groups]
# The pinned Sphinx needs 3.12+; docs are only ever built on the latest Python.
docs = { requires-python = '>= 3.12' }
Loading