How to patch via patch file # e.g. setup.py

I’m trying to get odoo 12 patched

there are required packages which are only optional

this works:

prePatch = ''
    substituteInPlace setup.py \
        --replace 'pyldap' '#pyldap'

    substituteInPlace requirements.txt \
        --replace 'pyldap' '#pyldap'
  '';

but I would like to created it via a patch file like
diff -u setup.py setup_.py > patch_setupPy

--- setup.py	2021-07-23 15:15:33.318385825 +0200
+++ setup.py	2021-07-23 15:15:33.318385825 +0200
@@ -40,7 +40,7 @@
         'psutil',  # windows binary code.google.com/p/psutil/downloads/list
         'psycopg2 >= 2.2',
         'pydot',
-        'pyldap',  # optional
+        #'pyldap',  # optional
         'pyparsing',
         'pypdf2',
         'pyserial',

and applied it in

in buildPythonApplication rec {
patches =  [ ./patch_setupPy ./patchReqTxt ];

but it results in

unpacking source archive /nix/store/w1fhrkqp43yr1l4r7d7387k73kc1690g-odoo_12.0.latest.tar.gz
source root is odoo-12.0.post20210722
setting SOURCE_DATE_EPOCH to timestamp 1626913714 of file odoo-12.0.post20210722/setup.cfg
patching sources
applying patch /nix/store/2iysksmw7xypyp7n6bc3mjgv3hjksya3-patch_setupPy
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- setup.py   2021-07-23 15:15:33.318385825 +0200
|+++ setup.py   2021-07-23 15:15:33.318385825 +0200
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
builder for '/nix/store/cyr8n7ss6ws28bbh85rdgsaif95dq4f0-odoo-12.0.drv' failed with exit code 1
cannot build derivation '/nix/store/32vh2kh68qccrrqysgabfx5ckw03fazr-python3-3.8.5-env.drv': 1 dependencies couldn't be built
error: build of '/nix/store/32vh2kh68qccrrqysgabfx5ckw03fazr-python3-3.8.5-env.drv' failed

This is the key part here. patch is by default called with -p1, which expects to strip a single directory component off of the two paths in these lines:

    --- setup.py   2021-07-23 15:15:33.318385825 +0200
    +++ setup.py   2021-07-23 15:15:33.318385825 +0200
        ^^^^^^^^

If you change the lines to a/setup.py and b/setup.py respectively, like in the diffs that git produces, it will work. The actual value of this first component is arbitrary though, it doesn’t have to be a and b. Often you’ll see somepkg-1.2.3-orig/... and somepkg-1.2.3/....

1 Like