how to improve simple python shell script (to compile list of files)
[Keep CC, thank you] Please suggest comments how can I make this script to work from bash. Also how can I skip better the [0] argument from command line without hte extra variable i? #!/bin/bash function compile () { python -c ' import os, sys, py_compile; i = 0; for arg in sys.argv: file = os.path.basename(arg); dir = os.path.dirname(arg); i += 1; if i > 1 and os.path.exists(dir): os.chdir(dir); print "compiling %s\n" % (file); py_compile.compile(file); ' $* } compile $(find path/to -type f -name "*.py") # End of example The error message reads: File "", line 2 import os, sys, py_compile; ^ SyntaxError: invalid syntax Jari -- http://mail.python.org/mailman/listinfo/python-list
Re: how to improve simple python shell script (to compile list of files)
"Fredrik Lundh" <[EMAIL PROTECTED]> writes: > Jari Aalto wrote: > | > Please suggest comments how can I make this script to work | > from bash. > > replace it with a call to the compileall module? > > $ python -mcompileall [directory...] Thanks, but that will not work. The files are gathered from discrete places and I'd need advice why the simple -c options does not accept the code inside parentheses. Are there some restrictions in Python to use only "all in one line"? I mean: python -c "command; command ...; command; ..." Jari -- http://mail.python.org/mailman/listinfo/python-list
Re: how to improve simple python shell script (to compile list of files)
"Chris F.A. Johnson" <[EMAIL PROTECTED]> writes: > On 2005-10-15, Jari Aalto wrote: >Don't indent: > > function compile () > { > python -c ' > import os, sys, py_compile; > i = 0; > for arg in sys.argv: > file = os.path.basename(arg); > dir = os.path.dirname(arg); > i += 1; > if i > 1 and os.path.exists(dir): > os.chdir(dir); > print "compiling %s\n" % (file); > py_compile.compile(file); > ' $* > } Thanks, is there equivalent to this Perl statement in Python? @list = @ARGV[1 .. @ARGV]; or something similar so that I could avoid the 1 > 1 (sys.argv) check altogether? Jari -- http://mail.python.org/mailman/listinfo/python-list
distutils - Is is possible to install without the .py extensions
Given following setup.py stanza: #!/usr/bin/python from distutils.core import setup import glob setup(name='program', description='', keywords='', version='', url='', download_url='', license='', author='', author_email='', long_description=""" """, scripts = ['program,py'], packages = ['''], ) Is there any way to fix the installation (postinstall or something), so that the the result is: /usr/bin/program instead of: /usr/bin/program.py Jari -- Welcome to FOSS revolution: we fix and modify until it shines -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils - Is is possible to install without the .py extensions
* Fri 2008-03-07 Robert Kern <[EMAIL PROTECTED]> gmane.comp.python.general * Message-Id: [EMAIL PROTECTED] > Jari Aalto wrote: >> #!/usr/bin/python >> >> from distutils.core import setup >> import glob >> >> setup(name='program', ... >> scripts = ['program,py'], >> ) >> that the the result is: >> >> /usr/bin/program >> >> instead of: >> >> /usr/bin/program.py > > The easiest and best way is to just rename the file in your source tree to > "program" and be done with it. Is there any other way? This is the source package that I would like to keep intact and just patch the setup.py Jari -- Welcome to FOSS revolution: we fix and modify until it shines -- http://mail.python.org/mailman/listinfo/python-list
Re: distutils - Is is possible to install without the .py extensions
* Fri 2008-03-07 Robert Kern <[EMAIL PROTECTED]> gmane.comp.python.general * Message-Id: [EMAIL PROTECTED] setup(name='program', >> ... scripts = ['program,py'], ) that the the result is: /usr/bin/program instead of: /usr/bin/program.py >>> >>> The easiest and best way is to just rename the file in your source tree to >>> "program" and be done with it. >> >> Is there any other way? This is the source package that I would like >> to keep intact and just patch the setup.py > > Not really, no. Why is it so important to only patch the setup.py > file and not any others? It has to do with generating a diff against the original package. If the file is moved: mv file.py file prior setup.py run (which, according to answers, would have a change to <>), the problem is the generated diff against original sources: + would flag removal of 'file.py' + inclusion of 'file' The ideal would be if setup.py could do all the destination install "postwork". The generated patch would be clean and only contain changes in setup.py. But I understand, if distutils does not support stripping the extensions during install. It just cacuses exra work for utility packagers. Jari -- Welcome to FOSS revolution: we fix and modify until it shines -- http://mail.python.org/mailman/listinfo/python-list