Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Python project root dir detection for flake8 configuration #2502

Merged
merged 2 commits into from
May 20, 2019
Merged

Change Python project root dir detection for flake8 configuration #2502

merged 2 commits into from
May 20, 2019

Conversation

ericvw
Copy link
Contributor

@ericvw ericvw commented May 14, 2019

The official configuration files for flake8 are .flake8, tox.ini,
and setup.cfg.

After investigation, it is safe to remove flake8.cfg as it appears to
only exist as a typo in other tooling documentation (e.g.,
python-language-server).

Even though no linters automatically read .flake8rc, it is kept in
case projects may be using it for detecting the projects root directory.

http://flake8.pycqa.org/en/latest/user/configuration.html#configuration-locations

Copy link
Member

@w0rp w0rp left a comment

Choose a reason for hiding this comment

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

Add a test for this.

@@ -25,8 +25,7 @@ function! ale#python#FindProjectRootIni(buffer) abort
\|| filereadable(l:path . '/tox.ini')
\|| filereadable(l:path . '/mypy.ini')
\|| filereadable(l:path . '/pycodestyle.cfg')
\|| filereadable(l:path . '/flake8.cfg')
Copy link
Member

Choose a reason for hiding this comment

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

python-language-server discovers paths by looking for flake8.cfg, so I'd keep this. It's mentioned here: https://pypi.org/project/python-language-server/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears to be a typo in the README of python-language-server.

https://github.com/palantir/python-language-server/blob/96e08d85635382d17024c352306c4759f124195d/pyls/config/flake8_conf.py#L10

The commit which introduced the original introduced the change for reading flake8 but documented it incorrectly (palantir/python-language-server@3c1f183).

The python-language-server has limited contributions to the project to those who have contributed in the past — I am unable to open an issue nor a pull request to address this discrepancy 😞 .

@@ -25,8 +25,7 @@ function! ale#python#FindProjectRootIni(buffer) abort
\|| filereadable(l:path . '/tox.ini')
\|| filereadable(l:path . '/mypy.ini')
\|| filereadable(l:path . '/pycodestyle.cfg')
\|| filereadable(l:path . '/flake8.cfg')
\|| filereadable(l:path . '/.flake8rc')
Copy link
Member

Choose a reason for hiding this comment

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

A number of projects and linter plugins search for .flake8rc, so I'd keep this too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I searched the history of the flake8 project and it has never supported .flake8rc, from what I can tell.

I conducted a hasty Google search: ".flake8rc" and identified the following (potential) projects that may be using this are:

Ale is using this in the documentation and within this function.

