alan-turing-institute / python-project-template

15 stars 3 forks source link

Linting rules are pretty strict #19

Open mhauru opened 9 months ago

mhauru commented 9 months ago

This might sometimes be what you want, but it's worth noting that

These aren't necessarily issues to be fixed, but I wonder if it would be good to have options for some more relaxed linter/fixer rules when setting up.

Tagging @rwood-97 and @mastoffel since these were observations that came from working on a new repo with them.

phinate commented 9 months ago

the ruff rules are pretty strict and include automatically fixing a lot of issues.

Can totally see that, which was my first experience using a template like this too.

For instance, I add an import, don't yet get to adding the part that uses the import, save the file, my editor automatically runs ruff and removes the import as unused.

Hotfix for this in particular: in pyproject.toml, add

[tool.ruff.lint]
unfixable = ["F401"]

But I'm really happy you brought this up in general: the really cool thing about making our own template is that we can decide some sensible defaults together (with the option to turn things off!).

We could definitely work on streamlining the process of configuring the linter; I'm aware the "everything on by default" strategy is not that useful when you actually want to customize things.

mypy complains a lot, including about missing stub packages and missing type annotations.

Right. This is something that is fixable usually in the following ways as outlined in the MyPy docs. The usual fix is to install the modules within the pre-commit file like this:

-   repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.8.0
    hooks:
      - mypy
        id: mypy
        files: src
        additional_dependencies:
          ['numpy', 'types-tqdm', 'click', 'types-jsonpatch', 'types-pyyaml', 'types-jsonschema', 'importlib_metadata', 'packaging']

The brute-force solution that's also shown in that link is to turn on ignore-missing-imports in the pyproject.toml.

I'd love to iterate more on these suggestions though: these are going to be consistent pain points for users, and I want to make sure to mitigate those as much as possible. Feel free to drop more thoughts here on suggestions, or we can talk about it offline!

phinate commented 6 months ago

Some resolutions from this, after following up offline: