Re: pep8 Re: Posting warning message

2018-06-14 Thread Cameron Simpson

On 14Jun2018 02:35, Tamara Berger  wrote:

On Thu, Jun 14, 2018 at 1:49 AM Cameron Simpson  wrote:

Just as you can run your code before you install it, you can lint your code
beforehand also. In fact, you should be doing both: run and test the code
_before_ installing it, and also lint it (when you care) and test again
(because if you made lint changes you want to check they haven't done something
unwanted).


Great. So I'm using three interfaces: in my case, the text editor, the
Python shell, and the UNIX terminal. Is that right?


Possibly; I thought you were using IDLE, which is a GUI with a simple editor 
and a Python interpreter built in?


My setup tends to be a terminal with an editor in it, and another terminal with 
a UNIX shell in it. And sometimes the Python shell in the UNIX shell in the 
terminal when I'm testing something simple. For example:


 [~/hg/css(hg:default)]fleet*> python3
 + exec /Users/cameron/var/venv/3/bin/python3
 Python 3.6.5 (default, Mar 29 2018, 15:38:28)
 [GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
 Type "help", "copyright", "credits" or "license" for more information.
 >>>

That's a python 3 shell run from the UNIX shell in a terminal. The 
"[~/hg/css(hg:default)]fleet*>" is my UNIX shell prompt, with my working 
directory, VCS branch and hostname. So "~/hg/css" is where I'm working, 
separate from where the code gets installed. For testing I run the local code, 
which might be arbitrarily bad. I don't do the "install" step until it seems 
fairly good.


Of course, the UNIX shell is there to run whatever I like. So to lint one of my 
Python files I might do this:


 [~/hg/css(hg:default)]fleet*> lint cs/sh.py
 + exec lint cs/sh.py
 + exec python3 -m py_compile cs/sh.py
 + exec /Users/cameron/var/venv/3/bin/python3 -m py_compile cs/sh.py
 + exec pyflakes cs/sh.py
 + exec pep8 
--ignore=E111,E114,E124,E126,E201,E202,E221,E226,E227,E265,E266,E301,E302,E501,E731,W503
 cs/sh.py
 + exec pylint --rcfile=/Users/cameron/.pylintrc 
--disable=bad-whitespace,invalid-name cs/sh.py
 Using config file /Users/cameron/.pylintrc
 * Module python.cs.sh
 W:105, 2: Using possibly undefined loop variable 'offset' 
 (undefined-loop-variable)


 --
 Your code has been rated at 9.85/10 (previous run: 9.85/10, +0.00)

You can see my lint script doing:

 - test compile the script (no need to bother with the rest if that fails)
 - run pyflakes on it
 - run pep8 on it
 - run pylint on it

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-14 Thread Tamara Berger
On Thu, Jun 14, 2018 at 1:49 AM Cameron Simpson  wrote:

> Just as you can run your code before you install it, you can lint your code
> beforehand also. In fact, you should be doing both: run and test the code
> _before_ installing it, and also lint it (when you care) and test again
> (because if you made lint changes you want to check they haven't done 
> something
> unwanted).

Great. So I'm using three interfaces: in my case, the text editor, the
Python shell, and the UNIX terminal. Is that right?

Tamara
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-13 Thread Cameron Simpson

On 14Jun2018 01:34, Tamara Berger  wrote:

Is it possible to do the "linting" after you've written your code but
before you install it for the first time?


Sure. I always do it that way.

Just as you can run your code before you install it, you can lint your code 
beforehand also. In fact, you should be doing both: run and test the code 
_before_ installing it, and also lint it (when you care) and test again 
(because if you made lint changes you want to check they haven't done something 
unwanted).


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-13 Thread Tamara Berger
Is it possible to do the "linting" after you've written your code but
before you install it for the first time?

Tamara
On Wed, Jun 13, 2018 at 12:30 AM Cameron Simpson  wrote:
>
> On 13Jun2018 00:05, Tamara Berger  wrote:
> >Thanks for the in-depth answer. I'm going to have to read it
> >carefully, with the help of a Python glossary. Some of the terms you
> >use are new to me.
>
> No worries. Just ask if you don't find definitions.
>
> BTW, a "lint" program, or "linter" is a program for reporting on style trivia,
> trivial logic errors like variable used before defined (or never defined, 
> which
> is often a typing error misspelling a variable or function name), and things
> that look like they might be bugs (a common mistake of mine is constructing
> exceptions like logging calls, and one of my linters has found dozens of these
> for me.)
>
> >>or am I supposed to root around for my module and make the edits one by one?
> >
> >I was trying to be amusing and didn't get my point across.
>
> Ah, ok then. Easy for stuff like that to fall flat in email.
>
> >>Finally, no you don't normally root around and change an installed module.
> >>Instead, modify your original copy and reinstall the newer version!
> >
> >What I meant was, do I have to open the file, search for, e.g., colons
> >and insert space after them? These were the sorts of picayune errors
> >picked up by PEP8 on my program. I deliberately omit such spaces when
> >I code because I like to do as little unnecessary work as possible.
> >There is enough repetitive coding as it is. I know some IDEs have word
> >completion suggestion for variables, etc, that the user creates. But
> >I'm practicing in barebones IDLE and that means a lot of extra work.
>
> Regrettably, yes, unless you're using an editor that has autoformatting
> support. Learn typing habits which minimise stuff like that, it saves going
> back later.
>
> I don't use IDEs on the whole, and I don't use an autoformatter for Python. My
> environment tends to be an editor window and a shell to run things from (thus:
> 2 terminals, one running vim and one running a shell).
>
> Training your fingers to do the trivia reflexively helps. And leaving the
> linting until _after_ you've got your code working correctly helps, because 
> you
> aren't changing tasks midstream and you are linting code you've deleted or
> changed :-)
>
> An editor with syntax support can help. I use vi or vim, and its syntax 
> support
> is fairly crude. Two things its does have which I use a lot is autoindent (as
> simple as starting the next line at the same indent as the one I just
> completed) and syntax highlighting, which colours keywords and identifiers and
> strings differently. When you make trivial mistakes like not closing a quote 
> or
> misspelling a keyword or leaving off a colon there is often a visual cue.
>
> Cheers,
> Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-12 Thread Cameron Simpson

