Allow running calibre under both python2 and python3 from the same source checkout

This commit is contained in:
Kovid Goyal 2019-04-10 13:47:10 +05:30
parent 4e3c64d09f
commit 86ffa4f717
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 40 additions and 4 deletions

29
README.python3 Normal file
View File

@ -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

View File

@ -217,6 +217,10 @@ def init_env():
class Build(Command): class Build(Command):
short_description = 'Build calibre C/C++ extension modules' short_description = 'Build calibre C/C++ extension modules'
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_OUTPUTDIR = os.path.abspath(os.path.join(SRC, 'calibre', 'plugins'))
DEFAULT_BUILDDIR = os.path.abspath(os.path.join(os.path.dirname(SRC), 'build')) DEFAULT_BUILDDIR = os.path.abspath(os.path.join(os.path.dirname(SRC), 'build'))

View File

@ -198,7 +198,10 @@ class Plugins(collections.Mapping):
def load_plugin(self, name): def load_plugin(self, name):
if name in self._plugins: if name in self._plugins:
return 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: try:
del sys.modules[name] del sys.modules[name]
except KeyError: except KeyError:
@ -210,7 +213,7 @@ class Plugins(collections.Mapping):
p = None p = None
plugin_err = unicode_type(err) plugin_err = unicode_type(err)
self._plugins[name] = p, plugin_err self._plugins[name] = p, plugin_err
sys.path.remove(sys.extensions_location) sys.path.remove(plugins_loc)
def __iter__(self): def __iter__(self):
return iter(self.plugins) return iter(self.plugins)