From a0572359ae843c21b9f5430b16e706c39196c2ed Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 24 Jun 2025 07:47:02 +0100 Subject: [PATCH] Remove pytest.ini from project detection files This breaks detecting the project root when editing tests with a nested pytest.ini file where other project files are available. The other files are so common we can just removes this entirely and test that we ignore it in one case. --- autoload/ale/python.vim | 12 +++++------ doc/ale-python.txt | 2 +- test/linter/test_flake8.vader | 12 +++++------ test/linter/test_flakehell.vader | 35 -------------------------------- 4 files changed, 13 insertions(+), 48 deletions(-) diff --git a/autoload/ale/python.vim b/autoload/ale/python.vim index 148683d6..81ab6eb7 100644 --- a/autoload/ale/python.vim +++ b/autoload/ale/python.vim @@ -26,7 +26,6 @@ function! ale#python#FindProjectRootIni(buffer) abort " If you change this, update ale-python-root documentation. if filereadable(l:path . '/MANIFEST.in') \|| filereadable(l:path . '/setup.cfg') - \|| filereadable(l:path . '/pytest.ini') \|| filereadable(l:path . '/tox.ini') \|| filereadable(l:path . '/.pyre_configuration.local') \|| filereadable(l:path . '/mypy.ini') @@ -55,11 +54,12 @@ endfunction " Given a buffer number, find the project root directory for Python. " The root directory is defined as the first directory found while searching " upwards through paths, including the current directory, until a path -" containing an init file (one from MANIFEST.in, setup.cfg, pytest.ini, -" tox.ini) is found. If it is not possible to find the project root directory -" via init file, then it will be defined as the first directory found -" searching upwards through paths, including the current directory, until no -" __init__.py files is found. +" containing an configuration file is found. (See list above) +" +" If it is not possible to find the project root directory via configuration +" file, then it will be defined as the first directory found searching upwards +" through paths, including the current directory, until no __init__.py files +" is found. function! ale#python#FindProjectRoot(buffer) abort let l:ini_root = ale#python#FindProjectRootIni(a:buffer) diff --git a/doc/ale-python.txt b/doc/ale-python.txt index ce672acd..3a4cedf7 100644 --- a/doc/ale-python.txt +++ b/doc/ale-python.txt @@ -63,7 +63,6 @@ ALE will look for configuration files with the following filenames. > MANIFEST.in setup.cfg - pytest.ini tox.ini .pyre_configuration.local mypy.ini @@ -81,6 +80,7 @@ ALE will look for configuration files with the following filenames. > poetry.lock pyproject.toml .tool-versions + uv.lock < The first directory containing any of the files named above will be used. diff --git a/test/linter/test_flake8.vader b/test/linter/test_flake8.vader index d59c9e06..721b53e9 100644 --- a/test/linter/test_flake8.vader +++ b/test/linter/test_flake8.vader @@ -125,35 +125,35 @@ Execute(The flake8 callbacks should detect virtualenv directories): \ . ' --stdin-display-name %s -', \] -Execute(The FindProjectRoot should detect the project root directory for namespace package via Manifest.in): +Execute(FindProjectRoot should detect the project root directory for namespace package via Manifest.in): call ale#test#SetFilename('../test-files/python/namespace_package_manifest/namespace/foo/bar.py') AssertEqual \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_manifest'), \ ale#python#FindProjectRoot(bufnr('')) -Execute(The FindProjectRoot should detect the project root directory for namespace package via setup.cf): +Execute(FindProjectRoot should detect the project root directory for namespace package via setup.cf): call ale#test#SetFilename('../test-files/python/namespace_package_setup/namespace/foo/bar.py') AssertEqual \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_setup'), \ ale#python#FindProjectRoot(bufnr('')) -Execute(The FindProjectRoot should detect the project root directory for namespace package via pytest.ini): +Execute(FindProjectRoot should ignore the location of pytest.ini): call ale#test#SetFilename('../test-files/python/namespace_package_pytest/namespace/foo/bar.py') AssertEqual - \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_pytest'), + \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_pytest/namespace'), \ ale#python#FindProjectRoot(bufnr('')) -Execute(The FindProjectRoot should detect the project root directory for namespace package via tox.ini): +Execute(FindProjectRoot should detect the project root directory for namespace package via tox.ini): call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py') AssertEqual \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_tox'), \ ale#python#FindProjectRoot(bufnr('')) -Execute(The FindProjectRoot should detect the project root directory for non-namespace package): +Execute(FindProjectRoot should detect the project root directory for non-namespace package): call ale#test#SetFilename('../test-files/python/no_virtualenv/subdir/foo/bar.py') AssertEqual diff --git a/test/linter/test_flakehell.vader b/test/linter/test_flakehell.vader index 8a159f0d..97886113 100644 --- a/test/linter/test_flakehell.vader +++ b/test/linter/test_flakehell.vader @@ -111,41 +111,6 @@ Execute(The flakehell callbacks should detect virtualenv directories): \ . ' --stdin-display-name %s -', \] -Execute(The FindProjectRoot should detect the project root directory for namespace package via Manifest.in): - call ale#test#SetFilename('../test-files/python/namespace_package_manifest/namespace/foo/bar.py') - - AssertEqual - \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_manifest'), - \ ale#python#FindProjectRoot(bufnr('')) - -Execute(The FindProjectRoot should detect the project root directory for namespace package via setup.cf): - call ale#test#SetFilename('../test-files/python/namespace_package_setup/namespace/foo/bar.py') - - AssertEqual - \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_setup'), - \ ale#python#FindProjectRoot(bufnr('')) - -Execute(The FindProjectRoot should detect the project root directory for namespace package via pytest.ini): - call ale#test#SetFilename('../test-files/python/namespace_package_pytest/namespace/foo/bar.py') - - AssertEqual - \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_pytest'), - \ ale#python#FindProjectRoot(bufnr('')) - -Execute(The FindProjectRoot should detect the project root directory for namespace package via tox.ini): - call ale#test#SetFilename('../test-files/python/namespace_package_tox/namespace/foo/bar.py') - - AssertEqual - \ ale#path#Simplify(g:dir . '/../test-files/python/namespace_package_tox'), - \ ale#python#FindProjectRoot(bufnr('')) - -Execute(The FindProjectRoot should detect the project root directory for non-namespace package): - call ale#test#SetFilename('../test-files/python/no_virtualenv/subdir/foo/bar.py') - - AssertEqual - \ ale#path#Simplify(g:dir . '/../test-files/python/no_virtualenv/subdir'), - \ ale#python#FindProjectRoot(bufnr('')) - " Some users currently run flakehell this way, so we should support it. Execute(Using `python -m flakehell` should be supported for running flakehell): call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')