-
Notifications
You must be signed in to change notification settings - Fork 91
Write with filter and some other things #21
Conversation
Pro: same code for cython and python Contra: manual compiling reqired pyx left for checks and references
Backport from main
Seems to be old implementation of pngfilters "undo"...
Useful e.g. for recompression
This can be useful for picture viewer or something like this.
And few bugs around
For speedup by cython
C-result of Cython included to allow compilation during install
This reverts commit 88c5b8f.
Speedup about 10% in unittests (python 2.7, compiled filters)
|
In principle this is great. But you've added another python file. I'd like to keep all of the code for "import png" in one file. See this comment on the original Cython pull request: #9 (comment) |
|
I think two files is better than two copies of same code. try:
import pyximport
pyximport.install()
import cpngfilters as pngfiltersCode inside png.py is just a fallback for case when import of cpngfilters.pyx is failed. And different code in pyx and fallback could lead to situation when some code would be changed in one, but not in other. After such thing "png.py" would be ok with cython, but crash without (or reverse). |
|
I think I made to fail to make myself clear: When using a plain Python installation (without Cython), I require that all the relevant code is in one file: png.py. I don't really care how or what you Cython users do, as long as it doesn't change that. |
|
Well, I can move code to png.py and write some script to save that into separate file before making ".c" file. I just don't feel difference between single file or two files after import one in another. |
|
I've been thinking about your requirement all these days... So pngfilters.py will produce ".c" code and class in png.py. Import try get binary version, if fails - pngfilters.py, if fails - we use except to use class. |
Make pngfilters work even when import of pngfilters.py failed.
|
Check super-safe pngfilters. And please, write your reason to this limitation for future developers. |
|
I'll have a look on Friday. |
|
Where would you want the reason documented? How about "It's intended that you can copy png.py into your application and distribute it" from the README ? |
|
Hm... may be after 'except' keyword... so when developer will see this trick he would know it's purpose. And... Is there any other reason? If not - ok, I'll write this remarks in comments before you pull. *But may be it's still worth to switch into package sometimes later. |
|
Explain what |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel ill. pull request rejected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decorators? You've just made this file FAIL TO COMPILE for Python 2.2 and Python 2.3. Not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and also missed error for except) because all this part was written as just proof-of-concept while I'm trying to understand you requirement about 'all code in one file' .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why you expect me to merge something that you admit is a proof-of-concept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not expect you merge this. I expect you estimate this. So I add code to pull-request as part of dialog.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duly noted.
|
I've now had a longer look. You've made
|
|
Get on the mailing list and start a discussion about what you're trying to achieve. |
|
"png.py must be the primary source for editing, " My English may be bad, but I still have no clue why. If I had this reason I wouldn't do this crazy tricks with super-safe import. |
|
One File Policy: a) one file is good for installation and embedding; This PR is not the place for a discussion of PyPNG's One File Policy. Any more discussion should be on a separate issue or on the mailing list. If you want to discuss how PyPNG should play nicely with people using Cython, get on the mailing list. Cython will never be an important audience, but I'm would like to discuss how to integrate with Cython users. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't do what you think. Although bytearray doesn't appear until Python 2.6, python 2.x (x<6) is quite happy to define a function with a reference to the global bytearray. So the body of the except: never gets run, even on Python 2.5 and below.
Better:
try:
bytearray
except:
def bytearray( blah blah blah )...
Even better: Don't write this sort of stuff until you've actually tested it on earlier Python versions.
Implementing filter types other than '0'.
This can be nice to achieve better compression.
Right now only one filter per file applied.
Also core of applying filter and undo filter switched to 'augmented' py to make python development easier and keeping cython speedup.
This is my first experience to contribute, sorry if something wrong.