patch: Switch to using Python code#1006
Conversation
|
Moving to Python sounds great to me. There were lots of annoyance to using |
|
@jakirkham https://github.com/techtonik/python-patch doesn't use any C++ and (as the PR states) is the upstream for this :-) It also has quite a comprehensive (if somewhat fiddly to add to) testsuite. But I agree that it needs testing and more testing, so please, go to town. |
|
@mingwandroid, we were using |
I see. I didn't look too closely. Maybe GitHub was just pointing out the sample code for patch tests. |
|
I don't remember anyone asking to use patch.exe. IIRC, I did so because the old one was failing miserably in my efforts to add python 3.5 and all its packages to Anaconda. |
|
I'm OK with this addition, but I would like some tests to accompany it. What I have in mind is a project with some dummy source code, and a patch that applies to that source code. We need to parse or examine the patched output to ensure that the patch applied cleanly. I guess we need patches both with p0 and p1 (without and with prefix, respectively), just for completeness? |
|
For the first one, can I copy a test from upstream? They have extensive tests for this sort of thing. The patch strip level detection code needs a new test for sure (actually it should be able to detect -p too). .. though actually I might make a single test that covers a few features (creation, deletion and patch level determination). .. but first, I need to figure out what's up with the CI on this. |
|
Copying is A-OK, but any testing here should cover our use of patch.py, not On Tue, Jun 7, 2016 at 9:39 AM Ray Donnelly notifications@github.com
|
`patch.exe` from gnuwin32 has fallen over on several of my bigger patches now and it's becoming a serious impediment. I don't want to add MSYS2's `patch.exe` since that requires a lot of infrastructure to work correctly (though I could build a native Windows `patch.exe` if necessary). However rather than relying on some arbitrary `patch` executable, it's better to use Python to do the work and avoid the subprocess overhead (though there will be a native-vs-python difference). Also add automatic patch skip level detection logic, which allows us to directly use patches generated using `git format-patch` and also those authored by external entities without needing to add metadata (although this may not be a bad idea). This part could be moved into patch.py at a later point perhaps? I've not added tests for this since upstream has a comprehensive testsuite (and I did add tests to check my changes to my PR). `patch.py` is also excluded from flake8 for now. Upstream: https://github.com/techtonik/python-patch Pull Req: techtonik/python-patch#41
GNU patch has fuzzing and offset capabilities: Hunk #1 succeeded at 167 with fuzz 2 (offset -1 lines). A good description of the gnu patch inexact matching method can be found at: http://www.gnu.org/software/diffutils/manual/html_node/Inexact.html .. python-patch.py doesn't implement this. This is a bit of a blocker for this change. Adjust the patch for now just to see what else falls out.
dab0fbf to
ee35d42
Compare
|
Is the Python patch only for Windows? Also, I would argue that if we move to a different patch program, we should only change the dependency, and package |
|
@ilanschnell python-patch is for all systems, it is pure python and it works on 2.7.x and 3.x. I've split this PR two bits, one that I hope will be merged soon (automatic detection of patch strip level): #1011, the other bit I don't plan to push for inclusion at present (see later). IMHO the patch executables in the wild are too variable. For example, gnuwin32's patch.exe crashes on completely valid patches. There are pros and cons to using Python implementations of the tools we depend on: not needing to use subprocess, consistency of operation, python's speed versus some-other-language's speed, maintainability, amount of code, and other things I've missed. Therefore, the decision of whether to import a python implementation of a given tool needs to be done on a case-by-case basis and I think a (working) python-patch would be a good thing (provided the code isn't too large, which in this case, I don't think it is). Using different patch implementations could generate different source code and that could result in horrible to track down bugs. The other major issue with gnu patch executables is that they are always interactive on patch failure which breaks CI systems. It's interesting you mention That being said, python-patch can't handle offsets or fuzzing, both of which are features we need, so for that reason I am closing this request, but I'd be interested in carrying on the conversation about whether continuing on this path (by implementing offsets and fuzzing) in future is worthwhile or not. |
|
Thanks for your response, Ray. I've never had any problems with |
|
That approach would also work for me, thanks Ilan. |
|
@mingwandroid, ok to close this? |
|
Closing since it's been a while. |
@msarahan, @jakirkham what do you think?
patch.exefrom gnuwin32 has fallen over on several of my biggerpatches now and it's becoming a serious impediment.
I don't want to add MSYS2's
patch.exesince that requires a lotof infrastructure to work correctly (though I could build a native
Windows
patch.exeif necessary).However rather than relying on some arbitrary
patchexecutable,it's better to use Python to do the work and avoid the subprocess
overhead (though there will be a native-vs-python difference).
Also add automatic patch skip level detection logic, which allows
us to directly use patches generated using
git format-patchandalso those authored by external entities without needing to add
metadata (although this may not be a bad idea). This part could be
moved into patch.py at a later point perhaps?
I've not added tests for this since upstream has a comprehensive
testsuite (and I did add tests to check my changes to my PR).
Upstream: https://github.com/techtonik/python-patch
Pull Req: techtonik/python-patch#41