Q: How to generate code object from bytecode?
Hi, It is possible to get bytecode from code object. Reversely, is it possible to create code object from bytecode? ex. ## python code (not a module) pycode = '''\ print "\n" for item in items: print "%s\n" % item print "\n" ''' ## compile it and get bytecode code = compile(pycode, kind='exec') bytecode = code.co_code open('hoge.pyc', 'wb').write(bytecode) ## load bytecode and eval it bytecode = open('hoge.pyc', 'rb').read() code = create_code(bytecode)## how to ? output = eval(code, globals, {'items': ['A', 'B', 'C']}) -- regards, kwatch -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: How to generate code object from bytecode?
Thanks Fredrik and Carsten, I'll try marshal module. > * Your code snippet is a statement, actually, a suite of statements. You > need to exec it, not eval it. > * You seem to think that eval'ing or exec'ing a code object will > magically capture its output stream. It won't. Oh, it's my mistake. > What do you actually want to accomplish? I'm now developping embedded python text converter. ex. example.pyhtml title ${item} ex. converted python code _buf = []; _buf.append('''title \n'''); for item in items: _buf.append(''' '''); _buf.append(escape(to_str(item))); _buf.append('''\n'''); #end _buf.append('''\n'''); -- regards, kwatch -- http://mail.python.org/mailman/listinfo/python-list
[Q] module name available in 'from ... import ...' statement
What is the condition of module name which is available in 'from .. import ..' statement ? import os print os.path # from posixpath import sep # (no errors) from os.path import sep# (no errors, wow!) path = os.path from path import sep # ImportError: No module named path I found that library 'os.py' exists but 'os/path.py' doesn't exist in '/usr/local/lib/python2.5'. It means that file 'os/path.py' is not required to perform 'from os.path import sep' statement. Could you teach me the condition of module name which is available in 'from ... import ...' statement? The goal what I want to do is to create a module by 'new' module and specify that module name in 'from ...' statement. # create a module import new foo = new.module('foo') foo.pi = 3.14159 foo.x2 = lambda x: 2*x # specify it in 'from' statement from foo import pi, x2 # ImportError: No module named foo -- regards, kwatch -- http://mail.python.org/mailman/listinfo/python-list
Re: module name available in 'from ... import ...' statement
Thanks Carsten and Gabriel, the answer is 'sys.modules'. import sys, os from path import sep# ImportError: No module named path sys.modules['path'] = os.path from path import sep# (no error) I can now import from my module which is generated by 'new' module. # create a module import new foo = new.module('foo') foo.pi = 3.14159 foo.x2 = lambda x: 2*x # register it to sys.modules import sys sys.modules['foo'] = foo # import from that module from foo import pi, x2 Great. > Not that this can't be done, but why do you think you have to create > this 'foo' module on the fly? What is the actual problem you're trying > to solve? I have a package which has several small modules and I want to integrate them into a file, with keeping compatibility. current: mylib/ __init__.py html.py xhtml.py xml.py : : future: mylib.py -- regards, kwatch "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Mon, 30 Apr 2007 20:19:54 -0300,kwatch<[EMAIL PROTECTED]> escribió: > > > Could you teach me the condition of module name which is available > > in 'from ... import ...' statement? > > > The goal what I want to do is to create a module by 'new' module > > and specify that module name in 'from ...' statement. > > You can create the module with imp.new_module, populate it, and then > insert it inside sys.modules: > > py> from imp import * > py> m = new_module("foo") > py> m > > py> m.a = 1 > py> def test(): > ... print "Function test inside foo module" > ... > py> m.test = test > py> import sys > py> sys.modules["foo"]=m > py> m > > py> foo > Traceback (most recent call last): >File "", line 1, in > NameError: name 'foo' is not defined > py> import foo > py> foo.test() > Function test inside foo module > > But, why do you want to do this exactly? > > -- > Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
[Q] result of os.times() is different with 'time' command
Hi, I have a question about os.times(). os.times() returns a tuple containing user time and system time, but it is not matched to the result of 'time' command. For example, os.times() reports that user time is 39.85 sec, but 'time' command reports that user time is 28.55sec. (machine: Python2.5, MacOS X 10.4 Tiger, MacBook 1.83GHz intel core duo) file: ostimetest.py import os ## benchmark function def f(x): if x <= 1: return 1 else: return f(x-1) + f(x-2) ## do benchmark n = 35 t1 = os.times() # start time v = f(n)# end time print "n=%d, v=%d" % (n, v) t2 = os.times() ## print result utime = t2[0] - t1[0] # user time stime = t2[1] - t1[1] # system time print "utime=%s, stime=%s" % (utime, stime) Result: $ python -V Python 2.5 $ time python ostimetest.py n=35, v=14930352 utime=39.85, stime=0.2167 real0m28.554suser0m23.938ssys 0m0.177s This shows that os.times() reports that user time is 39.85sec, but time command shows that user time is 23.938sec. Why os.times() reports wrong result? Do I have any mistake? -- kwatch -- http://mail.python.org/mailman/listinfo/python-list
Re: result of os.times() is different with 'time' command
Thank you, aspineux and Douglas. Douglas's analysis is especially great. I changed HZ to CLK_TCK in Python-2.5/Modules/posixmodule.c and got the proper result! $ time /usr/local/python2.5/bin/python ostimetest.rb n=35, v=14930352 utime=12.42, stime=0.04 real0m13.621s user0m12.438s sys 0m0.063s Great job, Douglas. -- regards, kwatch [EMAIL PROTECTED] (Douglas Wells) wrote: > [various posting problems corrected and response interspersed in > previous post for purposes of coherent response] > > In article <[EMAIL PROTECTED]>, > > > > "aspineux" <[EMAIL PROTECTED]> writes: > > On 2 Feb, 19:30, [EMAIL PROTECTED] wrote: > > > Hi, > > > > I have a question about os.times(). > > > os.times() returns a tuple containing user time and system time, > > > but it is not matched to the result of 'time' command. > > > For example, os.times() reports that user time is 39.85 sec, > > > but 'time' command reports that user time is 28.55sec. > > > (machine: Python2.5, MacOS X 10.4 Tiger, MacBook 1.83GHz intel core > > > duo) > > > > [ source elided ] > > > I dont see anything wrong ! > > Did you try to measure time with your watch ? > > Did you try a simple python test.py without the time command ? > > Maybe python is 'disturbed' by the intel core > > > can you try this ? > > > # strace python test.py 2>&1 | grep time > > times({tms_utime=1, tms_stime=1, tms_cutime=0, tms_cstime=0}) = > > 43021 > > times({tms_utime=2238, tms_stime=2, tms_cutime=0, tms_cstime=0}) = > > 430220049 > > write(1, "n=35, v=14930352\nutime=22.37, st"..., 41n=35, v=14930 52 > > utime=22.37, stime=0.01 > > Note that this likely won't work. First, strace is not native to > OS X; ktrace is the analogous native command. Second, OS X almost > certainly implements the times system call in terms of getrusage. > > > > > > Result: > > > > > > $ python -V > > > Python 2.5 > > > $ time python ostimetest.py > > > n=35, v=14930352 > > > utime=39.85, stime=0.2167 > > > real0m28.554suser0m23.938ssys 0m0.177s > > > > > > > This shows that os.times() reports that user time is 39.85sec, > > > but time command shows that user time is 23.938sec. > > > Why os.times() reports wrong result? Do I have any mistake? > > > > -- > > > kwatch > > Yes, I can reproduce this on my FreeBSD system. No, I do not believe > that you have made a mistake. Yes, I believe that you have uncovered > a bug in the Python os/posix modules. > > Here's my analysis (although I should note that I've not looked > at the source of Python previously). I'm looking at Python 2.4.3, > but this looks like a long existing bug: > > The following code exists in the source code module > Modules/posixmodule.c @ posix_times: > struct tms t; > clock_t c; > [ ... ] > c = times(&t); > [ ... ] > return Py_BuildValue("d", > (double)t.tms_utime / HZ, > (double)t.tms_stime / HZ, > (double)t.tms_cutime / HZ, > (double)t.tms_cstime / HZ, > (double)c / HZ); > This is incorrect. It should not be dividing by HZ, but by the > result of the dynamic value 'sysconf (_SC_CLK_TCK)'. Even if > it were to use a compile time value, the proper value would be > CLK_TCK, not HZ. > > So here's what's happening. Neither my FreeBSD nor the OP's Mac > defines HZ as a compile time variable, but the same source module > also contains the following code: > #ifndef HZ > #define HZ 60 /* Universal constant :-) */ > #endif /* HZ */ > So, the Python posix module is using 60 instead of the proper > value, which happens to be 128 on my FreeBSD, and 100 on the OP's > OS X(*). (BTW, this sort of historic code is exactly why POSIX > no longer defines HZ.) > > In support of this, I note that the following ratios exist: > user time from os.times / user time from time command > 39.85 / 23.938 => 1.665 > CLK_TCK / HZ > 100 / 60 => 1.667 > which are in reasonably close agreement! > > - dmw > > [*] I've actually only looked at OS X for the PPC platform, not > for the User's Intel platform, but I'm fairly certain that the > CLK_TCK value is the same on both. > > -- > . Douglas Wells . Connection Technologies . > . Internet: -sp9804- -at - contek.com- . -- http://mail.python.org/mailman/listinfo/python-list
Re: pyYaml community
you should subscribe yaml-core mailing list. mailto:[EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/yaml-core this is what you want. -- kwatch Imbaud Pierre <[EMAIL PROTECTED]> wrote: > I began using pyYaml. > I found no place where pyYaml users exchange ideas, know-how, etc > (as here for python). > There is a wiki, a bug tracker, documentation, but such a place > (mailing list, newsgroup, forum, or even IRC) is a must (IMHO) to smooth > the learning curve. > Does someone know better? > > My concern: yaml allows "complex data" as keys to dicts. > I need tuples as keys, pyYaml turns my yaml sequences into lists, > and then yells list cant be used as keys. No way to turn my yaml > sequences into tuples? > Oh, I found! RTFM, as usual! > (the first question sticks) -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyKook 0.0.1 - a simple build tool similar to Make or Ant
Hi all, I have released pyKook 0.0.1. http://pypi.python.org/pypi/Kook/0.0.1 http://www.kuwata-lab.com/kook/ http://www.kuwata-lab.com/kook/pykook-users-guide.html pyKook is a simple build tool similar to Make, Ant, Rake, or SCons. pyKook regards software project as cooking. Terms used in pyKook are cooking terms. For example: cookbook- Makefile product - target file ingredient - source file recipe - how to create target from source Cookbook (= Makefile) is written in pure Python. You can write any statements or expressions in cookbook. Example of cookbook (Kookbook.py): -- ## ## properties ## cc = prop('cc', 'gcc') cflags = prop('cflags', '-g -Wall') ## ## recipes ## @ingreds("hello") def task_all(c): pass @product("hello") @ingreds("hello.o") def file_command(c): """generates hello command""" system(c%"$(cc) $(cflags) -o $(product) $(ingred)") @product("*.o") @ingreds("$(1).c", if_exists("$(1).h")) def file_ext_o(c): """compile '*.c' and '*.h'""" system(c%"$(cc) $(cflags) -c $(1).c") def task_clean(c): rm_f("*.o") -- Exampe of result: == sh> ls Kookbook.py hello.chello.h sh> pykook -l Properties: cc : 'gcc' cflags : '-g -Wall' Task recipes: all : cook all products clean : remove by-products File recipes: hello : generates hello command *.o : compile '*.c' and '*.h' (Tips: you can set 'kook_default_product' variable in your kookbook.) sh> pykook all # or, pykook --cc=gcc4 all ### *** hello.o (func=file_ext_o) $ gcc -g -Wall -c hello.c ### ** hello (func=file_command) $ gcc -g -Wall -o hello hello.o ### * all (func=task_all) == See users-guide for more details. http://www.kuwata-lab.com/kook/pykook-users-guide.html Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyTenjin 0.7.0 - the fastest and full-featured template engine
Hi, I have released pyTenjin 0.7.0 http://www.kuwata-lab.com/tenjin/ pyTenjin is the fastest template engine for Python. It is not only very fast but also full-featured and easy-to-use. You can embed Python statements and expressions into your text file. Tenjin converts it into Python program and evaluate it. Features: * very fast - x2 faster than Mako - x3 faster than Cheetah and Myghty - x9 faster than Django - x60 faster than Kid * Full-featured - layout template - partial template - capturing - preprocessing - and so on... You can see the detail of benchmark at: http://www.kuwata-lab.com/tenjin/ (benchmark script is included in pyTenjin distribution.) Enhancements in 0.7.0 - * Python 3.0 is now supported officially. * Google AppEngine (GAE) supported. http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-google-appengine * Logging support. * enerate_tostrfun() can take not only encode-encoding but also decode-encoding. * (Experimental) HTML helper functions are now provided. * New command-line option '-a cache' supported. * You can share caches between all engine objects. * Pickle-base and text-base template caching support. See CHANGES.txt for details. http://www.kuwata-lab.com/pytenjin-CHANGES.txt Changes in 0.7.0 * 'cache' option for tenjin.Engine() changed. * to_str() is changed to encode unicode object into binary(=str) using utf-8 encoding in default. * Benchmark script now skips to do benchmark template libraries which are failed to import. Bugfix in 0.7.0 * In preprocessing, error was raised when expression is not string. Now fixed. Download and Install Type: $ sudo eazy_install Tenjin Or: $ wget http://downloads.sourceforge.net/tenjin/Tenjin-0.7.0.tar.gz $ tar xzf Tenjin-0.7.0.tar.gz $ cd Tenjin-0.7.0 $ sudo python setup.py install Documents - * User's Guide http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html * FAQ http://www.kuwata-lab.com/tenjin/pytenjin-faq.html * Examples http://www.kuwata-lab.com/tenjin/pytenjin-examples.html * (Presentation) Tenjin - the fastest template engine in the world http://www.slideshare.net/kwatch/tenjin-the-wastest-template-engine-in-the-world Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
[Q] raise exception with fake filename and linenumber
Hi all, Is it possible to raise exception with custom traceback to specify file and line? Situation = I'm creating a certain parser. I want to report syntax error with the same format as other exception. Example === parser.py: - 1: def parse(filename): 2: if something_is_wrong(): 3: linenum = 123 4: raise Exception("syntax error on %s, line %s" % (filename, linenum)) 5: 6: parse('example.file') - current result: - Traceback (most recent call last): File "/tmp/parser.py", line 6, in parse('example.file') File "/tmp/parser.py", line 4, in parse raise Exception("syntax error on %s, line %s" % (filename, linenum)) Exception: syntax error on example.file, line 123 - my hope is: - Traceback (most recent call last): File "/tmp/parser.py", line 6, in parse('example.file') File "/tmp/parser.py", line 4, in parse raise Exception("syntax error on %s, line %s" % (filename, linenum)) File "/tmp/example.file", line 123 foreach item in items # wrong syntax line Exception: syntax error - I guess I must create dummy traceback data, but I don't know how to do it. Could you give me an advice? Thank you. -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
Re: raise exception with fake filename and linenumber
On 4月8日, 午後12:52, "Gabriel Genellina" wrote: > > The built-in SyntaxError exception does what you want. Constructor > parameters are undocumented, but they're as follows: > > raise SyntaxError("A descriptive error message", (filename, linenum, > colnum, source_line)) > > colnum is used to place the ^ symbol (10 in this fake example). Output: > > Traceback (most recent call last): > File "1.py", line 9, in > foo() > File "1.py", line 7, in foo > raise SyntaxError("A descriptive error message", (filename, linenum, > colnum, "this is line 123 in example.file")) > File "example.file", line 123 > this is line 123 in example.file > ^ > SyntaxError: A descriptive error message > > -- > Gabriel Genellina Thank you Gabriel, this is great help for me. By the way, is it hard to specify any other exception class instead of SyntaxError? The SyntaxError class is a good solution in my case, but if possible, I want to know more general solution to specify filename and linenum for exception. -- makoto -- http://mail.python.org/mailman/listinfo/python-list
ANN: Oktest 0.2.1 released - a new style testing library.
Hi, I released Oktest 0.2.1. homepage: http://packages.python.org/Oktest/ download: http://pypi.python.org/pypi/Oktest/ repository: http://bitbucket.org/kwatch/oktest/ Oktest is a new-style testing library for Python. from oktest import ok ok (x) > 0 # same as assert_(x > 0) ok (s) == 'foo'# same as assertEqual(s, 'foo') ok (s) != 'foo'# same as assertNotEqual(s, 'foo') ok (f).raises(ValueError) # same as assertRaises(ValueError, f) ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', ode)) not_ok (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', ) ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt')) not_ok ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt')) You can use ok() instead of 'assertXxx()' in unittest. Oktest requires Python 2.3 or later. Oktest is ready for Python 3. NOTICE!! Oktest is a young project and specification may change in the future. See http://packages.python.org/Oktest/ for details. -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Benchmarker 1.0.0 - a samll utility for benchmarking
Hi, I released Benchmarker 1.0.0. http://pypi.python.org/pypi/Benchmarker/ Benchmarker is a small library for benchmarking. Example --- ex.py:: def fib(n): return n <= 2 and 1 or fib(n-1) + fib(n-2) from benchmarker import Benchmarker bm = Benchmarker() # or Benchmarker(width=30, out=sys.stderr, header=True) ## Python 2.5 or later with bm('fib(n) (n==34)'): fib(34) with bm('fib(n) (n==35)'): fib(35) ## Python 2.4 bm('fib(n) (n==34)').run(lambda: fib(34)) bm('fib(n) (n==35)').run(lambda: fib(35)) Output:: $ python ex.py utime stime total real fib(n) (n==34)4.3700 0.0200 4.3900 4.9449 fib(n) (n==35)7.1500 0.0500 7.2000 8.0643 Download http://pypi.python.org/pypi/Benchmarker/ Installation:: ## if you have installed easy_install: $ sudo easy_install Benchmarker ## or download Benchmarker-1.0.0.tar.gz and install it $ wget http://pypi.python.org/packages/source/B/Benchmarker/Benchmarker-1.0.0.tar.gz $ tar xzf Benchmarker-1.0.0.tar.gz $ cd Benchmarker-1.0.0/ $ sudo python setup.py install License --- Public Domain Copyright - copyright(c) 2010 kuwata-lab.com all rights reserved -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Oktest 0.3.0 released - a new style testing library
Hi, I released Oktest 0.3.0. http://packages.python.org/Oktest/ http://pypi.python.org/pypi/Oktest/ Overview Oktest is a new-style testing library for Python. :: from oktest import ok ok (x) > 0 # same as assert_(x > 0) ok (s) == 'foo'# same as assertEqual(s, 'foo') ok (s) != 'foo'# same as assertNotEqual(s, 'foo') ok (f).raises(ValueError) # same as assertRaises(ValueError, f) ok (u'foo').is_a(unicode) # same as assert_(isinstance(u'foo', unicode)) not_ok (u'foo').is_a(int) # same as assert_(not isinstance(u'foo', int)) ok ('A.txt').is_file() # same as assert_(os.path.isfile('A.txt')) not_ok ('A.txt').is_dir() # same as assert_(not os.path.isdir('A.txt')) You can use ok() instead of 'assertXxx()' in unittest. Oktest requires Python 2.3 or later. Oktest is ready for Python 3. NOTICE!! Oktest is a young project and specification may change in the future. See http://packages.python.org/Oktest/ for details. Changes --- * enhanced 'ok (s1) == s2' to display unified diff (diff -u) * changed to call 'before()/after()' instead of 'before_each()/ after_each()' (currently 'before_each()/after_each()' is also enabled but they will be disabled in the future) * improved compatibility with unittest module * (internal) 'ValueObject' class is renamed to 'AssertionObject' * (internal) 'Reporter#before_each()' and '#after_each()' are renamed into '#before()' and '#after()' Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
Re: Benchmarker 1.1.0 released - a samll benchmark utility
Stefan, Thank you for trying Benchmarker library. On Jun 28, 6:39 pm, Stefan Behnel wrote: > Makoto Kuwata, 26.06.2010 19:09: > > > I released Benchmarker 1.1.0. > >http://pypi.python.org/pypi/Benchmarker/ > > > Benchmarker is a small utility to benchmark your code. > > Does it use any statistically sound way to run the benchmarks? It seems to > produce just one number on output, which can be misleading depending on the > way it measures. > > Stefan Could you explain about "statistically sound way to run the benchmarks"? -- regards, makoto -- http://mail.python.org/mailman/listinfo/python-list
ANN: pyTenjin 0.8.0 - much faster template engine than Django
I have released pyTenjin 0.8.0 http://www.kuwata-lab.com/tenjin/ pyTenjin is the fastest template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (layout template, partial template, preprocessing, ...) * Very small (only 1,200 lines, one file) * Goole AppEngine supported. http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-google-appengine Changes from 0.7.0 -- * !!IMPORTANT!! HTML helper function 'tagattr()' is renamed to 'tagattrs()'. (Notice that new 'tagattr()' is added. See below.) * 'tagattrs()' is changed to add ' ' (space) at the first character. ex. (0.7.0) tagattr(klass='error') #=> 'class="error"' (0.7.1) tagattrs(klass='error')#=> ' class="error"' * 'tagattrs()' is changed to handle 'checked', 'selected', and 'disabled' attributes. ex. >>> from tenjin.helpers.html import * >>> tagattrs(checked=True, selected='Y', disabled=1) ' checked="checked" selected="selected" disabled="disabled"' >>> tagattrs(checked=False, selected='', disabled=0) '' Bugfix -- * !!IMPORTANT!! Template caching is changed to keep template file's timestamp instead of create time of cached object. See http://groups.google.com/group/kuwata-lab-products/browse_thread/thread/a0d447c282fb383d#msg_de39557405c9b656 for details. (Thanks Steve) Enhancements * Add new HTML helper function 'tagattr()'. (Notice that 'tagattr()' in 0.7.0 is renamed into 'tagattrs()'.) ex. >>> from tenjin.helpers.html import * >>> tagattr('size', 20) ' size="20"' >>> tagattr('size', 0) '' >>> tagattr('size', 20, 'large') ' size="large"' >>> size = 20# you can use tagattrs() instead of tagattr () >>> tagattrs(size=(size and 'large')) ' size="large"' * Add new HTML helper function 'new_cycle()'. ex. >>> from tenjin.helpers.html import * >>> cycle = new_cycle('odd, 'even') >>> cycle() 'odd' >>> cycle() 'even' >>> cycle() 'odd' >>> cycle() 'even' * (experimental) Template converter is changed to add dummy if- statement when first Python statement is indented. (Thanks Steve) ex. $ cat ex.pyhtml ${item} $ pytenjin -sb ex.pyhtml _buf.extend((''' \n''', )); if True: ## dummy for item in items: _buf.extend((''' ''', escape(to_str(item)), '''\n''', )); #end _buf.extend((''' \n''', )); * Update User's Guide and FAQ. Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
ANN: pyTenjin 0.8.1 - much faster template engine than Django
I released pyTenjin 0.8.1. http://www.kuwata-lab.com/tenjin/ http://pypi.python.org/pypi/Tenjin/ pyTenjin is the fastest template engine for Python. * Very fast (about 10 times faster than Django template engine) * Easy to learn (no need to learn template-original language) * Full-featured (layout template, partial template, preprocessing, ...) * Very small (only 1,200 lines, one file) This is a bug fix release. See CHANGES for details. http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Bugfix from 0.8.1 - * Fix bugs on CacheStorage#unset(). (thanks Steve) * Fix tenjin.helpers.html.new_cycle() to work on Python 3.0. Changes from 0.8.1 -- * Update 'doc/faq.html' and add new section. 'Is it possible to change indent restriction more flexible?' http://www.kuwata-lab.com/tenjin/pytenjin-faq.html#faq-flexibleindent Documents - * User's Guide http://www.kuwata-lab.com/tenjin/pytenjin-users-guide.html * FAQ http://www.kuwata-lab.com/tenjin/pytenjin-faq.html * CHANGES http://www.kuwata-lab.com/tenjin/pytenjin-CHANGES.txt Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyKook 0.0.2 - a simple build tool similar to Make or Ant
Hi, I have released pyKook 0.0.2. http://pypi.python.org/pypi/Kook/0.0.2 http://www.kuwata-lab.com/kook/ http://www.kuwata-lab.com/kook/pykook-users-guide.html Overview pyKook is a simple build tool similar to Make, Ant, Rake, or SCons. pyKook regards software project as cooking. Terms used in pyKook are cooking terms. For example: cookbook- Makefile product - target file ingredient - source file recipe - how to create target from source spices - command-line options for recipe Cookbook (= Makefile) is written in pure Python. You can write any statements or expressions in cookbook. NOTICE: pyKook is under alpha release. Spec and features may be changed in the future without previous announcement. Example --- Example of cookbook (Kookbook.py): -- ## ## properties ## cc = prop('cc', 'gcc') cflags = prop('cflags', '-g -Wall') ## ## recipes ## @ingreds("hello") def task_all(c): pass @product("hello") @ingreds("hello.o") def file_command(c): """generates hello command""" system(c%"$(cc) $(cflags) -o $(product) $(ingred)") @product("*.o") @ingreds("$(1).c", if_exists("$(1).h")) def file_ext_o(c): """compile '*.c' and '*.h'""" system(c%"$(cc) $(cflags) -c $(1).c") def task_clean(c): rm_f("*.o") -- Exampe of result: == bash> ls Kookbook.py hello.chello.h bash> pykook -l Properties: cc : 'gcc' cflags : '-g -Wall' Task recipes: all : cook all products clean : remove by-products File recipes: hello : generates hello command *.o : compile '*.c' and '*.h' (Tips: you can set 'kook_default_product' variable in your kookbook.) bash> pykook all # or, pykook --cc=gcc4 all ### *** hello.o (func=file_ext_o) $ gcc -g -Wall -c hello.c ### ** hello (func=file_command) $ gcc -g -Wall -o hello hello.o ### * all (func=task_all) == See users-guide for more details. http://www.kuwata-lab.com/kook/pykook-users-guide.html Enhancements, Changes, Bug fixes sice 0.0.1 --- Enhancements: - Python 3 support. - Add 'kk' script which is shortcat for kk command. Changes: - Decorator '@cmdopts()' is renamed to '@spices()', and there is no need to call parse_cmdopts(). ### prev version @cmdopts('-v: verbose', '-f file: filename') def task_example(c, *args): opts, rests = c.parse_cmdopts(args) verbose = opts.get('v', False): fileame = opts.get('f', None) ### since this release (0.0.2) @spices('-v: verbose', '-f file: filename') def task_example(c, *args, *kwargs): opts, rests = kwarts, args verbose = opts.get('v', False): fileame = opts.get('f', None) - Remove 'pyk' script - Testing library is changed from Python's unittest library into 'test/oktest.py'. Bugfixes: - glob2() now recognizes files on current directory. Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyKook 0.0.3 - a smart build tool similar to Make, Rake, or Ant
Hi, I have released pyKook 0.0.3. http://pypi.python.org/pypi/Kook/0.0.3 http://www.kuwata-lab.com/kook/ http://www.kuwata-lab.com/kook/pykook-users-guide.html In this release, recipe syntax is changed (see below). Overview pyKook is a smart build tool similar to Make, Rake, Ant, or Cook. pyKook regards software project as cooking. Terms used in pyKook are cooking terms. For example: cookbook- Makefile product - target file ingredient - source file recipe - how to create target from source spices - command-line options for recipe Cookbook (= Makefile) is written in pure Python. You can write any statements or expressions in cookbook. NOTICE: pyKook is under alpha release. Spec and features may be changed in the future without previous announcement. Example === Example of cookbook (Kookbook.py): -- ## ## properties ## cc = prop('cc', 'gcc') cflags = prop('cflags', '-g -Wall') ## ## recipes ## @recipe @ingreds("hello") def all(c):# or task_all(c) pass @recipe @product("hello") @ingreds("hello.o") def file_command(c): """generates hello command""" system(c%"$(cc) $(cflags) -o $(product) $(ingred)") @recipe @product("*.o") @ingreds("$(1).c", if_exists("$(1).h")) def file_ext_o(c): """compile '*.c' and '*.h'""" system(c%"$(cc) $(cflags) -c $(1).c") @recipe def clean(c): rm_f("*.o") -- Exampe of result: -- bash> ls Kookbook.py hello.chello.h bash> pykook -l Properties: cc : 'gcc' cflags : '-g -Wall' Task recipes: all : cook all products clean : remove by-products File recipes: hello : generates hello command *.o : compile '*.c' and '*.h' (Tips: you can set 'kook_default_product' variable in your kookbook.) bash> pykook all # or, pykook --cc=gcc4 all ### *** hello.o (func=file_ext_o) $ gcc -g -Wall -c hello.c ### ** hello (func=file_command) $ gcc -g -Wall -o hello hello.o ### * all (func=task_all) -- See users-guide for more details. http://www.kuwata-lab.com/kook/pykook-users-guide.html Enhancements, Changes, Bug fixes sice 0.0.2 === Changes --- - IMPORTANT!! New '@recipe' decorator is required for each recipe function. If function is decorated by '@recipe', 'task_' prefix is not necessary. ex: ## previous version def task_clean(c):# 'task_' prefix is required rm_rf("*.o") ## since this release @release # @release decorator is required def clean(c): # 'task_' prefix is not necessary rm_rf("*.o") See http://www.kuwata-lab.com/kook/pykook-users-guide.html#cookbook-recipekind for details. - Library codes are much refactored. Enhancements - IMPORTANT!! New feature to support command-line script framework. You can convert Kookbook.py into command-line script. See http://www.kuwata-lab.com/kook/pykook-users-guide.html#topic-framework for details. - New command-line option '-n' (no exec) supported. If you specify '-n', commands such as 'cp()' or 'rm()' are not executed. In other words, '-n' means 'dry-run'. - Add a lot of test scripts. Bug fixes - - A bug related timestamp detection is now fixed. There was a case that product file was not updated even when ingredient files were updated. - A bug about recipe tree is fixed. There was a case that the same recipe can be invoke more than once when an intermediate recipe was required from several recipes. Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
[ANN] pyKook 0.0.4 - a smart build tool similar to Make, Rake, or Ant
Hi, I have released pyKook 0.0.4. http://pypi.python.org/pypi/Kook/0.0.4 http://www.kuwata-lab.com/kook/ http://www.kuwata-lab.com/kook/pykook-users-guide.html In this release, recipe syntax is changed (see below). Overview pyKook is a smart build tool similar to Make, Rake, Ant, or Cook. pyKook regards software project as cooking. Terms used in pyKook are cooking terms. For example: cookbook- Makefile product - target file ingredient - source file recipe - how to create target from source spices - command-line options for recipe Cookbook (= Makefile) is written in pure Python. You can write any statements or expressions in cookbook. NOTICE: pyKook is under alpha release. Spec and features may be changed in the future without previous announcement. Example === Example of cookbook (Kookbook.py): -- ## ## properties ## cc = prop('cc', 'gcc') cflags = prop('cflags', '-g -Wall') ## ## recipes ## @recipe @ingreds("hello") def all(c):# or task_all(c) pass @recipe @product("hello") @ingreds("hello.o") def file_command(c): """generates hello command""" system(c%"$(cc) $(cflags) -o $(product) $(ingred)") @recipe @product("*.o") @ingreds("$(1).c", if_exists("$(1).h")) def file_ext_o(c): """compile '*.c' and '*.h'""" system(c%"$(cc) $(cflags) -c $(1).c") @recipe def clean(c): rm_f("*.o") -- Exampe of result: -- bash> ls Kookbook.py hello.chello.h bash> pykook -l Properties: cc : 'gcc' cflags : '-g -Wall' Task recipes: all : cook all products clean : remove by-products File recipes: hello : generates hello command *.o : compile '*.c' and '*.h' (Tips: you can set 'kook_default_product' variable in your kookbook.) bash> pykook all # or, pykook --cc=gcc4 all ### *** hello.o (func=file_ext_o) $ gcc -g -Wall -c hello.c ### ** hello (func=file_command) $ gcc -g -Wall -o hello hello.o ### * all (func=task_all) -- See users-guide for more details. http://www.kuwata-lab.com/kook/pykook-users-guide.html Enhancements sice 0.0.3 === - Compact style of @recipe decorator supported. ex:: ## normal style @recipe @product('*.o') @ingreds('$(1).c', '$(1).h') def file_o(c): system(c%"gcc -c $(ingre)") ## compact style @recipe('*.o', ['$(1).c', '$(1).h']) def file_o(c): system(c%"gcc -c $(ingre)") - 'kk' script supports '$KK_CLIMB' environment variable. If you set it, 'kk' script searches parent directories when 'Kookbook.py' is not found. ex:: sh> ls -F Kookbook.pysrc/test/ sh> cd src/foo/bar/ sh> kk clean# ERROR kk: No kookbook found. sh> export KK_CLIMB=1 sh> kk clean# OK ### * clean (recipe=clean) $ rm **/*.pyc - New command-line option '-R' (recursively) supported. If you specify '-R', pykook command searches Kookbook.py in parent directory recursively. ex:: sh> ls -F Kookbook.pysrc/test/ sh> cd src/foo/bar/ sh> pykook clean# ERROR pykook: Kookbook.py: not found. sh> pykook -R clean # OK ### * clean (recipe=clean) $ rm **/*.pyc Have fun! -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
[ANN] Benchmarker 2.0.0 released - a samll benchmark utility
I released Benchmarker 2.0.0. http://pypi.python.org/pypi/Benchmarker/ Benchmarker is a small utility to benchmark your code. Download http://pypi.python.org/pypi/Benchmarker/ Installation:: ## if you have installed easy_install: $ sudo easy_install Benchmarker ## or download Benchmarker-X.X.X.tar.gz and install it $ wget http://pypi.python.org/packages/source/B/Benchmarker/Benchmarker-X.X.X.tar.gz $ tar xzf Benchmarker-X.X.X.tar.gz $ cd Benchmarker-X.X.X/ $ sudo python setup.py install Example for Busy People --- ex0.py:: from __future__ import with_statement from benchmarker import Benchmarker s1, s2, s3, s4, s5 = "Haruhi", "Mikuru", "Yuki", "Itsuki", "Kyon" with Benchmarker(loop=1000*1000) as bm: for i in bm.empty():## empty loop pass for i in bm('"".join((s,s,s))'): sos = "".join((s1, s2, s3, s4, s5)) for i in bm('s+s+s'): sos = s1 + s2 + s3 + s4 + s5 for i in bm('"%s%s%s" % (s,s,s)'): sos = "%s%s%s%s%s" % (s1, s2, s3, s4, s5) Output:: $ python ex0.py ## benchmarker: release 0.0.0 (for python) ## python platform: darwin [GCC 4.2.1 (Apple Inc. build 5659)] ## python version:2.5.5 ## python executable: /usr/local/python/2.5.5/bin/python ## Benchmarkuser sys total real (Empty) 0.12000.03000.1500 0.1605 "".join((s,s,s)) 0.7300 -0.03000.7000 0.6992 s+s+s 0.6600 -0.02000.6400 0.6321 "%s%s%s" % (s,s,s)0.8700 -0.03000.8400 0.8305 ## Ranking real ratio chart s+s+s 0.6321 (100.0) "".join((s,s,s)) 0.6992 ( 90.4) ** "%s%s%s" % (s,s,s)0.8305 ( 76.1) *** ## Ratio Matrix real[01][02][03] [01] s+s+s0.6321 100.0 110.6 131.4 [02] "".join((s,s,s)) 0.699290.4 100.0 118.8 [03] "%s%s%s" % (s,s,s) 0.830576.184.2 100.0 See http://pypi.python.org/pypi/Benchmarker/ for more details. Changes from 1.1.0 -- * Rewrited entirely. * Enhance to support empty loop. Result of empty loop is subtracted automatically automatically from other benchmark result. :: bm = Benchmarker() with bm.empty(): for i in xrange(1000*1000): pass with bm('my benchmark 1'): #... do something ... * Enhance to support for-statement. :: bm = Benchmarker(loop=1000*1000) for i in bm('example'): #... do something ... ## the above is same as: bm = Benchmarker() with bm('example'): for i in xrange(1000*1000): #... do something ... * Enhance to support new feature to repeat benchmarks. :: bm = Benchmarker() for b in bm.repeat(5): # repeat benchmark 5 times with b('example1'): #... do something ... with b('example2'): #... do something ... * 'compared_matrix()' is replaced by 'stat.all()'. 'stat.all()' shows benchmark ranking and ratio matrix. :: bm = Benchmarker() with bm('example'): # print(bm.stat.all()) # ranking and ratio matrix * Enhance to support 'Benchmark.platform()' which gives you platform information. :: print bm.platform() output example ## benchmarker: release 2.0.0 (for python) ## python platform: darwin [GCC 4.2.1 (Apple Inc. build 5659)] ## python version:2.5.5 ## python executable: /usr/local/python/2.5.5/bin/python2.5 * 'with-statement' for benchmarker object prints platform info and statistics automatically. :: with Benchmarker() as bm: wtih bm('fib(30)'): fib(30) the above is same as: # bm = Benchmarker() # print(bm.platform()) # with bm('fib(30)'): # fib(30) # print(bm.stat.all()) * Enhance Benchmarker.run() to use function docment (__doc__) as benchmark label when label is not specified. :: def fib(n): """fibonacchi""" return n <= 2 and 1 or fib(n-1) + fib(n-2) bm = Benchmarker() bm.run(fib, 30)# same as bm("fibonacchi").run(fib, 30) * Default format of times is changed from '%9.3f' to '%9.4f'. -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list