Skip to content

Commit 7cdaaa6

Browse files
oliverralbertiniOliver Ruben Albertini
andauthored
[python/pyre.vim] use pyrefly executable (#4972)
https://github.com/facebook/pyrefly The pyre project has evolved to pyrefly. This replaces the pyre linter with a pyrefly one and removes the test files that were added for finding the project root in the old pyre world. Co-authored-by: Oliver Ruben Albertini <oliverruben@gmail.com>
1 parent 2f4a866 commit 7cdaaa6

File tree

9 files changed

+193
-1
lines changed

9 files changed

+193
-1
lines changed

ale_linters/python/pyrefly.vim

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
" Author: oliverralbertini <oliver.albertini@gmail.com>
2+
" Description: A performant type-checker supporting LSP for Python 3 created by Facebook
3+
4+
call ale#Set('python_pyrefly_executable', 'pyrefly')
5+
call ale#Set('python_pyrefly_use_global', get(g:, 'ale_use_global_executables', 0))
6+
call ale#Set('python_pyrefly_auto_pipenv', 0)
7+
call ale#Set('python_pyrefly_auto_poetry', 0)
8+
call ale#Set('python_pyrefly_auto_uv', 0)
9+
10+
function! ale_linters#python#pyrefly#GetExecutable(buffer) abort
11+
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'python_pyrefly_auto_pipenv'))
12+
\ && ale#python#PipenvPresent(a:buffer)
13+
return 'pipenv'
14+
endif
15+
16+
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'python_pyrefly_auto_poetry'))
17+
\ && ale#python#PoetryPresent(a:buffer)
18+
return 'poetry'
19+
endif
20+
21+
if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'python_pyrefly_auto_uv'))
22+
\ && ale#python#UvPresent(a:buffer)
23+
return 'uv'
24+
endif
25+
26+
return ale#python#FindExecutable(a:buffer, 'python_pyrefly', ['pyrefly'])
27+
endfunction
28+
29+
function! ale_linters#python#pyrefly#GetCommand(buffer) abort
30+
let l:executable = ale_linters#python#pyrefly#GetExecutable(a:buffer)
31+
let l:exec_args = [
32+
\ ale#Escape(l:executable)
33+
\ ]
34+
\ + (l:executable =~? '\(pipenv\|poetry\|uv\)$' ? ['run', 'pyrefly'] : [])
35+
\ + [
36+
\ 'lsp',
37+
\ ]
38+
39+
return join(l:exec_args, ' ')
40+
endfunction
41+
42+
function! ale_linters#python#pyrefly#GetCwd(buffer) abort
43+
" Run from project root if found, else from buffer dir.
44+
let l:project_root = ale#python#FindProjectRoot(a:buffer)
45+
46+
return !empty(l:project_root) ? l:project_root : '%s:h'
47+
endfunction
48+
49+
call ale#linter#Define('python', {
50+
\ 'name': 'pyrefly',
51+
\ 'lsp': 'stdio',
52+
\ 'executable': function('ale_linters#python#pyrefly#GetExecutable'),
53+
\ 'command': function('ale_linters#python#pyrefly#GetCommand'),
54+
\ 'project_root': function('ale#python#FindProjectRoot'),
55+
\ 'completion_filter': 'ale#completion#python#CompletionItemFilter',
56+
\ 'cwd': function('ale_linters#python#pyrefly#GetCwd'),
57+
\})

doc/ale-python.txt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,69 @@ g:ale_python_pyre_auto_uv
16161616
executable.
16171617

16181618

