MetOffice / MetOffice/ANTS

Configure isort to recognise ants as a first party package

Open
#74 0 comments 0 reactions 0 assignees View on GitHub
⬇ low priority 🛠️ infrastructure
Dominant language
Python
Stars
7
Forks
10
Avg merge
1d 19h
Merged PRs (30d)
5

Description

## Background
`isort` allows setting a [​known first party](https://pycqa.github.io/isort/docs/configuration/options.html#known-first-party) package, which forces isort to recognize a module as being part of the current python project.

Currently it seems ants is being recognised as a third party package, unless the working copy is named `ants`. This leads to inconsistent results depending on the name of the working copy. If the working copy is named `ants`, then the rose stem will yield different results to running in the working copy directly.

## Previous investigation notes
Noting that there are some known issues with isort's handling of first-party vs third-party packages (e.g. [​#2365 on github](https://github.com/PyCQA/isort/issues/2365)).

Bizarrely, the new import order imposed by isort with ants as a first party package seems to break the esmpy import:

```
>>> import ants
lib/ants/regrid/esmf.py:35: UserWarning: 'Author'
Proceeding without capabilities provided by ESMPy (esmf).
warnings.warn(msg.format(str(_ESMPY_IMPORT_ERROR)))
```
Importing esmpy directly without importing ants, however, seems to work fine, and you can then import ants:
```
>>> import esmpy
>>> import ants
```
but importing the other way round results in the "Author" error.

Good news is this is [​fixed in esmpy 8.5.0](https://github.com/esmf-org/esmf/issues/140) (we're currently using esmpy 8.4.2).

I've managed to narrow it down to the file `lib/ants/analysis/__init__.py` causing the issue. Although this doesn't use esmpy directly, it does import `ants.regrid`.

## Ruff
We may replace `isort` with `ruff`, but I think the above will still apply. It should be a case of configuring ruff to treat ants as first party, rather than isort.

Contributor guide

Open the contributing guide

Research direction

Start with lib/ants/analysis/__init__.py and trace its import of ants.regrid, then review the repository's current isort or Ruff configuration. Verify that ants is treated as first party, import ordering is consistent regardless of the working-copy name, and importing ants does not reproduce the documented esmpy error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.