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
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2013 John Ralls <jralls@ceridwen.us>
|
# 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
|
# 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
|
# 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
|
It should be called only by const.py; other code should retrieve the
|
||||||
paths from there.
|
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
|
instance = None
|
||||||
def __new__(cls):
|
def __new__(cls):
|
||||||
@ -47,9 +67,9 @@ class ResourcePath:
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
if self.initialized:
|
if self.initialized:
|
||||||
return
|
return
|
||||||
resource_file = os.path.join(os.path.abspath(os.path.dirname(
|
package_path = os.path.abspath(os.path.join(os.path.dirname(
|
||||||
__file__)), 'resource-path')
|
__file__), '..', "..", ".."))
|
||||||
installed = os.path.exists(resource_file)
|
installed = not os.path.exists(os.path.join(package_path, '.git'))
|
||||||
if installed:
|
if installed:
|
||||||
test_path = os.path.join("gramps", "authors.xml")
|
test_path = os.path.join("gramps", "authors.xml")
|
||||||
else:
|
else:
|
||||||
@ -59,27 +79,30 @@ class ResourcePath:
|
|||||||
if (tmp_path and os.path.exists(os.path.join(tmp_path, test_path))):
|
if (tmp_path and os.path.exists(os.path.join(tmp_path, test_path))):
|
||||||
resource_path = tmp_path
|
resource_path = tmp_path
|
||||||
elif installed:
|
elif installed:
|
||||||
try:
|
base_path = None
|
||||||
with open(resource_file, encoding='utf-8',
|
head, tail = os.path.split(package_path)
|
||||||
errors='strict') as fp:
|
if tail in ('site-packages', 'dist-packages'):
|
||||||
resource_path = fp.readline()
|
# Prefix or User installation scheme
|
||||||
except UnicodeError as err:
|
head, tail = os.path.split(head)
|
||||||
LOG.exception("Encoding error while parsing resource path", err)
|
if tail.startswith('python'):
|
||||||
sys.exit(1)
|
base_path, tail = os.path.split(head)
|
||||||
except IOError as err:
|
elif tail == 'Lib' or tail.startswith('Python'):
|
||||||
LOG.exception("Failed to open resource file", err)
|
base_path = head
|
||||||
sys.exit(1)
|
elif tail == 'python':
|
||||||
if not os.path.exists(os.path.join(resource_path, test_path)):
|
# Home installation scheme
|
||||||
LOG.error("Resource Path %s is invalid", resource_path)
|
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)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
# Let's try to run from source without env['GRAMPS_RESOURCES']:
|
# Let's try to run from source without env['GRAMPS_RESOURCES']:
|
||||||
resource_path = os.path.join(os.path.abspath(os.path.dirname(
|
resource_path = package_path
|
||||||
__file__)), '..', "..", "..")
|
|
||||||
test_path = os.path.join("data", "authors.xml")
|
if (not os.path.exists(os.path.join(resource_path, test_path))):
|
||||||
if (not os.path.exists(os.path.join(resource_path, test_path))):
|
LOG.error("Resource Path %s is invalid", resource_path)
|
||||||
LOG.error("Unable to determine resource path")
|
sys.exit(1)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
resource_path = os.path.abspath(resource_path)
|
resource_path = os.path.abspath(resource_path)
|
||||||
if installed:
|
if installed:
|
||||||
|
30
setup.py
30
setup.py
@ -36,7 +36,6 @@ from distutils import log
|
|||||||
from distutils.core import setup, Command
|
from distutils.core import setup, Command
|
||||||
from distutils.util import convert_path, newer
|
from distutils.util import convert_path, newer
|
||||||
from distutils.command.build import build as _build
|
from distutils.command.build import build as _build
|
||||||
from distutils.command.install import install as _install
|
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
import codecs
|
import codecs
|
||||||
@ -60,19 +59,10 @@ if svem_flag in sys.argv:
|
|||||||
# Die, setuptools, die.
|
# Die, setuptools, die.
|
||||||
sys.argv.remove(svem_flag)
|
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 = argparse.ArgumentParser(add_help=False)
|
||||||
argparser.add_argument("--resourcepath", dest="resource_path")
|
|
||||||
argparser.add_argument("--no-compress-manpages", dest="no_compress_manpages",
|
argparser.add_argument("--no-compress-manpages", dest="no_compress_manpages",
|
||||||
action="store_true")
|
action="store_true")
|
||||||
args, passthrough = argparser.parse_known_args()
|
args, passthrough = argparser.parse_known_args()
|
||||||
if args.resource_path:
|
|
||||||
resource_path = args.resource_path
|
|
||||||
packaging = True
|
|
||||||
sys.argv = [sys.argv[0]] + passthrough
|
sys.argv = [sys.argv[0]] + passthrough
|
||||||
|
|
||||||
def intltool_version():
|
def intltool_version():
|
||||||
@ -273,22 +263,6 @@ class build(_build):
|
|||||||
build_intl(self)
|
build_intl(self)
|
||||||
_build.run(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):
|
class test(Command):
|
||||||
"""Command to run Gramps unit tests"""
|
"""Command to run Gramps unit tests"""
|
||||||
description = "run all 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 + '/*.xml')
|
||||||
package_data_core.append(dirpath[7:] + '/' + dirname + '/*.ini')
|
package_data_core.append(dirpath[7:] + '/' + dirname + '/*.ini')
|
||||||
|
|
||||||
package_data_core.append('gen/utils/resource-path')
|
|
||||||
|
|
||||||
package_data_gui = ['gui/glade/*.glade']
|
package_data_gui = ['gui/glade/*.glade']
|
||||||
package_data = package_data_core + package_data_gui
|
package_data = package_data_core + package_data_gui
|
||||||
|
|
||||||
@ -488,7 +460,7 @@ setup(name = 'gramps',
|
|||||||
url = 'http://gramps-project.org',
|
url = 'http://gramps-project.org',
|
||||||
license = 'GPL v2 or greater',
|
license = 'GPL v2 or greater',
|
||||||
platforms = ['FreeBSD', 'Linux', 'MacOS', 'Windows'],
|
platforms = ['FreeBSD', 'Linux', 'MacOS', 'Windows'],
|
||||||
cmdclass = {'build': build, 'install': install, 'test': test},
|
cmdclass = {'build': build, 'test': test},
|
||||||
packages = packages,
|
packages = packages,
|
||||||
package_data = {'gramps': package_data},
|
package_data = {'gramps': package_data},
|
||||||
data_files = data_files,
|
data_files = data_files,
|
||||||
|
Loading…
Reference in New Issue
Block a user