mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make it easier to set calibre environment variables on macOS
This commit is contained in:
parent
dcc5757a24
commit
ff4316bc93
@ -121,12 +121,36 @@ def run_entry_point():
|
||||
return getattr(pmod, func)()
|
||||
|
||||
|
||||
def read_user_env_vars():
|
||||
try:
|
||||
with open(os.path.expanduser('~/Library/Preferences/calibre/macos-env.txt'), 'rb') as f:
|
||||
raw = f.read().decode('utf-8', 'replace')
|
||||
except EnvironmentError as err:
|
||||
return
|
||||
for line in raw.splitlines():
|
||||
if line.startswith('#'):
|
||||
continue
|
||||
parts = line.split('=', 1)
|
||||
if len(parts) == 2:
|
||||
key, val = parts
|
||||
os.environ[key] = os.path.expandvars(os.path.expanduser(val))
|
||||
|
||||
|
||||
def add_calibre_vars(base):
|
||||
sys.frameworks_dir = os.path.join(os.path.dirname(base), 'Frameworks')
|
||||
sys.resources_location = os.path.abspath(os.path.join(base, 'resources'))
|
||||
sys.extensions_location = os.path.join(sys.frameworks_dir, 'plugins')
|
||||
sys.binaries_path = os.path.join(os.path.dirname(base), 'MacOS')
|
||||
|
||||
try:
|
||||
read_user_env_vars()
|
||||
except Exception as err:
|
||||
try:
|
||||
sys.stderr.write('Failed to read user env vars with error: {}\n'.format(err))
|
||||
sys.stderr.flush()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
dv = os.environ.get('CALIBRE_DEVELOP_FROM', None)
|
||||
if dv and os.path.exists(dv):
|
||||
sys.path.insert(0, os.path.abspath(dv))
|
||||
|
@ -43,10 +43,16 @@ Environment variables
|
||||
* ``CALIBRE_USE_DARK_PALETTE`` - Set it to ``1`` to have calibre use dark colors and ``0`` for normal colors (ignored on macOS).
|
||||
On Windows 10 in the absence of this variable, the windows system preference for dark colors is used.
|
||||
* ``SYSFS_PATH`` - Use if sysfs is mounted somewhere other than /sys
|
||||
* ``http_proxy``, ``https_proxy`` - Used on linux to specify an HTTP(S) proxy
|
||||
* ``http_proxy``, ``https_proxy`` - Used on Linux to specify an HTTP(S) proxy
|
||||
|
||||
See `How to set environment variables in Windows <https://www.computerhope.com/issues/ch000549.htm>`_. If you are on macOS
|
||||
you can set environment variables by creating the :file:`~/Library/Preferences/calibre/macos-env.txt` and putting
|
||||
the environment variables one per line in it, for example::
|
||||
|
||||
CALIBRE_DEVELOP_FROM=$HOME/calibre-src/src
|
||||
CALIBRE_NO_NATIVE_FILEDIALOGS=1
|
||||
CALIBRE_CONFIG_DIRECTORY=~/.config/calibre
|
||||
|
||||
See `How to set environment variables in Windows <https://www.computerhope.com/issues/ch000549.htm>`_ or
|
||||
`How to set environment variables in macOS <https://www.dowdandassociates.com/blog/content/howto-set-an-environment-variable-in-mac-os-x-launchd-plist/>`_.
|
||||
|
||||
Tweaks
|
||||
------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user