Remove the resource-path file
Attempt to derive the resource path from the package path assuming that one of the three main installation schemes has been used. The package path will be one of the following: <prefix>/lib/pythonX.Y/site-packages <prefix>\Lib\site-packages <home>/lib/python <userbase>/lib/pythonX.Y/site-packages <userbase>\PythonXY\site-packages Where <prefix>, <home> and <userbase> are the resource paths used in the Prefix, Home and User installation schemes. The use of the command line option "--install-data" in the setup script is no longer supported. This change is intended to allow a Gramps core package to be created as a wheel and installed via pip.
This commit is contained in:
parent
8ffb544b2c
commit
3ca82e2ebc
@ -2,6 +2,7 @@
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2013 John Ralls <jralls@ceridwen.us>
|
||||
# Copyright (C) 2020 Nick Hall <nick-h@gramps-project.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -35,6 +36,25 @@ class ResourcePath:
|
||||
|
||||
It should be called only by const.py; other code should retrieve the
|
||||
paths from there.
|
||||
|
||||
Attempt to derive the resource path from the package path assuming that
|
||||
one of the three main installation schemes has been used.
|
||||
|
||||
The package path will be one of the following:
|
||||
|
||||
<prefix>/lib/pythonX.Y/site-packages
|
||||
<prefix>\Lib\site-packages
|
||||
|
||||
<home>/lib/python
|
||||
|
||||
<userbase>/lib/pythonX.Y/site-packages
|
||||
<userbase>\PythonXY\site-packages
|
||||
|
||||
Where <prefix>, <home> and <userbase> are the resource paths used in the
|
||||
Prefix, Home and User installation schemes.
|
||||
|
||||
The use of the command line option "--install-data" in the setup script
|
||||
is no longer supported.
|
||||
"""
|
||||
instance = None
|
||||
def __new__(cls):
|
||||
@ -47,9 +67,9 @@ class ResourcePath:
|
||||
def __init__(self):
|
||||
if self.initialized:
|
||||
return
|
||||
resource_file = os.path.join(os.path.abspath(os.path.dirname(
|
||||
__file__)), 'resource-path')
|
||||
installed = os.path.exists(resource_file)
|
||||
package_path = os.path.abspath(os.path.join(os.path.dirname(
|
||||
__file__), '..', "..", ".."))
|
||||
installed = not os.path.exists(os.path.join(package_path, '.git'))
|
||||
if installed:
|
||||
test_path = os.path.join("gramps", "authors.xml")
|
||||
else:
|
||||
@ -59,27 +79,30 @@ class ResourcePath:
|
||||
if (tmp_path and os.path.exists(os.path.join(tmp_path, test_path))):
|
||||
resource_path = tmp_path
|
||||
elif installed:
|
||||
try:
|
||||
with open(resource_file, encoding='utf-8',
|
||||
errors='strict') as fp:
|
||||
resource_path = fp.readline()
|
||||
except UnicodeError as err:
|
||||
LOG.exception("Encoding error while parsing resource path", err)
|
||||
sys.exit(1)
|
||||
except IOError as err:
|
||||
LOG.exception("Failed to open resource file", err)
|
||||
sys.exit(1)
|
||||
if not os.path.exists(os.path.join(resource_path, test_path)):
|
||||
LOG.error("Resource Path %s is invalid", resource_path)
|
||||
base_path = None
|
||||
head, tail = os.path.split(package_path)
|
||||
if tail in ('site-packages', 'dist-packages'):
|
||||
# Prefix or User installation scheme
|
||||
head, tail = os.path.split(head)
|
||||
if tail.startswith('python'):
|
||||
base_path, tail = os.path.split(head)
|
||||
elif tail == 'Lib' or tail.startswith('Python'):
|
||||
base_path = head
|
||||
elif tail == 'python':
|
||||
# Home installation scheme
|
||||
base_path, tail = os.path.split(head)
|
||||
if base_path is not None:
|
||||
resource_path = os.path.join(base_path, 'share')
|
||||
else:
|
||||
LOG.error("Unable to determine resource path")
|
||||
sys.exit(1)
|
||||
else:
|
||||
# Let's try to run from source without env['GRAMPS_RESOURCES']:
|
||||
resource_path = os.path.join(os.path.abspath(os.path.dirname(
|
||||
__file__)), '..', "..", "..")
|
||||
test_path = os.path.join("data", "authors.xml")
|
||||
if (not os.path.exists(os.path.join(resource_path, test_path))):
|
||||
LOG.error("Unable to determine resource path")
|
||||
sys.exit(1)
|
||||
resource_path = package_path
|
||||
|
||||
if (not os.path.exists(os.path.join(resource_path, test_path))):
|
||||
LOG.error("Resource Path %s is invalid", resource_path)
|
||||
sys.exit(1)
|
||||
|
||||
resource_path = os.path.abspath(resource_path)
|
||||
if installed:
|
||||
|
30
setup.py
30
setup.py
@ -36,7 +36,6 @@ from distutils import log
|
||||
from distutils.core import setup, Command
|
||||
from distutils.util import convert_path, newer
|
||||
from distutils.command.build import build as _build
|
||||
from distutils.command.install import install as _install
|
||||
import os
|
||||
import glob
|
||||
import codecs
|
||||
@ -60,19 +59,10 @@ if svem_flag in sys.argv:
|
||||
# Die, setuptools, die.
|
||||
sys.argv.remove(svem_flag)
|
||||
|
||||
# check if the resourcepath option is used and store the path
|
||||
# this is for packagers that build out of the source tree
|
||||
# other options to setup.py are passed through
|
||||
resource_path = ''
|
||||
packaging = False
|
||||
argparser = argparse.ArgumentParser(add_help=False)
|
||||
argparser.add_argument("--resourcepath", dest="resource_path")
|
||||
argparser.add_argument("--no-compress-manpages", dest="no_compress_manpages",
|
||||
action="store_true")
|
||||
args, passthrough = argparser.parse_known_args()
|
||||
if args.resource_path:
|
||||
resource_path = args.resource_path
|
||||
packaging = True
|
||||
sys.argv = [sys.argv[0]] + passthrough
|
||||
|
||||
def intltool_version():
|
||||
@ -273,22 +263,6 @@ class build(_build):
|
||||
build_intl(self)
|
||||
_build.run(self)
|
||||
|
||||
class install(_install):
|
||||
"""Custom install command."""
|
||||
def run(self):
|
||||
resource_file = os.path.join(os.path.dirname(__file__), 'gramps', 'gen',
|
||||
'utils', 'resource-path')
|
||||
with open(resource_file, 'w', encoding='utf-8', errors='strict') as fp:
|
||||
if packaging:
|
||||
path = resource_path
|
||||
else:
|
||||
path = os.path.abspath(os.path.join(self.install_data, 'share'))
|
||||
fp.write(path)
|
||||
|
||||
_install.run(self)
|
||||
|
||||
os.remove(resource_file)
|
||||
|
||||
class test(Command):
|
||||
"""Command to run Gramps unit tests"""
|
||||
description = "run all unit tests"
|
||||
@ -409,8 +383,6 @@ for (dirpath, dirnames, filenames) in os.walk(basedir):
|
||||
package_data_core.append(dirpath[7:] + '/' + dirname + '/*.xml')
|
||||
package_data_core.append(dirpath[7:] + '/' + dirname + '/*.ini')
|
||||
|
||||
package_data_core.append('gen/utils/resource-path')
|
||||
|
||||
package_data_gui = ['gui/glade/*.glade']
|
||||
package_data = package_data_core + package_data_gui
|
||||
|
||||
@ -488,7 +460,7 @@ setup(name = 'gramps',
|
||||
url = 'http://gramps-project.org',
|
||||
license = 'GPL v2 or greater',
|
||||
platforms = ['FreeBSD', 'Linux', 'MacOS', 'Windows'],
|
||||
cmdclass = {'build': build, 'install': install, 'test': test},
|
||||
cmdclass = {'build': build, 'test': test},
|
||||
packages = packages,
|
||||
package_data = {'gramps': package_data},
|
||||
data_files = data_files,
|
||||
|
Loading…
Reference in New Issue
Block a user