gentoo / gentoo-syntax

[MIRROR] Gentoo Ebuild, Eclass, GLEP, ChangeLog and Portage Files syntax highlighting, filetype and indent settings for Vim
https://gitweb.gentoo.org/proj/gentoo-syntax.git
Other
27 stars 29 forks source link

Python detection relies on eselect-python #35

Closed shibotto closed 2 years ago

shibotto commented 2 years ago

When eselect-python is not installed (which by now should be norm) creating a python related ebuild results in:

...

PYTHON_COMPAT=( !!! Error: Can't load module pythonexiting )

...

I think it needs to be updated to query PYTHON_TARGETS or PYTHON_SINGLE_TARGET.

mgorny commented 2 years ago

Do you have a suggestion on how we could do that?

Maybe I should just replace it with something like processing the output of:

python -c 'import epython; print(epython.EPYTHON)'

I think that could be a reasonable default, assuming that the user is likely to test the package on the current Python version.

shibotto commented 2 years ago

IMHO that sounds good.

mgorny commented 2 years ago

Could you please test the git master now, and lemme know whether it helped you? I'll make a release then.

You can basically:

cp plugin/gentoo-common.vim /usr/share/vim/vimfiles/plugin/gentoo-common.vim
shibotto commented 2 years ago

Works OK for me, this is the complete ebuild template I get:

# Copyright 2021 Gentoo Authors                                                     
# Distributed under the terms of the GNU General Public License v2                  

EAPI=8                                                                              

PYTHON_COMPAT=( python3_9 )                                                         
inherit distutils-r1                                                                

DESCRIPTION=""                                                                         
HOMEPAGE=""                                                                         
SRC_URI=""                                                                          

LICENSE=""                                                                          
SLOT="0"                                                                            
KEYWORDS=""                                                                         

DEPEND=""                                                                           
RDEPEND="${DEPEND}"                                                                 
BDEPEND=""

(KEYWORDS is missing because I made a -9999.ebuild)

msva commented 2 years ago

And what about taking pythons directly from ${EPREFIX}/etc/python-exec/python-exec.conf file? Or can it be valid for it to not exist on non-broken system?

mgorny commented 2 years ago

It effectively does that, by calling python through python-exec.

msva commented 2 years ago

It effectively does that, by calling python through python-exec.

Yeah, I've edited the message to reflect what I mean a second before your reply.

I mean: maybe it would worth to read the file directly, and take all the versions described there, and not just print current active version (like that python command does here on my system, at least)

mgorny commented 2 years ago

Hmm, I suppose that makes sense too but TBH my vim-foo is too weak for that.

msva commented 2 years ago

I'll try to do something like that in few hours (when finish up with tree-sitter PR stuff)

msva commented 2 years ago

@mgorny, WDYT?

diff --git i/plugin/gentoo-common.vim w/plugin/gentoo-common.vim
index 42b2451..5c4b830 100644
--- i/plugin/gentoo-common.vim
+++ w/plugin/gentoo-common.vim
@@ -56,8 +56,19 @@ fun! GentooGetPythonTargets()
     if exists("g:gentoopythontargets") && g:gentoopythontargets != ""
         return g:gentoopythontargets
     else
-        let l:py3 = system("python -c 'import epython; print(epython.EPYTHON)'")
-        let l:py3 = substitute(l:py3, "\n", "", "g")
+        let l:py3_list = []
+        for item in readfile('/etc/python-exec/python-exec.conf')
+            let l:py = matchstr(item,'^python.*')
+            if !empty(l:py)
+                call add(l:py3_list,l:py)
+            endif
+        endfor
+        if !empty(l:py3_list)
+            let l:py3 = join(l:py3_list)
+        else
+            let l:py3 = system("python -c 'import epython; print(epython.EPYTHON)'")
+            let l:py3 = substitute(l:py3, "\n", "", "g")
+        endif

         let l:pythons = substitute(l:py3, "[.]", "_", "g")
mgorny commented 2 years ago

Could you submit that as PR, so I can comment on specific lines, plz?