diff --git a/README.python3 b/README.python3 new file mode 100644 index 0000000000..6f34cd75e3 --- /dev/null +++ b/README.python3 @@ -0,0 +1,29 @@ +Efforts to port calibre to python 3 are ongoing. calibre can be run +using python3 under Linux. To do so, install python 3, checkout calibre +from source with + + git clone git@github.com:kovidgoyal/calibre.git && cd calibre + +Then, setup calibre to run under python2, with: + + python2 setup.py bootstrap + +Check that calibre works, with: + + python2 run-local calibre + +Now build the calibre C extensions for python 3 with: + + CALIBRE_PY3_PORT=1 python3 setup.py build + +You should now be able to run the calibre test suite using: + + python3 setup.py test + +And run calibre itself (which may not work) with: + + python3 run-local calibre + + +For the status of the port, and discussion of its design, see +https://github.com/kovidgoyal/calibre/pull/870 diff --git a/setup/build.py b/setup/build.py index 13c0e5c82c..41afd98173 100644 --- a/setup/build.py +++ b/setup/build.py @@ -217,8 +217,12 @@ def init_env(): class Build(Command): short_description = 'Build calibre C/C++ extension modules' - DEFAULT_OUTPUTDIR = os.path.abspath(os.path.join(SRC, 'calibre', 'plugins')) - DEFAULT_BUILDDIR = os.path.abspath(os.path.join(os.path.dirname(SRC), 'build')) + if ispy3: + DEFAULT_OUTPUTDIR = os.path.abspath(os.path.join(SRC, 'calibre', 'plugins', '3')) + DEFAULT_BUILDDIR = os.path.abspath(os.path.join(os.path.dirname(SRC), 'build', '3')) + else: + DEFAULT_OUTPUTDIR = os.path.abspath(os.path.join(SRC, 'calibre', 'plugins')) + DEFAULT_BUILDDIR = os.path.abspath(os.path.join(os.path.dirname(SRC), 'build')) description = textwrap.dedent('''\ calibre depends on several python extensions written in C/C++. diff --git a/src/calibre/constants.py b/src/calibre/constants.py index 80cbe9d223..78fb36860a 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -198,7 +198,10 @@ class Plugins(collections.Mapping): def load_plugin(self, name): if name in self._plugins: return - sys.path.insert(0, sys.extensions_location) + plugins_loc = sys.extensions_location + if ispy3: + plugins_loc = os.path.join(plugins_loc, '3') + sys.path.insert(0, plugins_loc) try: del sys.modules[name] except KeyError: @@ -210,7 +213,7 @@ class Plugins(collections.Mapping): p = None plugin_err = unicode_type(err) self._plugins[name] = p, plugin_err - sys.path.remove(sys.extensions_location) + sys.path.remove(plugins_loc) def __iter__(self): return iter(self.plugins)