Script For Counting Lines Of Python Code?

2022-01-16 Thread tbp1...@gmail.com
I'm not a big fan of counts of lines of code, but sometimes it's fun or 
otherwise useful.  I didn't see a script to count the LOC in scripts.leo or 
PyLeoRef.leo, so I came up with one, but I wondered whether anyone else has 
a slicker one.

My script counts lines of code in a Leo subtree, not in external files.  
The subtree could be a file, but doesn't need to be.

Of course, there's the question of what counts as a line of code.  Part of 
that is whether a docstring counts.  If it does, the code is way easier 
since you don't have to figure out where a docstring begins or ends.  

My version counts all non-blank, non-comment, non-directive lines.  So it 
omits Python decorators, but there are unlikely to be enough of them to 
really matter.  Here's my script:

"""Count non-blank, non-comment, non-directive lines in subtree."""
p = c.p
nodes = p.self_and_subtree()
cnt = 0
for n in nodes:
lines = [l for l in n.b.split('\n') if l.strip()]
lines = [l for l in lines if not l.lstrip()[0] in ('#', '@')]
cnt += len(lines)
g.es(cnt, f'lines of code in "{p.h}"')

This executes pretty fast even on  a large outline like PyLeoRef, which for 
the *Code* subtree outputs

154966 lines of code in "Code" 

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/bcee2881-38ae-42bc-ac55-50d388537bc7n%40googlegroups.com.


Re: Managing Python 2.7 Code In Leo

2022-01-16 Thread tbp1...@gmail.com
The project is a Tomcat web application that uses mixed java and Jython.  
Most of the work is done with Jython, but there are some things that need 
java.  In some places, java code calls Jython objects and methods, in other 
places Jython code calls into java. It works great. I've been supporting 
and slowly developing this application since about 2007.  There is zero 
chance I would ever convert it to all java, that would be too unpleasant to 
contemplate (and my client would not want to cover the cost to do it).

On Sunday, January 16, 2022 at 2:37:00 PM UTC-5 tbp1...@gmail.com wrote:

> Can't do it for at least one case.  The code is Jython 2.7, and it will be 
> a long time, if ever, before Jython gets up to 3+.
>
> On Sunday, January 16, 2022 at 2:11:08 PM UTC-5 Edward K. Ream wrote:
>
>> On Sun, Jan 16, 2022 at 12:20 PM tbp1...@gmail.com  
>> wrote:
>>
>>> Now that Leo is Python 3.6+ only, there is a question about using it to 
>>> maintain old Python 2.x code, of which I have some that can't be converted 
>>> to Python 3.6+.  The issue, of course, is that checkers like flake8 will 
>>> report errors which aren't actual errors for 2.7 code.  This is a best a 
>>> nuisance and at worst might lead to failure to save files.
>>>
>>> What's the best way to handle these older Python files in Leo?
>>>
>>
>> Convert them to python 3.x.
>>
>> Edward
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/33adba65-bea3-4ee5-ad7b-62dd9a5a1d88n%40googlegroups.com.


Re: Managing Python 2.7 Code In Leo

2022-01-16 Thread tbp1...@gmail.com
Can't do it for at least one case.  The code is Jython 2.7, and it will be 
a long time, if ever, before Jython gets up to 3+.

On Sunday, January 16, 2022 at 2:11:08 PM UTC-5 Edward K. Ream wrote:

> On Sun, Jan 16, 2022 at 12:20 PM tbp1...@gmail.com  
> wrote:
>
>> Now that Leo is Python 3.6+ only, there is a question about using it to 
>> maintain old Python 2.x code, of which I have some that can't be converted 
>> to Python 3.6+.  The issue, of course, is that checkers like flake8 will 
>> report errors which aren't actual errors for 2.7 code.  This is a best a 
>> nuisance and at worst might lead to failure to save files.
>>
>> What's the best way to handle these older Python files in Leo?
>>
>
> Convert them to python 3.x.
>
> Edward
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/c98e67f1-adf6-4c08-b697-1a3d891ca7f6n%40googlegroups.com.


