Skip to content

Commit

Permalink
Python: Switch from distutils to setuptools
Browse files Browse the repository at this point in the history
for package creation.

In Python 3.10 and 3.11, distutils will be formally marked as deprecated.
See https://www.python.org/dev/peps/pep-0632/
Albeit setuptools uses distutils internally, this will continue to work
in the future, because setuptools includes its own version of distutils.
See https://setuptools.pypa.io/en/latest/deprecated/index.html
Tested on python 3.6+.

Note: Each distribution patches heavily setuptools and distutils, the
package maintainers should check correctness of the new builds.

Although python PEP 518 proposes a new format to specify the build system
for python packages (pyproject.toml), this is not fully implemented in
python3.6 and can't be used.

Fixes #392
  • Loading branch information
rcrdnalor committed Nov 8, 2021
1 parent ebbed97 commit ac9eb19
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 101 deletions.
7 changes: 1 addition & 6 deletions mythtv/bindings/python/Makefile
Expand Up @@ -24,12 +24,7 @@ python_build: setup.py
install: setup.py
$(PYTHON) setup.py install --skip-build $(ROOT_FLAGS) $(PREFIX_FLAGS)

ifdef INSTALL_ROOT
uninstall:
$(warning make -C bindings/python uninstall is not supported with $$(INSTALL_ROOT))
else
uninstall: setup.py
$(PYTHON) setup.py uninstall $(PREFIX_FLAGS)
endif
$(warning make -C bindings/python uninstall is not supported for python bindings)

.PHONY: all clean distclean install python_build uninstall
45 changes: 45 additions & 0 deletions mythtv/bindings/python/setup.cfg
@@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-

[metadata]
name = MythTV
version = 32.0.-1
description = MythTV Python bindings.
long_description = Provides canned database and protocol access to the MythTV database, mythproto, mythxml, services_api and frontend remote control.
url = https://mythtv.org


[options]
include_package_data = True

packages=
MythTV
MythTV/tmdb3
MythTV/ttvdb
MythTV/tvmaze
MythTV/ttvdbv4
MythTV/wikiscripts
MythTV/utility
MythTV/services_api

package_dir =
MythTV/tmdb3 = ./tmdb3/tmdb3
MythTV/tvmaze = ./tvmaze
MythTV/ttvdbv4 = ./ttvdbv4

scripts =
scripts/mythpython
scripts/mythwikiscripts

python_requires = >=3.6

install_requires =
MySQLdb > 1.3.0
lxml > 4.2.1


[options.package_data]
* = ttvdb/XSLT/*


[install]
single_version_externally_managed = 1
147 changes: 52 additions & 95 deletions mythtv/bindings/python/setup.py
@@ -1,95 +1,52 @@
##/usr/bin/env python

from __future__ import print_function
from distutils.core import setup
from distutils.cmd import Command
from distutils.sysconfig import get_python_lib, project_base
from distutils.command.install import INSTALL_SCHEMES
from distutils.command.build import build as pybuild

import os
import glob

SCRIPTS = ['scripts/mythpython', 'scripts/mythwikiscripts']

for scheme in INSTALL_SCHEMES.values():
scheme['data'] = scheme['purelib']

class uninstall(Command):
user_options=[('prefix=', None, 'installation prefix')]
def initialize_options(self):
self.prefix = None
def finalize_options(self):
pass
def run(self):
install_path = get_python_lib(prefix=self.prefix)
mythtv_path = os.path.join(install_path,'MythTV')
if os.access(mythtv_path, os.F_OK):
for path,dirs,files in os.walk(mythtv_path, topdown=False):
for fname in files:
fname = os.path.join(path,fname)
print('unlinking '+fname)
os.unlink(fname)
print('removing folder '+path)
os.rmdir(path)
for fname in os.listdir(install_path):
if fname.endswith('.egg-info') and fname.startswith('MythTV'):
fname = os.path.join(install_path, fname)
print('unlinking '+fname)
os.unlink(fname)
for fname in SCRIPTS:
fname = os.path.join(project_base, fname.split('/')[-1])
if os.access(fname, os.F_OK):
print('unlinking '+fname)
os.unlink(fname)

class build(pybuild):
user_options = pybuild.user_options + [('mythtv-prefix=', None, 'MythTV installation prefix')]
def initialize_options(self):
pybuild.initialize_options(self)
self.mythtv_prefix = None
def run(self):
pybuild.run(self)

# check for alternate prefix
if self.mythtv_prefix is None:
return

# find file
for path,dirs,files in os.walk('build'):
if 'static.py' in files:
break
else:
return

# read in and replace existing line
buff = []
path = os.path.join(path,'static.py')
with open(path) as fi:
for line in fi:
if 'INSTALL_PREFIX' in line:
line = "INSTALL_PREFIX = '%s'\n" % self.mythtv_prefix
buff.append(line)

# push back to file
with open(path,'w') as fo:
fo.write(''.join(buff))



setup(
name='MythTV',
version='32.0.-1',
description='MythTV Python bindings.',
long_description='Provides canned database and protocol access to the MythTV database, mythproto, mythxml, services_api and frontend remote control.',
packages=['MythTV', 'MythTV/tmdb3', 'MythTV/ttvdb', 'MythTV/tvmaze', 'MythTV/ttvdbv4',
'MythTV/wikiscripts', 'MythTV/utility',
'MythTV/services_api'],
package_dir={'MythTV/tmdb3':'./tmdb3/tmdb3', 'MythTV/tvmaze':'./tvmaze', 'MythTV/ttvdbv4':'./ttvdbv4'},
data_files=[('MythTV/ttvdb/XSLT', glob.glob('MythTV/ttvdb/XSLT/*'))],
url=['http://www.mythtv.org/'],
scripts=SCRIPTS,
requires=['MySQLdb','lxml'],
cmdclass={'uninstall':uninstall,
'build':build},
)
# -*- coding: utf-8 -*-

import sys, os
import setuptools

run_post_build_action = False
index = 0
mythtv_prefix = None

# handle extra build option for 'mythtv-prefix'
if sys.argv[1] == 'build':
for index,arg in enumerate(sys.argv):
if arg.startswith("--mythtv-prefix="):
run_post_build_action = True
try:
mythtv_prefix = arg.split("=")[1].strip()
except IndexError:
pass
break

# 'mythtv-prefix' argument is not meant for setup()
if run_post_build_action:
del sys.argv[index]

# run setup() from setuptools with expected arguments
setuptools.setup()

# adapt the path to the grabber scripts according installation
if run_post_build_action:
# check for alternate prefix
if mythtv_prefix is None or mythtv_prefix == '':
sys.exit(0)

# find file
for path,dirs,files in os.walk('build'):
if 'static.py' in files:
break
else:
sys.exit(0)

# read in and replace existing line
buff = []
path = os.path.join(path,'static.py')
with open(path) as fi:
for line in fi:
if 'INSTALL_PREFIX' in line:
line = "INSTALL_PREFIX = '%s'\n" % mythtv_prefix
buff.append(line)

# push back to file
with open(path,'w') as fo:
fo.write(''.join(buff))

0 comments on commit ac9eb19

Please sign in to comment.