[issue25303] Add option to py_compile to compile for syntax checking without writing bytecode

2017-06-18 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Closing, as suggested above.

--
resolution:  -> out of date
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25303] Add option to py_compile to compile for syntax checking without writing bytecode

2015-10-10 Thread Pavel Roskin

Pavel Roskin added the comment:

Thank you for the comments. I was annoyed by py_compile making files with names 
very similar to the original scripts, names that could not even be recognized 
by shell patterns in .gitignore unless scripts ending with "c" are banned. But 
that problem is addressed in Python 3. I don't really care what files are in 
__pycache__, I won't have that urge to remove them. And then I simply was 
annoyed by the fact that py_compile was ignoring my attempts to suppress its 
output. Now I understand the reason for that. Migrating to Python 3 would 
address my original problem with strange looking cache files. I'm going to 
close this issue.

--
nosy: +Pavel Roskin

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25303] Add option to py_compile to compile for syntax checking without writing bytecode

2015-10-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

On the side issue: While the example given, which uses the py_compile.compile 
defaults via the command line interface, is useless, I disagree that writing a 
.pyc file for a file without .py is a bug.

Python will run python code with any filename as main module (and not write 
.pyc).  It will only import the *same code* (and normally write .pyc) if the 
filename ends with .py (or .pyw on windows).  However, 'import script' will 
import script.pyc (on the search path) without a script.py file existing.  
Using py_compile.compile('script', 'script.pyc') makes that possible.  (I just 
tried it.)

.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25303] Add option to py_compile to compile for syntax checking without writing bytecode

2015-10-09 Thread Pavel Roskin

Pavel Roskin added the comment:

That's what I have now:

check:
$(PYTHON) -m py_compile $(SOURCES)
rm -f $(addsuffix c, $(SOURCES))

make check
python -m py_compile redacted-build redacted-git-diff redacted-git-gc 
redacted-git-status redacted-init redacted-server
redactedbuilder.py
rm -f redacted-buildc redacted-git-diffc redacted-git-gcc redacted-git-statusc 
redacted-initc redacted-serverc redactedb
uilder.pyc

That's what David is suggesting:

check:
for file in $(SOURCES); do \
python -c "compile(open('$$file').read(), '', 'exec')" || exit 1; \
done

make check
for file in redacted-build redacted-git-diff redacted-git-gc 
redacted-git-status redacted-init redacted-server redactedb
uilder.py; do \
python -c "compile(open('$file').read(), '', 'exec')" || exit 1; \
done

That's what I could have if I live long enough to see Python 3.6 on my 
development machine.

check:
$(PYTHON) -m py_compile --no-output $(SOURCES)

make check
python -m py_compile --no-output redacted-build redacted-git-diff 
redacted-git-gc redacted-git-status redacted-init redacted-server
redactedbuilder.py

If that does not seem like an important improvement, then I can live with what 
I have.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25303] Add option to py_compile to compile for syntax checking without writing bytecode

2015-10-09 Thread R. David Murray

R. David Murray added the comment:

Well, the thing is that py_compile *already* has all the needed logic, the flag 
would just allow us to add an if statement before the two lines that write the 
compiled bytecode out to the file system.  py_compile also has the advantage 
that it supports the importlib loader logic.  The goal here (from my point of 
view) is to have a simple command line way of checking the syntax of a script, 
so that last may not be important.  

The python -c using 'compile(open' *is* reasonably brief, but it is not as 
elegant as the 'perl -c' mentioned in the linked stackoverflow question.  
'python -m py_compile' isn't quite a succinct as 'perl -c', but it is a lot 
closer than 

  python -c "compile(open().read(), '', 'exec')"

and a lot easier to remember.  Now, you can argue that referencing perl in this 
context is a bit of 'keeping up with the joneses', but I think there is an 
argument to be made that it is worthwhile in this case.  I won't be heartbroken 
if the idea gets shot down, though :)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25303] Add option to py_compile to compile for syntax checking without writing bytecode

2015-10-09 Thread Brett Cannon

Brett Cannon added the comment:

You can verify a script is syntactically correct by compiling it to an AST or 
just calling compile() which is another way of doing essentially what `import` 
does but without having to worry about import-related side-effects in the code 
being checked.

But is this really worth adding to the stdlib? You can run your tests to verify 
the code is syntactically sound, run pylint, etc. I think this is probably 
straying a bit too much into the tooling arena to make the maintenance burden 
worth having in the stdlib.

--
nosy: +brett.cannon

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue25303] Add option to py_compile to compile for syntax checking without writing bytecode

2015-10-09 Thread R. David Murray

R. David Murray added the comment:

OK, I'll change the title to reflect the current proposal, and we'll see if 
anyone is interested in proposing a patch.

The bug with python -m py_compile is when you do:

python -m py_compile myscript

where myscript is a file containing python code (note there is no .py 
extension).  In this case you will end up with:

  __pycache__/myscriptcpython-36.pyc

(for example).  This is clearly a bug, but should be reported in a new issue.

--
title: py_compile disregards PYTHONDONTWRITEBYTECODE and -B -> Add option to 
py_compile to compile for syntax checking without writing bytecode

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com