From 8d61b9d079de1460d9e1e73f73174bea30fd324d Mon Sep 17 00:00:00 2001 From: Alexey Lebedeff Date: Fri, 30 Nov 2018 10:55:09 +0100 Subject: [PATCH 1/2] anki: 2.1.6-beta1 -> 2.1.6-beta2, fix python 3.7 With recent switch to python 3.7 this was no longer building. Upstream PR with the same patch: https://github.com/dae/anki/pull/266 --- pkgs/games/anki/default.nix | 5 +++-- pkgs/games/anki/python-3.7-compat.patch | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pkgs/games/anki/python-3.7-compat.patch diff --git a/pkgs/games/anki/default.nix b/pkgs/games/anki/default.nix index fb43640b2b12..c73afdd03934 100644 --- a/pkgs/games/anki/default.nix +++ b/pkgs/games/anki/default.nix @@ -25,7 +25,7 @@ }: buildPythonApplication rec { - version = "2.1.6-beta1"; + version = "2.1.6-beta2"; name = "anki-${version}"; src = fetchurl { @@ -35,7 +35,7 @@ buildPythonApplication rec { # "http://ankisrs.net/download/mirror/${name}.tgz" # "http://ankisrs.net/download/mirror/archive/${name}.tgz" ]; - sha256 = "0yqn8qjx9dyf754jljhyyrk8mahii188nz0yifl1lr3py9sxzbsf"; + sha256 = "0h71s1j1269x0b8481z8xf019caqglcjs32xlpzk72087ps169fa"; }; propagatedBuildInputs = [ pyqt5 sqlalchemy @@ -53,6 +53,7 @@ buildPythonApplication rec { patches = [ # Disable updated version check. ./no-version-check.patch + ./python-3.7-compat.patch ]; buildPhase = '' diff --git a/pkgs/games/anki/python-3.7-compat.patch b/pkgs/games/anki/python-3.7-compat.patch new file mode 100644 index 000000000000..8545b39d08cb --- /dev/null +++ b/pkgs/games/anki/python-3.7-compat.patch @@ -0,0 +1,23 @@ +commit 3d69aa9ce454a151ba75deafd7de117af2c7307d +Author: Alexey Lebedeff +Date: Fri Nov 30 10:44:39 2018 +0100 + + Fix searching for python 3.7 + + 3.7 introduced a change to `re.escape()`, which no longer escapes + `%`. By using `re.escape("%")` instead of a literal, we can detect + a proper form at runtime. + +diff --git a/anki/find.py b/anki/find.py +index 48d0dd1..213216d 100644 +--- a/anki/find.py ++++ b/anki/find.py +@@ -440,7 +440,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds + # nothing has that field + return + # gather nids +- regex = re.escape(val).replace("_", ".").replace("\\%", ".*") ++ regex = re.escape(val).replace("_", ".").replace(re.escape('%'), ".*") + nids = [] + for (id,mid,flds) in self.col.db.execute(""" + select id, mid, flds from notes From 19bffeee70043b7e9f8f7287b632078c05996d35 Mon Sep 17 00:00:00 2001 From: Alexey Lebedeff Date: Sat, 1 Dec 2018 11:05:28 +0100 Subject: [PATCH 2/2] anki: Use `fetchpatch` for python compatibilty patch --- pkgs/games/anki/default.nix | 12 +++++++++++- pkgs/games/anki/python-3.7-compat.patch | 23 ----------------------- 2 files changed, 11 insertions(+), 24 deletions(-) delete mode 100644 pkgs/games/anki/python-3.7-compat.patch diff --git a/pkgs/games/anki/default.nix b/pkgs/games/anki/default.nix index c73afdd03934..3f837886116c 100644 --- a/pkgs/games/anki/default.nix +++ b/pkgs/games/anki/default.nix @@ -4,6 +4,7 @@ , lib , python , fetchurl +, fetchpatch , lame , mplayer , libpulseaudio @@ -53,7 +54,16 @@ buildPythonApplication rec { patches = [ # Disable updated version check. ./no-version-check.patch - ./python-3.7-compat.patch + + # This is needed to fix python 3.7 compatibilty, where the + # behaviour of `re.escape()` was changed in a way that it no + # longer escapes `%`. This patch detects this difference at + # runtime and makes anki work with any python version. + # Upstream PR: https://github.com/dae/anki/pull/266 + (fetchpatch { + url = "https://github.com/dae/anki/commit/3d69aa9ce454a151ba75deafd7de117af2c7307d.patch"; + sha256 = "0kf9gajhy0wcajp24xfia71z6gn1mc4vl37svvq4sqbhj3gigd0h"; + }) ]; buildPhase = '' diff --git a/pkgs/games/anki/python-3.7-compat.patch b/pkgs/games/anki/python-3.7-compat.patch deleted file mode 100644 index 8545b39d08cb..000000000000 --- a/pkgs/games/anki/python-3.7-compat.patch +++ /dev/null @@ -1,23 +0,0 @@ -commit 3d69aa9ce454a151ba75deafd7de117af2c7307d -Author: Alexey Lebedeff -Date: Fri Nov 30 10:44:39 2018 +0100 - - Fix searching for python 3.7 - - 3.7 introduced a change to `re.escape()`, which no longer escapes - `%`. By using `re.escape("%")` instead of a literal, we can detect - a proper form at runtime. - -diff --git a/anki/find.py b/anki/find.py -index 48d0dd1..213216d 100644 ---- a/anki/find.py -+++ b/anki/find.py -@@ -440,7 +440,7 @@ select distinct(n.id) from cards c, notes n where c.nid=n.id and """+preds - # nothing has that field - return - # gather nids -- regex = re.escape(val).replace("_", ".").replace("\\%", ".*") -+ regex = re.escape(val).replace("_", ".").replace(re.escape('%'), ".*") - nids = [] - for (id,mid,flds) in self.col.db.execute(""" - select id, mid, flds from notes