Migrate build from distutils to setuptools
Distutils is deprecated with removal planned for Python 3.12.
This commit is contained in:
parent
b12cc4cf60
commit
fba5bfb584
41
setup.py
41
setup.py
@ -23,7 +23,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Gramps distutils module.
|
Gramps setuptools module.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
#check python version first
|
#check python version first
|
||||||
@ -32,11 +32,11 @@ import sys
|
|||||||
if sys.version_info < (3, 5):
|
if sys.version_info < (3, 5):
|
||||||
raise SystemExit("Gramps requires Python 3.5 or later.")
|
raise SystemExit("Gramps requires Python 3.5 or later.")
|
||||||
|
|
||||||
from distutils import log
|
from setuptools import setup, Command
|
||||||
from setuptools import setup
|
try:
|
||||||
from distutils.core import Command
|
from setuptools.command.build import build as _build
|
||||||
from distutils.util import convert_path, newer
|
except ImportError:
|
||||||
from distutils.command.build import build as _build
|
from distutils.command.build import build as _build
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
import codecs
|
import codecs
|
||||||
@ -45,7 +45,9 @@ from stat import ST_MODE
|
|||||||
from gramps.version import VERSION
|
from gramps.version import VERSION
|
||||||
import unittest
|
import unittest
|
||||||
import argparse
|
import argparse
|
||||||
|
import logging
|
||||||
|
|
||||||
|
_LOG = logging.getLogger(".setup")
|
||||||
|
|
||||||
svem_flag = '--single-version-externally-managed'
|
svem_flag = '--single-version-externally-managed'
|
||||||
if svem_flag in sys.argv:
|
if svem_flag in sys.argv:
|
||||||
@ -58,6 +60,17 @@ argparser.add_argument("--no-compress-manpages", dest="no_compress_manpages",
|
|||||||
args, passthrough = argparser.parse_known_args()
|
args, passthrough = argparser.parse_known_args()
|
||||||
sys.argv = [sys.argv[0]] + passthrough
|
sys.argv = [sys.argv[0]] + passthrough
|
||||||
|
|
||||||
|
def newer(source, target):
|
||||||
|
'''
|
||||||
|
Determines if a target file needs to be rebuilt.
|
||||||
|
|
||||||
|
Returns True if the target file doesn't exist or if the source file is
|
||||||
|
newer than the target file.
|
||||||
|
'''
|
||||||
|
if not os.path.exists(target):
|
||||||
|
return True
|
||||||
|
return os.path.getmtime(source) > os.path.getmtime(target)
|
||||||
|
|
||||||
def substitute_variables(filename_in, filename_out, subst_vars):
|
def substitute_variables(filename_in, filename_out, subst_vars):
|
||||||
'''
|
'''
|
||||||
Substitute variables in a file.
|
Substitute variables in a file.
|
||||||
@ -107,7 +120,7 @@ def build_trans(build_cmd):
|
|||||||
reply = input(ask)
|
reply = input(ask)
|
||||||
if reply in ['n', 'N']:
|
if reply in ['n', 'N']:
|
||||||
raise SystemExit(msg)
|
raise SystemExit(msg)
|
||||||
log.info('Compiling %s >> %s', po_file, mo_file)
|
_LOG.info('Compiling %s >> %s', po_file, mo_file)
|
||||||
|
|
||||||
#linux specific piece:
|
#linux specific piece:
|
||||||
target = 'share/locale/' + lang + '/LC_MESSAGES'
|
target = 'share/locale/' + lang + '/LC_MESSAGES'
|
||||||
@ -146,7 +159,7 @@ def build_man(build_cmd):
|
|||||||
with open(newfile, 'rb') as f_in,\
|
with open(newfile, 'rb') as f_in,\
|
||||||
gzip.open(man_file_gz, 'wb') as f_out:
|
gzip.open(man_file_gz, 'wb') as f_out:
|
||||||
f_out.writelines(f_in)
|
f_out.writelines(f_in)
|
||||||
log.info('Compiling %s >> %s', filename, man_file_gz)
|
_LOG.info('Compiling %s >> %s', filename, man_file_gz)
|
||||||
|
|
||||||
os.remove(newfile)
|
os.remove(newfile)
|
||||||
filename = False
|
filename = False
|
||||||
@ -163,18 +176,18 @@ def build_intl(build_cmd):
|
|||||||
data_files = build_cmd.distribution.data_files
|
data_files = build_cmd.distribution.data_files
|
||||||
base = build_cmd.build_base
|
base = build_cmd.build_base
|
||||||
|
|
||||||
merge_files = (('data/org.gramps_project.Gramps.desktop', 'share/applications', '--desktop'),
|
merge_files = (('org.gramps_project.Gramps.desktop', 'share/applications', '--desktop'),
|
||||||
('data/org.gramps_project.Gramps.xml', 'share/mime/packages', '--xml'),
|
('org.gramps_project.Gramps.xml', 'share/mime/packages', '--xml'),
|
||||||
('data/org.gramps_project.Gramps.appdata.xml', 'share/metainfo', '--xml'))
|
('org.gramps_project.Gramps.appdata.xml', 'share/metainfo', '--xml'))
|
||||||
|
|
||||||
for filename, target, option in merge_files:
|
for filename, target, option in merge_files:
|
||||||
filenamelocal = convert_path(filename)
|
filenamelocal = os.path.join('data', filename)
|
||||||
newfile = os.path.join(base, filenamelocal)
|
newfile = os.path.join(base, filenamelocal)
|
||||||
newdir = os.path.dirname(newfile)
|
newdir = os.path.dirname(newfile)
|
||||||
if not(os.path.isdir(newdir) or os.path.islink(newdir)):
|
if not(os.path.isdir(newdir) or os.path.islink(newdir)):
|
||||||
os.makedirs(newdir)
|
os.makedirs(newdir)
|
||||||
merge(filenamelocal + '.in', newfile, option)
|
merge(filenamelocal + '.in', newfile, option)
|
||||||
data_files.append((target, [base + '/' + filename]))
|
data_files.append((target, [base + '/data/' + filename]))
|
||||||
|
|
||||||
def merge(in_file, out_file, option, po_dir='po'):
|
def merge(in_file, out_file, option, po_dir='po'):
|
||||||
'''
|
'''
|
||||||
@ -186,7 +199,7 @@ def merge(in_file, out_file, option, po_dir='po'):
|
|||||||
msg = ('ERROR: %s was not merged into the translation files!\n' %
|
msg = ('ERROR: %s was not merged into the translation files!\n' %
|
||||||
out_file)
|
out_file)
|
||||||
raise SystemExit(msg)
|
raise SystemExit(msg)
|
||||||
log.info('Compiling %s >> %s', in_file, out_file)
|
_LOG.info('Compiling %s >> %s', in_file, out_file)
|
||||||
|
|
||||||
class build(_build):
|
class build(_build):
|
||||||
"""Custom build command."""
|
"""Custom build command."""
|
||||||
|
Loading…
Reference in New Issue
Block a user