1619+
===============================================================================
1620+
pyrefly *ale-python-pyrefly*
1621+
1622+
`pyrefly` will be run from a detected project root, per |ale-python-root|.
1623+
1624+
*ale-options.python_pyrefly_executable*
1625+
*g:ale_python_pyrefly_executable*
1626+
*b:ale_python_pyrefly_executable*
1627+
python_pyrefly_executable
1628+
g:ale_python_pyrefly_executable
1629+
Type: |String|
1630+
Default: `'pyrefly'`
1631+
1632+
See |ale-integrations-local-executables|
1633+
1634+
Set this to `'pipenv'` to invoke `'pipenv` `run` `pyrefly'`.
1635+
Set this to `'poetry'` to invoke `'poetry` `run` `pyrefly'`.
1636+
Set this to `'uv'` to invoke `'uv` `run` `pyrefly'`.
1637+
1638+
*ale-options.python_pyrefly_use_global*
1639+
*g:ale_python_pyrefly_use_global*
1640+
*b:ale_python_pyrefly_use_global*
1641+
python_pyrefly_use_global
1642+
g:ale_python_pyrefly_use_global
1643+
Type: |Number|
1644+
Default: `get(g:, 'ale_use_global_executables', 0)`
1645+
1646+
See |ale-integrations-local-executables|
1647+
1648+
*ale-options.python_pyrefly_auto_pipenv*
1649+
*g:ale_python_pyrefly_auto_pipenv*
1650+
*b:ale_python_pyrefly_auto_pipenv*
1651+
python_pyrefly_auto_pipenv
1652+
g:ale_python_pyrefly_auto_pipenv
1653+
Type: |Number|
1654+
Default: `0`
1655+
1656+
Detect whether the file is inside a pipenv, and set the executable to `pipenv`
1657+
if true. This is overridden by a manually-set executable.
1658+
1659+
*ale-options.python_pyrefly_auto_poetry*
1660+
*g:ale_python_pyrefly_auto_poetry*
1661+
*b:ale_python_pyrefly_auto_poetry*
1662+
python_pyrefly_auto_poetry
1663+
g:ale_python_pyrefly_auto_poetry
1664+
Type: |Number|
1665+
Default: `0`
1666+
1667+
Detect whether the file is inside a poetry, and set the executable to `poetry`
1668+
if true. This is overridden by a manually-set executable.
1669+
1670+
*ale-options.python_pyrefly_auto_uv*
1671+
*g:ale_python_pyrefly_auto_uv*
1672+
*b:ale_python_pyrefly_auto_uv*
1673+
python_pyrefly_auto_uv
1674+
g:ale_python_pyrefly_auto_uv
1675+
Type: |Number|
1676+
Default: `0`
1677+
1678+
Set the executable to `uv` if true. This is overridden by a manually-set
1679+
executable.
1680+
1681+
16191682
===============================================================================
16201683
pyright *ale-python-pyright*
16211684

doc/ale-supported-languages-and-tools.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ Notes:
545545
* `pylint`!!
546546
* `pylsp`
547547
* `pyre`
548+
* `pyrefly`
548549
* `pyright`
549550
* `refurb`
550551
* `reorder-python-imports`

doc/ale.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,7 @@ documented in additional help files.
37883788
pylint................................|ale-python-pylint|
37893789
pylsp.................................|ale-python-pylsp|
37903790
pyre..................................|ale-python-pyre|
3791+
pyrefly...............................|ale-python-pyrefly|
37913792
pyright...............................|ale-python-pyright|
37923793
refurb................................|ale-python-refurb|
37933794
reorder-python-imports................|ale-python-reorder_python_imports|