Re: Managing Python 2.7 Code In Leo

2022-01-16 Thread Edward K. Ream
On Sun, Jan 16, 2022 at 12:20 PM tbp1...@gmail.com 
wrote:

> Now that Leo is Python 3.6+ only, there is a question about using it to
> maintain old Python 2.x code, of which I have some that can't be converted
> to Python 3.6+.  The issue, of course, is that checkers like flake8 will
> report errors which aren't actual errors for 2.7 code.  This is a best a
> nuisance and at worst might lead to failure to save files.
>
> What's the best way to handle these older Python files in Leo?
>

Convert them to python 3.x.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS1t_Axk1HcTen%3DoF_EGYreDG5-UJJ5Pfm2b2Zp_3qEi7g%40mail.gmail.com.


Managing Python 2.7 Code In Leo

2022-01-16 Thread tbp1...@gmail.com
Now that Leo is Python 3.6+ only, there is a question about using it to 
maintain old Python 2.x code, of which I have some that can't be converted 
to Python 3.6+.  The issue, of course, is that checkers like flake8 will 
report errors which aren't actual errors for 2.7 code.  This is a best a 
nuisance and at worst might lead to failure to save files.

What's the best way to handle these older Python files in Leo?

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/6647a6ac-a28c-43ac-8e7a-7a05c49fd638n%40googlegroups.com.


Re: How many Leo users are still using Python3.6?

2022-01-16 Thread Edward K. Ream
On Sun, Jan 16, 2022 at 8:43 AM Josef  wrote:

> I am using Kubuntu LTS 20.04, which will still be supported for another
> year. It uses Python 3.8. I think it would be a major obstacle for Ubuntu
> LTS users to have to upgrade the Python version they are using. I have done
> that in the past, but it led to endless confusion between the versions and
> more importantly, I try to remain compatible with my colleagues at work,
> who all use either Ubuntu LTS or Debian.


Thanks for your comments. I think supporting python 3.6 indefinitely makes
sense for Leo. It also makes sense to recommend python 3.9 or 3.10.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/CAMF8tS3HvW%2BEwWmkO28raGUwb4Em%2BAd5EnAGf4KjC8D96HOwTQ%40mail.gmail.com.


Re: How many Leo users are still using Python3.6?

2022-01-16 Thread Josef
I am using Kubuntu LTS 20.04, which will still be supported for another 
year. It uses Python 3.8. I think it would be a major obstacle for Ubuntu 
LTS users to have to upgrade the Python version they are using. I have done 
that in the past, but it led to endless confusion between the versions and 
more importantly, I try to remain compatible with my colleagues at work, 
who all use either Ubuntu LTS or Debian.

Josef

On Thursday, January 13, 2022 at 10:27:28 PM UTC+1 Edward K. Ream wrote:

> On Thu, Jan 13, 2022 at 3:28 PM vitalije  wrote:
>
>> Python3.6 is already deprecated (see here 
>> ). Recently, new python 
>> importer is added to Leo which require minimum Python3.7. Rewriting it to 
>> support Python3.6 requires substantial work. Is it really necessary? Is 
>> there anyone who can't upgrade to Python3.7?
>>
>
> This is a perennial question. I personally would be happy to require 
> Python 3.9 (Python 3.10 was released over a year ago), but it's surprising 
> how long-lived old python versions are.
>
> In this case, a middle ground would be for the python importer to fail 
> gracefully on python 3.6. I'm willing to consider this option.
>
> BTW, there are known problems with the leoAst.py module on Python 3.8, but 
> that's a separate issue. In any case, leoAst.py is less important than the 
> python importer.
>
> Edward
>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/387a7c70-f1e0-48e8-b2fb-249602ce17d7n%40googlegroups.com.