On 13Jun2018 00:05, Tamara Berger  wrote:

Thanks for the in-depth answer. I'm going to have to read it
carefully, with the help of a Python glossary. Some of the terms you
use are new to me.


No worries. Just ask if you don't find definitions.

BTW, a "lint" program, or "linter" is a program for reporting on style trivia, 
trivial logic errors like variable used before defined (or never defined, which 
is often a typing error misspelling a variable or function name), and things 
that look like they might be bugs (a common mistake of mine is constructing 
exceptions like logging calls, and one of my linters has found dozens of these 
for me.)



or am I supposed to root around for my module and make the edits one by one?


I was trying to be amusing and didn't get my point across.


Ah, ok then. Easy for stuff like that to fall flat in email.


Finally, no you don't normally root around and change an installed module.
Instead, modify your original copy and reinstall the newer version!


What I meant was, do I have to open the file, search for, e.g., colons
and insert space after them? These were the sorts of picayune errors
picked up by PEP8 on my program. I deliberately omit such spaces when
I code because I like to do as little unnecessary work as possible.
There is enough repetitive coding as it is. I know some IDEs have word
completion suggestion for variables, etc, that the user creates. But
I'm practicing in barebones IDLE and that means a lot of extra work.


Regrettably, yes, unless you're using an editor that has autoformatting 
support. Learn typing habits which minimise stuff like that, it saves going 
back later.


I don't use IDEs on the whole, and I don't use an autoformatter for Python. My 
environment tends to be an editor window and a shell to run things from (thus: 
2 terminals, one running vim and one running a shell).


Training your fingers to do the trivia reflexively helps. And leaving the 
linting until _after_ you've got your code working correctly helps, because you 
aren't changing tasks midstream and you are linting code you've deleted or 
changed :-)


An editor with syntax support can help. I use vi or vim, and its syntax support 
is fairly crude. Two things its does have which I use a lot is autoindent (as 
simple as starting the next line at the same indent as the one I just 
completed) and syntax highlighting, which colours keywords and identifiers and 
strings differently. When you make trivial mistakes like not closing a quote or 
misspelling a keyword or leaving off a colon there is often a visual cue.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-12 Thread Tamara Berger
Hi Cameron,

Thanks for the in-depth answer. I'm going to have to read it
carefully, with the help of a Python glossary. Some of the terms you
use are new to me.

>or am I supposed to root around for my module and make the edits one by one?

I was trying to be amusing and didn't get my point across.

>Finally, no you don't normally root around and change an installed module.
>Instead, modify your original copy and reinstall the newer version!

What I meant was, do I have to open the file, search for, e.g., colons
and insert space after them? These were the sorts of picayune errors
picked up by PEP8 on my program. I deliberately omit such spaces when
I code because I like to do as little unnecessary work as possible.
There is enough repetitive coding as it is. I know some IDEs have word
completion suggestion for variables, etc, that the user creates. But
I'm practicing in barebones IDLE and that means a lot of extra work.

Thanks,

Tamara