supported-tools.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ formatting.
554554
* [pylint](https://www.pylint.org/) :floppy_disk:
555555
* [pylsp](https://github.com/python-lsp/python-lsp-server) :warning:
556556
* [pyre](https://github.com/facebook/pyre-check) :warning:
557+
* [pyrefly](https://github.com/facebook/pyrefly) :warning:
557558
* [pyright](https://github.com/microsoft/pyright)
558559
* [refurb](https://github.com/dosisod/refurb) :floppy_disk:
559560
* [reorder-python-imports](https://github.com/asottile/reorder_python_imports)

test/completion/test_ale_import_command.vader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Before:
1414
let g:ale_completion_enabled = 0
1515
let g:ale_completion_autoimport = 0
1616
let g:ale_completion_max_suggestions = 50
17-
let g:ale_linters = {'typescript': ['tsserver'], 'python': ['pyre']}
17+
let g:ale_linters = {'typescript': ['tsserver'], 'python': ['pyrefly']}
1818
unlet! b:ale_linters
1919

2020
let g:server_started_value = 1

test/linter/test_pyrefly.vader

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
Before:
2+
call ale#assert#SetUpLinterTest('python', 'pyrefly')
3+
let b:bin_dir = has('win32') ? 'Scripts' : 'bin'
4+
5+
After:
6+
unlet! b:bin_dir
7+
unlet! b:executable
8+
call ale#assert#TearDownLinterTest()
9+
10+
Execute(The pyrefly command callback should return default string):
11+
call ale#test#SetFilename('./foo.py')
12+
13+
AssertLinter 'pyrefly', ale#Escape('pyrefly') . ' lsp'
14+
15+
Execute(The pyrefly executable should be configurable):
16+
let g:ale_python_pyrefly_executable = '~/.local/bin/pyrefly'
17+
18+
AssertLinter '~/.local/bin/pyrefly',
19+
\ ale#Escape('~/.local/bin/pyrefly') . ' lsp'
20+
21+
Execute(The pyrefly executable should be run from the virtualenv path):
22+
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
23+
24+
let b:executable = ale#path#Simplify(
25+
\ g:dir . '/../test-files/python/with_virtualenv/env/' . b:bin_dir . '/pyrefly'
26+
\)
27+
28+
AssertLinter b:executable, ale#Escape(b:executable) . ' lsp'
29+
30+
Execute(You should be able to override the pyrefly virtualenv lookup):
31+
call ale#test#SetFilename('../test-files/python/with_virtualenv/subdir/foo/bar.py')
32+
33+
let g:ale_python_pyrefly_use_global = 1
34+
35+
AssertLinter 'pyrefly', ale#Escape('pyrefly') . ' lsp'
36+
37+
Execute(Setting executable to 'pipenv' appends 'run pyrefly'):
38+
let g:ale_python_pyrefly_executable = 'path/to/pipenv'
39+
call ale#test#SetFilename('../test-files/dummy')
40+
41+
AssertLinter 'path/to/pipenv',
42+
\ ale#Escape('path/to/pipenv') . ' run pyrefly lsp'
43+
44+
Execute(Pipenv is detected when python_pyrefly_auto_pipenv is set):
45+
let g:ale_python_pyrefly_auto_pipenv = 1
46+
call ale#test#SetFilename('../test-files/python/pipenv/whatever.py')
47+
48+
AssertLinter 'pipenv',
49+
\ ale#Escape('pipenv') . ' run pyrefly lsp'
50+
51+
Execute(Setting executable to 'poetry' appends 'run pyrefly lsp'):
52+
let g:ale_python_pyrefly_executable = 'path/to/poetry'
53+
54+
AssertLinter 'path/to/poetry',
55+
\ ale#Escape('path/to/poetry') . ' run pyrefly lsp'
56+
57+
Execute(Poetry is detected when python_pyrefly_auto_poetry is set):
58+
let g:ale_python_pyrefly_auto_poetry = 1
59+
call ale#test#SetFilename('../test-files/python/poetry/whatever.py')
60+
61+
AssertLinter 'poetry',
62+
\ ale#Escape('poetry') . ' run pyrefly lsp'
63+
64+
Execute(uv is detected when python_pyrefly_auto_uv is set):
65+
let g:ale_python_pyrefly_auto_uv = 1
66+
call ale#test#SetFilename('../test-files/python/uv/whatever.py')
67+
68+
AssertLinter 'uv',
69+
\ ale#Escape('uv') . ' run pyrefly lsp'

test/test-files/python/with_virtualenv/env/Scripts/pyrefly.exe

Whitespace-only changes.

test/test-files/python/with_virtualenv/env/bin/pyrefly

Whitespace-only changes.

0 commit comments

Comments
 (0)