For linter-flake8, it looks like it is another documentation bug (https://github.com/AtomLinter/linter-flake8/blob/875c273d3affe253478b804a51441688a0b2d03e/package.json#L27), from search https://github.com/AtomLinter/linter-flake8/search?q=flake8rc&unscoped_q=flake8rc.

For flycheck, it appears they have a flycheck-flake8rc-specific configuration file documented in (https://github.com/flycheck/flycheck/blob/47174a12fd84a685f36019632838c73b4813b66d/doc/languages.rst).

@@ -25,8 +25,7 @@ function! ale#python#FindProjectRootIni(buffer) abort
\|| filereadable(l:path . '/tox.ini')
\|| filereadable(l:path . '/mypy.ini')
\|| filereadable(l:path . '/pycodestyle.cfg')
\|| filereadable(l:path . '/flake8.cfg')
\|| filereadable(l:path . '/.flake8rc')
\|| filereadable(l:path . '/.flake8')
Copy link
Member

Choose a reason for hiding this comment

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

You can move this further up the list, as this is the officially supported filename.

Copy link
Contributor Author

@ericvw ericvw left a comment

Choose a reason for hiding this comment

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

Add a test for this.

Absolutely.

I noticed that the tests for ale#python#FindProjectRoot are in https://github.com/w0rp/ale/blob/master/test/command_callback/test_flake8_command_callback.vader. The path of least resistence would be to add a test there, which I'm planning on doing.

There is an opportunity to factor these out into a separate file, which occurs for some other languagse. If you don't mind, I'm happy to do this refactoring as a separate PR.

I'm still getting familiar with Vimscript, so it may take me a bit to get this right 😄.

@w0rp, let me know how you would like to proceed with the other configuration files that I responded to.

@@ -25,8 +25,7 @@ function! ale#python#FindProjectRootIni(buffer) abort
\|| filereadable(l:path . '/tox.ini')
\|| filereadable(l:path . '/mypy.ini')
\|| filereadable(l:path . '/pycodestyle.cfg')
\|| filereadable(l:path . '/flake8.cfg')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears to be a typo in the README of python-language-server.

https://github.com/palantir/python-language-server/blob/96e08d85635382d17024c352306c4759f124195d/pyls/config/flake8_conf.py#L10

The commit which introduced the original introduced the change for reading flake8 but documented it incorrectly (palantir/python-language-server@3c1f183).

The python-language-server has limited contributions to the project to those who have contributed in the past — I am unable to open an issue nor a pull request to address this discrepancy 😞 .

@@ -25,8 +25,7 @@ function! ale#python#FindProjectRootIni(buffer) abort
\|| filereadable(l:path . '/tox.ini')
\|| filereadable(l:path . '/mypy.ini')
\|| filereadable(l:path . '/pycodestyle.cfg')
\|| filereadable(l:path . '/flake8.cfg')
\|| filereadable(l:path . '/.flake8rc')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I searched the history of the flake8 project and it has never supported .flake8rc, from what I can tell.

I conducted a hasty Google search: ".flake8rc" and identified the following (potential) projects that may be using this are:

Ale is using this in the documentation and within this function.

For linter-flake8, it looks like it is another documentation bug (https://github.com/AtomLinter/linter-flake8/blob/875c273d3affe253478b804a51441688a0b2d03e/package.json#L27), from search https://github.com/AtomLinter/linter-flake8/search?q=flake8rc&unscoped_q=flake8rc.

For flycheck, it appears they have a flycheck-flake8rc-specific configuration file documented in (https://github.com/flycheck/flycheck/blob/47174a12fd84a685f36019632838c73b4813b66d/doc/languages.rst).

@w0rp
Copy link
Member

w0rp commented May 14, 2019

Leave .flake8rc in place. flake8 has never recognised it, but there are projects out there that use it. If flake8.cfg isn't used in any project, we can remove it.

@ericvw
Copy link
Contributor Author

ericvw commented May 14, 2019

Leave .flake8rc in place. flake8 has never recognised it, but there are projects out there that use it.

I'm curious more than anything: What other linters have you seen that use it? I haven't been able to find anything concrete that would affect the Python linters which ale calls out to.

I'll leave .flake8rc in place as requested and will update the PR once I have a test in place for detecting .flake8. Greatly appreciate the quick review feedback :).

@w0rp
Copy link
Member

w0rp commented May 14, 2019

No linters automatically read it, but the location of the file is used to figure out where the root of a project might be.

@ericvw
Copy link
Contributor Author

ericvw commented May 18, 2019

@w0rp, I have updated the PR with the changes requested and added a new test suite for future iterations of detecting a Python project's root directory.

@ericvw ericvw changed the title Fix Python flake8 configuration file detection Change Python project root dir detection for flake8 configuration May 18, 2019
Add test files and a new test suite for detecting a Python project's
root directory.
The official configuration files for `flake8` are `.flake8`, `tox.ini`,
and `setup.cfg`.

After investigation, it is safe to remove `flake8.cfg` as it appears to
only exist as a typo in other tooling documentation (e.g.,
`python-language-server`).

Even though no linters automatically read `.flake8rc`, it is kept in
case projects may be using it for detecting the projects root directory.
@w0rp w0rp merged commit 89db851 into dense-analysis:master May 20, 2019
@w0rp
Copy link
Member

w0rp commented May 20, 2019

Cheers! 🍻

@ericvw ericvw deleted the flake8-config branch May 21, 2019 01:55
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.

None yet

2 participants