Re: configure.py assumes "python" command exists
Am 27.12.2021 um 20:30 schrieb José Abílio Matos : > > On Saturday, 25 December 2021 18.32.21 WET Scott Kostyshak wrote: > > On Sun, Oct 31, 2021 at 12:58:19PM -0400, Scott Kostyshak wrote: > > Hi Scott, > I find you choice of dates very convenient. :-) > > https://journeys.dartmouth.edu/folklorearchive/2016/11/12/halloween-and-christmas/ > > “Why do programmers always mix up Halloween and Christmas?” > “Because Oct 31 = Dec 25.” > > > Bump. > > > > Scott > > Regarding the problem at hand, as an example, my suggestion is to change: > > \converter pdf4 pdf8 "python $$s/scripts/convert_pdf.py $$i $$o ebook" > > to > > \converter pdf4 pdf8 "$${python} $$s/scripts/convert_pdf.py $$i $$o ebook" > > The idea is to use the converter code, e.g. the $$i $$o ..., and add there > the substitution from $${python} to the python path that we have already > determined in os::find_python. I like your proposal. Regarding the use of python calls in configure.py I’ve stolen your idea to use sys.executable and made a patch. This avoids the warning '„LyX“ needs to be updated‘ (see my RFC mail thread) and lyx starts as usual if I install python3 at first (https://www.python.org/downloads/release/python-3101) Stephan python-in-configure.patch Description: Binary data -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Mon, Dec 27, 2021 at 07:30:46PM +, José Abílio Matos wrote: > On Saturday, 25 December 2021 18.32.21 WET Scott Kostyshak wrote: > > On Sun, Oct 31, 2021 at 12:58:19PM -0400, Scott Kostyshak wrote: > > Hi Scott, > I find you choice of dates very convenient. :-) > > https://journeys.dartmouth.edu/folklorearchive/2016/11/12/halloween-and-christmas/ > > “Why do programmers always mix up Halloween and Christmas?” > “Because Oct 31 = Dec 25.” Ha that is a good one! > Regarding the problem at hand, as an example, my suggestion is to change: > > \converter pdf4 pdf8 "python $$s/scripts/convert_pdf.py $$i $$o ebook" > > to > > \converter pdf4 pdf8 "$${python} $$s/scripts/convert_pdf.py $$i $$o ebook" > > The idea is to use the converter code, e.g. the $$i $$o ..., and add there > the > substitution from $${python} to the python path that we have already > determined in os::find_python. > > Before doing that my question is if others are comfortable with this plan. > > The idea of using that syntax is to be in the same spirit as the ones we > already have: > > $$i > $$o > $$s > > and so on. > > The idea of using the curly brackets is similar to what shell (almost all the > variants) does. > > I also intend to add the -t to the command invocation, and thus removing all > those from configure.py. I like the idea of centralizing the command. That will make things easier when we switch everything back to Perl :) /s In more seriousness, I like the idea. I don't see any disadvantage to your proposal. Thanks, Scott signature.asc Description: PGP signature -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
Le 27/12/2021 à 20:30, José Abílio Matos a écrit : Regarding the problem at hand, as an example, my suggestion is to change: \converter pdf4 pdf8 "python $$s/scripts/convert_pdf.py $$i $$o ebook" to \converter pdf4 pdf8 "$${python} $$s/scripts/convert_pdf.py $$i $$o ebook" The idea is to use the converter code, e.g. the $$i $$o ..., and add there the substitution from $${python} to the python path that we have already determined in os::find_python. Looks good to me. JMarc -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Saturday, 25 December 2021 18.32.21 WET Scott Kostyshak wrote: > On Sun, Oct 31, 2021 at 12:58:19PM -0400, Scott Kostyshak wrote: Hi Scott, I find you choice of dates very convenient. :-) https://journeys.dartmouth.edu/folklorearchive/2016/11/12/halloween-and-christmas/ “Why do programmers always mix up Halloween and Christmas?” “Because Oct 31 = Dec 25.” > Bump. > > Scott Regarding the problem at hand, as an example, my suggestion is to change: \converter pdf4 pdf8 "python $$s/scripts/convert_pdf.py $$i $$o ebook" to \converter pdf4 pdf8 "$${python} $$s/scripts/convert_pdf.py $$i $$o ebook" The idea is to use the converter code, e.g. the $$i $$o ..., and add there the substitution from $${python} to the python path that we have already determined in os::find_python. Before doing that my question is if others are comfortable with this plan. The idea of using that syntax is to be in the same spirit as the ones we already have: $$i $$o $$s and so on. The idea of using the curly brackets is similar to what shell (almost all the variants) does. I also intend to add the -t to the command invocation, and thus removing all those from configure.py. Best regards, -- José Abílio-- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Sun, Oct 31, 2021 at 12:58:19PM -0400, Scott Kostyshak wrote: > On Mon, Apr 26, 2021 at 12:12:50AM -0400, Scott Kostyshak wrote: > > On Wed, Feb 24, 2021 at 01:19:30PM -0500, Scott Kostyshak wrote: > > > On Tue, Feb 23, 2021 at 06:40:46PM +, José Abílio Matos wrote: > > > > On Monday, February 15, 2021 3:25:45 PM WET Scott Kostyshak wrote: > > > > > +1 > > > > > > > > > > Thanks for taking a look, José. > > > > > > > > > > Scott > > > > > > > > OK. I have lots of issues on hand but at least this is funny. :-) > > > > > > > > One option would be to use some kind of string formatting. Actually > > > > since > > > > curly braces are usually not used in OS we could use the string format > > > > syntax > > > > (that is also used in C++20 format). One example would be: > > > > > > > > \converter pdf4 pdf8 "{python} $$s/scripts/convert_pdf.py $$i $$o > > > > ebook"... > > > > > > > > The lyx could convert internally {python} to the python path. Since lyx > > > > already has this information, or else it would not call configure.py > > > > > > > > If you do not like this option one in the same line as the other > > > > interpolations that we apply is to use $${python}. > > > > > > > > The other option is to replace this in configure.py like in the > > > > following > > > > patch that I have not yet tested. > > > > > > > > What do you think? > > > > > > Thanks for working on it, José! I don't have an opinion on which > > > approach is best. I can test the patch, but first perhaps I'll wait to > > > see if others have comments. > > > > Does anyone have an opinion on the options José proposed? > > Ping to lyx-devel. > > If no one responds, I suggest that José chooses which one he likes the most, > or flips a coin. > > José, I think you just mentioned you don't have any time, so don't worry if > you can't get to this soon. Bump. Scott signature.asc Description: PGP signature -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Mon, Apr 26, 2021 at 12:12:50AM -0400, Scott Kostyshak wrote: > On Wed, Feb 24, 2021 at 01:19:30PM -0500, Scott Kostyshak wrote: > > On Tue, Feb 23, 2021 at 06:40:46PM +, José Abílio Matos wrote: > > > On Monday, February 15, 2021 3:25:45 PM WET Scott Kostyshak wrote: > > > > +1 > > > > > > > > Thanks for taking a look, José. > > > > > > > > Scott > > > > > > OK. I have lots of issues on hand but at least this is funny. :-) > > > > > > One option would be to use some kind of string formatting. Actually since > > > curly braces are usually not used in OS we could use the string format > > > syntax > > > (that is also used in C++20 format). One example would be: > > > > > > \converter pdf4 pdf8 "{python} $$s/scripts/convert_pdf.py $$i $$o > > > ebook"... > > > > > > The lyx could convert internally {python} to the python path. Since lyx > > > already has this information, or else it would not call configure.py > > > > > > If you do not like this option one in the same line as the other > > > interpolations that we apply is to use $${python}. > > > > > > The other option is to replace this in configure.py like in the following > > > patch that I have not yet tested. > > > > > > What do you think? > > > > Thanks for working on it, José! I don't have an opinion on which > > approach is best. I can test the patch, but first perhaps I'll wait to > > see if others have comments. > > Does anyone have an opinion on the options José proposed? Ping to lyx-devel. If no one responds, I suggest that José chooses which one he likes the most, or flips a coin. José, I think you just mentioned you don't have any time, so don't worry if you can't get to this soon. Scott signature.asc Description: PGP signature -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Wed, Feb 24, 2021 at 01:19:30PM -0500, Scott Kostyshak wrote: > On Tue, Feb 23, 2021 at 06:40:46PM +, José Abílio Matos wrote: > > On Monday, February 15, 2021 3:25:45 PM WET Scott Kostyshak wrote: > > > +1 > > > > > > Thanks for taking a look, José. > > > > > > Scott > > > > OK. I have lots of issues on hand but at least this is funny. :-) > > > > One option would be to use some kind of string formatting. Actually since > > curly braces are usually not used in OS we could use the string format > > syntax > > (that is also used in C++20 format). One example would be: > > > > \converter pdf4 pdf8 "{python} $$s/scripts/convert_pdf.py $$i $$o > > ebook"... > > > > The lyx could convert internally {python} to the python path. Since lyx > > already has this information, or else it would not call configure.py > > > > If you do not like this option one in the same line as the other > > interpolations that we apply is to use $${python}. > > > > The other option is to replace this in configure.py like in the following > > patch that I have not yet tested. > > > > What do you think? > > Thanks for working on it, José! I don't have an opinion on which > approach is best. I can test the patch, but first perhaps I'll wait to > see if others have comments. Does anyone have an opinion on the options José proposed? Scott signature.asc Description: PGP signature -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Tue, Feb 23, 2021 at 06:40:46PM +, José Abílio Matos wrote: > On Monday, February 15, 2021 3:25:45 PM WET Scott Kostyshak wrote: > > +1 > > > > Thanks for taking a look, José. > > > > Scott > > OK. I have lots of issues on hand but at least this is funny. :-) > > One option would be to use some kind of string formatting. Actually since > curly braces are usually not used in OS we could use the string format syntax > (that is also used in C++20 format). One example would be: > > \converter pdf4 pdf8 "{python} $$s/scripts/convert_pdf.py $$i $$o ebook"... > > The lyx could convert internally {python} to the python path. Since lyx > already has this information, or else it would not call configure.py > > If you do not like this option one in the same line as the other > interpolations that we apply is to use $${python}. > > The other option is to replace this in configure.py like in the following > patch that I have not yet tested. > > What do you think? Thanks for working on it, José! I don't have an opinion on which approach is best. I can test the patch, but first perhaps I'll wait to see if others have comments. Scott signature.asc Description: PGP signature -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Monday, February 15, 2021 3:25:45 PM WET Scott Kostyshak wrote: > +1 > > Thanks for taking a look, José. > > Scott OK. I have lots of issues on hand but at least this is funny. :-) One option would be to use some kind of string formatting. Actually since curly braces are usually not used in OS we could use the string format syntax (that is also used in C++20 format). One example would be: \converter pdf4 pdf8 "{python} $$s/scripts/convert_pdf.py $$i $$o ebook"... The lyx could convert internally {python} to the python path. Since lyx already has this information, or else it would not call configure.py If you do not like this option one in the same line as the other interpolations that we apply is to use $${python}. The other option is to replace this in configure.py like in the following patch that I have not yet tested. What do you think? -- José Abíliodiff --git a/lib/configure.py b/lib/configure.py index 43073e901d..4e08ef6776 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -29,7 +29,10 @@ formatter = logging.Formatter('%(message)s') # only print out the message itself console.setFormatter(formatter) logger = logging.getLogger('LyX') logger.addHandler(console) - +interpreter = sys.executable +if interpreter == '': +interpreter = "python" + def quoteIfSpace(name): " utility function: quote name if it contains spaces " if ' ' in name: @@ -52,7 +55,7 @@ def addToRC(lines): add newline at the end of lines. ''' if lines.strip(): -writeToFile(outfile, lines + '\n', append = True) +writeToFile(outfile, lines.format(python=interpreter) + '\n', append = True) logger.debug('Add to RC:\n' + lines + '\n\n') @@ -653,7 +656,7 @@ def checkLatex(dtl_tools): if dtl_tools: # Windows only: DraftDVI addToRC(r'''\converter latex dvi2 "%s" "latex,hyperref-driver=dvips" -\converter dvi2 dvi"python -tt $$s/scripts/clean_dvi.py $$i $$o" ""''' % LATEX) +\converter dvi2 dvi"{python} $$s/scripts/clean_dvi.py $$i $$o" ""''' % LATEX) else: addToRC(r'\converter latex dvi"%s" "latex,hyperref-driver=dvips"' % LATEX) # no latex @@ -943,7 +946,7 @@ def checkConverterEntries(): checkProg('an HTML -> LaTeX converter', ['html2latex $$i', 'gnuhtml2latex', 'htmltolatex -input $$i -output $$o', 'htmltolatex.jar -input $$i -output $$o'], rc_entry = [ r'\converter html latex "%%" ""', - r'\converter html latex "python -tt $$s/scripts/html2latexwrapper.py %% $$i $$o" ""', + r'\converter html latex "{python} $$s/scripts/html2latexwrapper.py %% $$i $$o" ""', r'\converter html latex "%%" ""', r'\converter html latex "%%" ""', '' ]) # @@ -964,8 +967,8 @@ def checkConverterEntries(): ['elyxer.py --html --nofooter --unicode --directory $$r $$i $$o', 'elyxer --html --nofooter --unicode --directory $$r $$i $$o'], rc_entry = [ r'\converter lyx word "%%" ""' ]) if elyxer.find('elyxer') >= 0: - addToRC(r'''\copierhtml "python -tt $$s/scripts/ext_copy.py -e html,png,jpg,jpeg,css $$i $$o"''') - addToRC(r'''\copierwordhtml "python -tt $$s/scripts/ext_copy.py -e html,png,jpg,jpeg,css $$i $$o"''') + addToRC(r'''\copierhtml "{python} $$s/scripts/ext_copy.py -e html,png,jpg,jpeg,css $$i $$o"''') + addToRC(r'''\copierwordhtml "{python} $$s/scripts/ext_copy.py -e html,png,jpg,jpeg,css $$i $$o"''') else: # search for HTML converters other than eLyXer # On SuSE the scripts have a .sh suffix, and on debian they are in /usr/share/tex4ht/ @@ -974,24 +977,24 @@ def checkConverterEntries(): 'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'], rc_entry = [ r'\converter latex html "%%" "needaux"' ]) if htmlconv.find('htlatex') >= 0 or htmlconv == 'latex2html': -addToRC(r'''\copierhtml "python -tt $$s/scripts/ext_copy.py -e html,png,css $$i $$o"''') +addToRC(r'''\copierhtml "{python} $$s/scripts/ext_copy.py -e html,png,css $$i $$o"''') else: -addToRC(r'''\copierhtml "python -tt $$s/scripts/ext_copy.py $$i $$o"''') +addToRC(r'''\copierhtml "{python} $$s/scripts/ext_copy.py $$i $$o"''') path, htmlconv = checkProg('a LaTeX -> HTML (MS Word) converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'", "htlatex.sh $$i 'html,word' 'symbol/!' '-cvalidate'", "/usr/share/tex4ht/htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"], rc_entry = [ r'\converter latex wordhtml "%%" "needaux"' ]) if htmlconv.find('htlatex') >= 0: -addToRC(r'''\copierwordhtml "python -tt $$s/scripts/ext_copy.py -e html,png,css $$i
Re: configure.py assumes "python" command exists
On Mon, Feb 15, 2021 at 09:50:04AM -0500, Richard Kimberly Heck wrote: > On 2/15/21 5:56 AM, José Abílio Matos wrote: > > > > On Monday, February 15, 2021 4:27:40 AM WET Richard Kimberly Heck wrote: > > > > > We have a Python detection routine, find_python_binary(), so it could be > > > > > modified to check for those commands explicitly. I'm reluctant to touch > > > > > that code myself though. > > > > > > The detection code in LyX is working correctly, it works if the name > > is not python. The code searches for python39 or python3.9 or ... > > > > > > The issue that Scott is raising is different. The problem is that > > configure.py always issue a "python" as the python name. When we get > > here the lyx detection code already worked correctly. > > > > > > I had thought previously about this and I have an idea to fix this. > > > > > > """ > > > > import os, sys > > > > > > print(os.path.basename(sys.executable)) > > > > """ > > > > > > so the idea is to replace "python" by os.path.basename(sys.executable) > > in all the calls on configure.py. > > > > > > This code is general, since it takes care of the directory separators, > > and it should work everywhere. > > > > > > > > Funnily enough the function rescanTeXFiles (line 1920) already does > > that. :-) > > > > > > For the next stable release if we assume a minimum of python 3.6 we > > can use the f-strings (formatted in case you wonder :-) ) and the code > > could be simply. > > > > > > python = os.path.basename(sys.executable); > > > > ... > > > > > > print (f"{python}") > > > > > > so that the content of variable python is replaced inside the function... > > > Well, José, you are the expert on this, so please go ahead. It probably > would be good to have this for the next release (probably beta 1). +1 Thanks for taking a look, José. Scott signature.asc Description: PGP signature -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On 2/15/21 5:56 AM, José Abílio Matos wrote: > > On Monday, February 15, 2021 4:27:40 AM WET Richard Kimberly Heck wrote: > > > We have a Python detection routine, find_python_binary(), so it could be > > > modified to check for those commands explicitly. I'm reluctant to touch > > > that code myself though. > > > The detection code in LyX is working correctly, it works if the name > is not python. The code searches for python39 or python3.9 or ... > > > The issue that Scott is raising is different. The problem is that > configure.py always issue a "python" as the python name. When we get > here the lyx detection code already worked correctly. > > > I had thought previously about this and I have an idea to fix this. > > > """ > > import os, sys > > > print(os.path.basename(sys.executable)) > > """ > > > so the idea is to replace "python" by os.path.basename(sys.executable) > in all the calls on configure.py. > > > This code is general, since it takes care of the directory separators, > and it should work everywhere. > > > > Funnily enough the function rescanTeXFiles (line 1920) already does > that. :-) > > > For the next stable release if we assume a minimum of python 3.6 we > can use the f-strings (formatted in case you wonder :-) ) and the code > could be simply. > > > python = os.path.basename(sys.executable); > > ... > > > print (f"{python}") > > > so that the content of variable python is replaced inside the function... > Well, José, you are the expert on this, so please go ahead. It probably would be good to have this for the next release (probably beta 1). Riki -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Monday, February 15, 2021 4:27:40 AM WET Richard Kimberly Heck wrote: > We have a Python detection routine, find_python_binary(), so it could be > modified to check for those commands explicitly. I'm reluctant to touch > that code myself though. The detection code in LyX is working correctly, it works if the name is not python. The code searches for python39 or python3.9 or ... The issue that Scott is raising is different. The problem is that configure.py always issue a "python" as the python name. When we get here the lyx detection code already worked correctly. I had thought previously about this and I have an idea to fix this. """ import os, sys print(os.path.basename(sys.executable)) """ so the idea is to replace "python" by os.path.basename(sys.executable) in all the calls on configure.py. This code is general, since it takes care of the directory separators, and it should work everywhere. Funnily enough the function rescanTeXFiles (line 1920) already does that. :-) For the next stable release if we assume a minimum of python 3.6 we can use the f-strings (formatted in case you wonder :-) ) and the code could be simply. python = os.path.basename(sys.executable); ... print (f"{python}") so that the content of variable python is replaced inside the function... -- José Abílio-- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On 2/14/21 7:43 PM, Scott Kostyshak wrote: > Some things did not work when I compiled on Ubuntu 20.10 because by > default Ubuntu 20.10 does not have a "python" command and instead > realies on "python2" and "python3" commands. The fix is easy: just > needed to install the package "python-is-python3". I don't know much > about this, but I think it is partly explained here: > > https://www.python.org/dev/peps/pep-0394/#recommendation > > LyX's configure.py assumes that the command "python" exists when setting > the commands of some converters. Is this something we want to fix? Would > it be reasonable for configure.py to just capture the path to the python > command that it is called with and pass that on when it is setting the > converter commands? > > Or for the next release cycle would it be reasonable to change all > "python" commands to "python3" commands or is that not portable for all > modern platforms (by the time the next major version is released)? We have a Python detection routine, find_python_binary(), so it could be modified to check for those commands explicitly. I'm reluctant to touch that code myself though. Riki -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
Re: configure.py assumes "python" command exists
On Mon, 15 Feb 2021 at 01:43, Scott Kostyshak wrote: > Some things did not work when I compiled on Ubuntu 20.10 because by > default Ubuntu 20.10 does not have a "python" command and instead > realies on "python2" and "python3" commands. The fix is easy: just > needed to install the package "python-is-python3". I don't know much > about this, but I think it is partly explained here: > > https://www.python.org/dev/peps/pep-0394/#recommendation > > LyX's configure.py assumes that the command "python" exists when setting > the commands of some converters. Is this something we want to fix? Would > it be reasonable for configure.py to just capture the path to the python > command that it is called with and pass that on when it is setting the > converter commands? > > Or for the next release cycle would it be reasonable to change all > "python" commands to "python3" commands or is that not portable for all > modern platforms (by the time the next major version is released)? > At least for the Anaconda distribution on Windows, there is no python3.exe, just python.exe (even if it's version 3.8). -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel
configure.py assumes "python" command exists
Some things did not work when I compiled on Ubuntu 20.10 because by default Ubuntu 20.10 does not have a "python" command and instead realies on "python2" and "python3" commands. The fix is easy: just needed to install the package "python-is-python3". I don't know much about this, but I think it is partly explained here: https://www.python.org/dev/peps/pep-0394/#recommendation LyX's configure.py assumes that the command "python" exists when setting the commands of some converters. Is this something we want to fix? Would it be reasonable for configure.py to just capture the path to the python command that it is called with and pass that on when it is setting the converter commands? Or for the next release cycle would it be reasonable to change all "python" commands to "python3" commands or is that not portable for all modern platforms (by the time the next major version is released)? Scott signature.asc Description: PGP signature -- lyx-devel mailing list lyx-devel@lists.lyx.org http://lists.lyx.org/mailman/listinfo/lyx-devel