Skip to content

ENH Add support for config files#69

Merged
MarcoGorelli merged 19 commits into
MarcoGorelli:mainfrom
jeremiedbb:support-config-files
Apr 3, 2023
Merged

ENH Add support for config files#69
MarcoGorelli merged 19 commits into
MarcoGorelli:mainfrom
jeremiedbb:support-config-files

Conversation

@jeremiedbb

Copy link
Copy Markdown
Collaborator

Fixes #64

This PR adds the possibility to set the configuration either from pyproject.toml or from setup.cfg.

I chose to support setup.cfg as well because I read a lot of discussion regarding the transition to pyproject.toml and it seems that it has not been adopted by a bunch of projects. The main reason I found was the issue that it automatically triggers isolated builds even when you want to install in editable mode. Since cython-lint is used exclusively by projects that do have some compilation, I thought it was more convenient to support setup.cfg.

@MarcoGorelli

Copy link
Copy Markdown
Owner

thanks for your PR!

I think what we also need is some example of how to set configuration in the readme

Unless there's an example of a package which uses cython-lint but can't use pyproject.toml, I'd suggest dropping setup.cfg, let's keep things simple

Comment thread cython_lint/cython_lint.py
Comment thread cython_lint/cython_lint.py Outdated
Search for a pyproject.toml or a setup.cfg file in common
parent directories of the given list of paths.
"""
paths = [path.resolve() for path in paths]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

aren't we iterating over paths multiple times like this? can we just call resolve() directly one level up?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yep, done

if sys.version_info >= (3, 11): # pragma: no cover
import tomllib
else:
import tomli as tomllib

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

doesn't this need to be a runtime dependency now?

@jeremiedbb jeremiedbb Apr 3, 2023

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I guess so, at least while py3.11 is not the min supported version :) . I added it to the install_requires section

Comment on lines +856 to +864
while root != root.parent:

# Look for pyproject.toml first
config_file = root / 'pyproject.toml'
if config_file.is_file():
config = tomllib.loads(config_file.read_text())
config = config.get('tool', {}).get('cython-lint', {})
if config:
return config

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

does this logic come from some other tool? if so, it would be good to reference it. if not, we should add more extensive testing

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I tested the behavior of other linters like black and flake8. You don't have to run the tool from the root of your project and so they'll try to locate it by climbing up the path. I couldn't copy paste their logic because it's entangled in a much more complicated logic but I tried to mimic the behavior. I extended one of the tests in this regard.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

makes sense, thanks!

Comment thread cython_lint/cython_lint.py Outdated
args = parser.parse_args(argv)
paths = [pathlib.Path(path).resolve() for path in args.paths]

# Update defaults from pyproject.toml or setup.cfg if present

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Suggested change
# Update defaults from pyproject.toml or setup.cfg if present
# Update defaults from pyproject.toml if present

😉

@jeremiedbb

Copy link
Copy Markdown
Collaborator Author

Unless there's an example of a package which uses cython-lint but can't use pyproject.toml, I'd suggest dropping setup.cfg, let's keep things simple

Okay, let's keep it simple for now. We can add support for setup.cfg if there's demand

@MarcoGorelli

Copy link
Copy Markdown
Owner

🤔 not sure why half the jobs are cancelled without even starting

@jeremiedbb

Copy link
Copy Markdown
Collaborator Author

Do you know why the ubuntu jobs are cancelled ? I just see them cancelled but no detail is given

@MarcoGorelli

MarcoGorelli commented Apr 3, 2023

Copy link
Copy Markdown
Owner

I don't know - want to try ubuntu-latest instead of ubuntu-18.04?

@jeremiedbb

Copy link
Copy Markdown
Collaborator Author

I was looking at https://github.blog/changelog/2022-08-09-github-actions-the-ubuntu-18-04-actions-runner-image-is-being-deprecated-and-will-be-removed-by-12-1-22/

It seems that the image is deprecated and should have been removed a while ago :)

@MarcoGorelli

Copy link
Copy Markdown
Owner

awesome! just needs a little example in the readme, then we can merge

We can add support for setup.cfg if there's demand

sure - OK if I add you as collaborator?

@jeremiedbb

Copy link
Copy Markdown
Collaborator Author

Sure, no problem, thanks !

@MarcoGorelli MarcoGorelli left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

thanks @jeremiedbb !

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.

Config to globally ignore errors

2 participants