On Tue, Jun 12, 2018 at 8:17 PM Cameron Simpson  wrote:
>
> On 12Jun2018 07:51, Tamara Berger  wrote:
> [... snip ...]
> >One more thing about PEP8. My workbook is a bit skimpy on details. Is there a
> >quick way to make the edits
>
> PEP8 is a style recommendation for Python code:
>
>   https://www.python.org/dev/peps/pep-0008/
>
> It is followed pretty rigorously in the Python standard library, and most
> Python code follows a lot of it as a matter of good practice, in that (a) it 
> is
> a fairly good style, producing easy to read code and (b) when everyone uses 
> the
> same or similar styes, we all find other people's code easier to read.
>
> But it is not enforced.
>
> There are several "lint" tools around which will look at your code and 
> complain
> about violations of PEP8 and various other constraints generally held to be
> good to obey, particularly some kinds of initialisation errors and other
> practices that while syntacticly legal may indicate bugs or lead to header to
> debug or maintain code.
>
> Also, some text editors have facilities for autostyling code, sometimes as you
> type it and sometimes as a final step when you save the modified file.
>
> For example, there are tools like autopep8 
> (https://pypi.org/project/autopep8/)
> which will modify python code directly to apply the PEP8 style.
>
> Personally, I run a few lint commands against my Python code by hand, and hand
> repair. Typical workflow goes:
>
> - modify code for whatever reason (add feature, fix bugs, etc) and test
>
> - when happy, _then_ run a lint tool and tidy up most of what it reports
>
> - _then_ instal the code where other things may use it (eg pip install)
>
> My personal kit has a "lint" shell script:
>
>   https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint
>
> which runs my preferred linters against code files, and for Python it runs:
>
> - pyflakes: https://pypi.org/project/pyflakes/
>
> - pep8: https://pypi.org/project/pep8/
>
> - pylint: https://pypi.org/project/pylint/,
>   https://pylint.readthedocs.io/en/latest/
>
> These can all be installed using pip:
>
>   pip install --user pyflakes pep8 pylint
>
> As you can see from my lint script I run them with various options that
> oveeride their default checks to better match my preffered code style.
>
> >or am I supposed to root around for my module and make the edits one by one?
>
> Finally, no you don't normally root around and change an installed module.
> Instead, modify your original copy and reinstall the newer version!
>
> Cheers,
> Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-12 Thread Chris Angelico
On Wed, Jun 13, 2018 at 10:46 AM, Gregory Ewing
 wrote:
> Cameron Simpson wrote:
>>
>> PEP8 is a style recommendation for Python code:
>>
>>  https://www.python.org/dev/peps/pep-0008/
>
>
> Specifically, it's a style guide for *code in the Python
> standard library*, as it says in the Introduction:
>
>> This document gives coding conventions for the Python code comprising
>
>> the standard library in the main Python distribution.
>
> Some of its recommendations are also good to follow in
> general Python code, but whether you do so is entirely
> up to you.

Many of its recommendations are good to follow in code written in
other languages, too :)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pep8 Re: Posting warning message

2018-06-12 Thread Gregory Ewing

Cameron Simpson wrote:

PEP8 is a style recommendation for Python code:

 https://www.python.org/dev/peps/pep-0008/


Specifically, it's a style guide for *code in the Python
standard library*, as it says in the Introduction:


This document gives coding conventions for the Python code comprising

> the standard library in the main Python distribution.

Some of its recommendations are also good to follow in
general Python code, but whether you do so is entirely
up to you.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


pep8 Re: Posting warning message

2018-06-12 Thread Cameron Simpson

On 12Jun2018 07:51, Tamara Berger  wrote:
[... snip ...]
One more thing about PEP8. My workbook is a bit skimpy on details. Is there a 
quick way to make the edits


PEP8 is a style recommendation for Python code:

 https://www.python.org/dev/peps/pep-0008/

It is followed pretty rigorously in the Python standard library, and most 
Python code follows a lot of it as a matter of good practice, in that (a) it is 
a fairly good style, producing easy to read code and (b) when everyone uses the 
same or similar styes, we all find other people's code easier to read.


But it is not enforced.

There are several "lint" tools around which will look at your code and complain 
about violations of PEP8 and various other constraints generally held to be 
good to obey, particularly some kinds of initialisation errors and other 
practices that while syntacticly legal may indicate bugs or lead to header to 
debug or maintain code.


Also, some text editors have facilities for autostyling code, sometimes as you 
type it and sometimes as a final step when you save the modified file.


For example, there are tools like autopep8 (https://pypi.org/project/autopep8/) 
which will modify python code directly to apply the PEP8 style.


Personally, I run a few lint commands against my Python code by hand, and hand 
repair. Typical workflow goes:


- modify code for whatever reason (add feature, fix bugs, etc) and test

- when happy, _then_ run a lint tool and tidy up most of what it reports

- _then_ instal the code where other things may use it (eg pip install)

My personal kit has a "lint" shell script:

 https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lint

which runs my preferred linters against code files, and for Python it runs:

- pyflakes: https://pypi.org/project/pyflakes/

- pep8: https://pypi.org/project/pep8/

- pylint: https://pypi.org/project/pylint/, 
 https://pylint.readthedocs.io/en/latest/


These can all be installed using pip:

 pip install --user pyflakes pep8 pylint

As you can see from my lint script I run them with various options that 
oveeride their default checks to better match my preffered code style.



or am I supposed to root around for my module and make the edits one by one?


Finally, no you don't normally root around and change an installed module.  
Instead, modify your original copy and reinstall the newer version!


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list