Skip to content

Commit 013845e

Browse files
committed
Fix debian build with python 3.10 and deprecate distutils
Summary is that distutils has been deprecated for a while and will be removed in 3.12. setuptools is its replacement. However its use as an installation mechanism, e.g. *calling* setup.py install with CLI arguments is also being deprecated - with no good alternative (yet) being available. Since the whole world still depends on it I don't expect the latter to go away any time soon though, but it does seem to no longer care about fixing things for that frontend which is what now cause prefix arguments to not work as expected (installing things in /usr/local/ whilst specifying --prefix=/usr), which breaks the building of Debian packages. What Debian/Ubuntu seem to have done is patch setuptools to make it keep on behaving as they want, but only if you provide --install-layout=deb. So now providing that argument for all calls of "python setup.py install" in the Debian build. This would have also worked in combination with distutils, but taking this opportunity to upgrade to setuptools (since we'll have to soon anyway). These are changes by @Patol75, taken from FluidityProject/fluidity#351.
1 parent e2a52a3 commit 013845e

File tree

5 files changed

+80
-102
lines changed

5 files changed

+80
-102
lines changed

debian/rules

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,13 @@ install-prereq:
7070
dh_installdirs -a
7171

7272
install-python%:
73-
# Force setuptools, but reset sys.argv[0] to 'setup.py' because setup.py files expect that.
74-
cd diamond;python$* -c "import setuptools,sys;f='setup.py';sys.argv[0]=f;exec(open(f,'r').read(),{'__file__':f,'__name__':'__main__'})" install --prefix=/usr --no-compile --single-version-externally-managed --root=$(CURDIR)/debian/${PACKAGE_NAME}
75-
if [ -d debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}.egg-info ]; then \
76-
mv debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages ; \
77-
mv debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}.egg-info debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}.egg-info ; \
78-
elif [ -d debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}-py$*.egg-info ]; then \
79-
mv debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages ; \
80-
mv debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}-py$*.egg-info debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}.egg-info ; \
81-
else \
82-
echo "Failed to locate python egg, was it built correctly?" && exit 1 ; \
83-
fi
73+
cd diamond; python$* setup.py install --prefix=/usr --no-compile --single-version-externally-managed --root=$(CURDIR)/debian/${PACKAGE_NAME} --install-layout=deb
8474

8575
install-pyspud:
8676
$(MAKE) install-pyspud DESTDIR=$(CURDIR)/debian/python3-spud BUILDING_DEBIAN=yes
8777

8878
install-dxdiff:
89-
$(MAKE) install-dxdiff DESTDIR=$(CURDIR)/debian/python3-dxdiff
79+
$(MAKE) install-dxdiff DESTDIR=$(CURDIR)/debian/python3-dxdiff BUILDING_DEBIAN=yes
9080

9181
binary-arch: build-libspud install-libspud install-spudtools install-pyspud
9282
dh_testdir
@@ -135,5 +125,8 @@ binary-indep: build-spud-diamond install-spud-diamond build-libspud install-libs
135125

136126
binary: binary-indep binary-arch
137127

128+
build-arch: binary-arch
129+
build-indep: binary-indep
130+
138131

139132
.PHONY: build clean binary-indep binary-arch binary-spud-diamond binary-libspud install configure

diamond/setup.py.in

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
from distutils.core import setup
2-
from distutils.extension import Extension
3-
import os
4-
import os.path
5-
import glob
1+
from glob import glob
2+
from os import listdir
3+
from os.path import isdir, join
4+
from setuptools import setup
5+
from sys import argv, platform
66

77
# There are a number of local hacks in this file, to deal with the multiple
8-
# ways in which setup.py is called by various scripts and packaging methods
8+
# ways in which setup.py is called by various scripts and packaging methods
99
# that interact with spud, enabling setuptools to grok their intentions.
1010

1111
# In some cases, we will be passed a 'DESTDIR' from an upstream packagaing
1212
# system. This will be a local directory to install into, and act as local '/'
13-
# as far as all paths are concerned. Check for this, and fail nicely if not set.
13+
# as far as all paths are concerned. Check for this and fail nicely if not set.
1414

1515
prefix = None
16-
import sys
17-
packaging=False
16+
packaging = False
1817

1918
# We may also be given prefix, either as a configuration option (which will be
2019
# dealt with by substitutions later) or as a command line option. If a command
@@ -27,9 +26,9 @@ packaging=False
2726
# parsed if present, and supercedes any previous DESTDIR picked up from
2827
# environment.
2928

30-
for i, arg in enumerate(sys.argv):
31-
if "--prefix" in arg:
32-
prefix = arg.split('=')[1]
29+
for i, arg in enumerate(argv):
30+
if "--prefix" in arg:
31+
prefix = arg.split('=')[1]
3332

3433
# Given the above prefix possibilities, as well as root and DESTDIR, we need to
3534
# construct a list of data directories to be installed
@@ -43,45 +42,43 @@ for i, arg in enumerate(sys.argv):
4342
# on the command line in preference to the configure prefix.
4443

4544
# First parse the plugin directories
46-
plugin_dirs = [dir for dir in os.listdir('plugins') if os.path.isdir(os.path.join('plugins', dir)) and dir[0] != '.']
45+
plugin_dirs = [dir for dir in listdir('plugins')
46+
if isdir(join('plugins', dir)) and dir[0] != '.']
4747
plugin_data_files = []
48-
if sys.platform == 'darwin' and packaging:
49-
for plugin in plugin_dirs:
50-
plugin_data_files.append(("./plugins/" + plugin,
51-
glob.glob('plugins/' + plugin + '/*.py')))
48+
if platform == 'darwin' and packaging:
49+
for plugin in plugin_dirs:
50+
plugin_data_files.append(("./plugins/" + plugin,
51+
glob('plugins/' + plugin + '/*.py')))
5252
else:
53-
for plugin in plugin_dirs:
54-
if prefix is None:
55-
plugin_data_files.append(("@prefix@/share/diamond/plugins/" + plugin,
56-
glob.glob('plugins/' + plugin + '/*.py')))
57-
else:
58-
plugin_data_files.append((prefix + "/share/diamond/plugins/" + plugin,
59-
glob.glob('plugins/' + plugin + '/*.py')))
53+
for plugin in plugin_dirs:
54+
if prefix is None:
55+
plugin_data_files.append(
56+
("@prefix@/share/diamond/plugins/" + plugin,
57+
glob('plugins/' + plugin + '/*.py')))
58+
else:
59+
plugin_data_files.append(
60+
(prefix + "/share/diamond/plugins/" + plugin,
61+
glob('plugins/' + plugin + '/*.py')))
6062

6163
# Now parse the GUI directories
6264
gui_data_files = []
63-
if sys.platform == 'darwin' and packaging :
64-
gui_data_files.append(("./gui",
65-
["gui/gui.ui", "gui/diamond.svg", "gui/diamond.png"]))
65+
if platform == 'darwin' and packaging:
66+
gui_data_files.append(
67+
("./gui", ["gui/gui.ui", "gui/diamond.svg", "gui/diamond.png"]))
6668
else:
67-
if prefix is None:
68-
gui_data_files.append(("@prefix@/share/diamond/gui",
69-
["gui/gui.ui", "gui/diamond.svg"]))
70-
else:
71-
gui_data_files.append((prefix + "/share/diamond/gui",
72-
["gui/gui.ui", "gui/diamond.svg"]))
69+
if prefix is None:
70+
gui_data_files.append(("@prefix@/share/diamond/gui",
71+
["gui/gui.ui", "gui/diamond.svg"]))
72+
else:
73+
gui_data_files.append((prefix + "/share/diamond/gui",
74+
["gui/gui.ui", "gui/diamond.svg"]))
7375

7476
# We now have all the information we need; run setup.
75-
setup(
76-
name='diamond',
77-
version='1.0',
77+
setup(name='diamond', version='1.0',
7878
description="Fluidity preprocessor",
79-
author = "The ICOM team",
80-
author_email = "patrick.farrell@imperial.ac.uk",
81-
url = "http://amcg.ese.ic.ac.uk",
82-
packages = ['diamond'],
83-
package_dir = {'diamond': 'diamond'},
79+
author="The ICOM team",
80+
author_email="patrick.farrell@imperial.ac.uk",
81+
url="http://amcg.ese.ic.ac.uk", packages=['diamond'],
82+
package_dir={'diamond': 'diamond'},
8483
scripts=["bin/diamond"],
85-
data_files = gui_data_files + plugin_data_files
86-
)
87-
84+
data_files=gui_data_files + plugin_data_files)

dxdiff/setup.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,10 @@
1-
from distutils.core import setup
2-
import os
3-
import os.path
4-
import glob
1+
from setuptools import setup
52

6-
try:
7-
destdir = os.environ["DESTDIR"]
8-
except KeyError:
9-
destdir = ""
10-
11-
setup(
12-
name='dxdiff',
3+
setup(name='dxdiff',
134
version='1.0',
14-
description="An XML aware diff tool.",
15-
author = "The ICOM team",
16-
author_email = "fraser.waters08@imperial.ac.uk",
17-
url = "http://amcg.ese.ic.ac.uk",
18-
packages = ['dxdiff'],
19-
scripts=["dxdiff/dxdiff"],
20-
)
21-
5+
description="An XML aware diff tool",
6+
author="The ICOM team",
7+
author_email="fraser.waters08@imperial.ac.uk",
8+
url="http://amcg.ese.ic.ac.uk",
9+
packages=['dxdiff'],
10+
scripts=["dxdiff/dxdiff"])

python/libspud.c

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#define PyString_Type PyUnicode_Type
1212
#define PyString_AsString PyUnicode_AsUTF8
1313
#define PyString_Check PyUnicode_Check
14-
#define PyString_GET_SIZE PyUnicode_GET_SIZE
14+
#define PyString_GET_SIZE PyUnicode_GET_LENGTH
1515
#endif
1616

1717
static PyObject *SpudError;
@@ -360,7 +360,7 @@ spud_get_option_aux_scalar_or_string(const char *key, int key_len, int type, int
360360
int i;
361361
for (i = 0; i < size+1; i++)
362362
val[i] = '\0';
363-
363+
364364
outcomeGetOption = spud_get_option(key, key_len, val);
365365
if (error_checking(outcomeGetOption, "get option aux scalar or string") == NULL){
366366
return NULL;
@@ -478,7 +478,7 @@ libspud_get_option(PyObject *self, PyObject *args)
478478
if (error_checking(outcomeGetOptionShape, "get option") == NULL){
479479
return NULL;
480480
}
481-
481+
482482
if (rank == -1){ // type error
483483
char errormessage [MAXLENGTH];
484484
snprintf(errormessage, MAXLENGTH, "Error: The specified option has a different \
@@ -506,7 +506,7 @@ libspud_get_option(PyObject *self, PyObject *args)
506506
}
507507
else if (type == SPUD_INT){ //a tensor of ints
508508
return spud_get_option_aux_tensor_ints(key, key_len, type, rank, shape);
509-
}
509+
}
510510
}
511511

512512
PyErr_SetString(SpudError,"Error: Get option failed.");
@@ -562,7 +562,7 @@ set_option_aux_list_doubles(PyObject *pylist, const char *key, int key_len, int
562562
static PyObject*
563563
set_option_aux_string(PyObject *pystring, const char *key, int key_len, int type, int rank, int *shape)
564564
{ // this function is for setting option when the second argument is of type string
565-
char *val = PyString_AsString(pystring);
565+
const char *val = PyString_AsString(pystring);
566566
int outcomeSetOption = spud_set_option(key, key_len, val, type, rank, shape);
567567
return error_checking(outcomeSetOption, "set option aux string");
568568
}
@@ -613,10 +613,10 @@ set_option_aux_tensor_doubles(PyObject *pylist, const char *key, int key_len, in
613613
int outcomeSetOption;
614614

615615
int size = shape[0]*shape[1];
616-
616+
617617
double element;
618618
double val [size];
619-
619+
620620
for (i = 0; i < shape[0]; i++){
621621
PyObject* pysublist = PyList_GetItem(pylist, i);
622622
for (j = 0; j < shape[1]; j++){
@@ -687,7 +687,7 @@ libspud_set_option(PyObject *self, PyObject *args)
687687
int shape[2];
688688
PyObject* firstArg;
689689
PyObject* secondArg;
690-
690+
691691
if(PyTuple_GET_SIZE(args)!=2){
692692
PyErr_SetString(SpudError,"Error: set_option takes exactly 2 arguments.");
693693
return NULL;
@@ -697,19 +697,19 @@ libspud_set_option(PyObject *self, PyObject *args)
697697
secondArg = PyTuple_GetItem(args, 1);
698698
PyArg_Parse(firstArg, "s", &key);
699699
key_len = strlen(key);
700-
700+
701701
if (!spud_have_option(key, key_len)){ //option does not exist yet
702702
int outcomeAddOption = spud_add_option(key, key_len);
703703
error_checking(outcomeAddOption, "set option");
704-
}
705-
704+
}
705+
706706
if (PyInt_Check(secondArg)){ //just an int
707707
type = SPUD_INT;
708708
rank = 0;
709709
shape[0] = -1;
710710
shape[1] = -1;
711-
712-
}
711+
712+
}
713713
else if (PyString_Check(secondArg)){// a string
714714
type = SPUD_STRING;
715715
rank = 1;
@@ -745,13 +745,13 @@ libspud_set_option(PyObject *self, PyObject *args)
745745
}
746746
else if (PyFloat_Check(sublistElement)){//list of lists of doubles
747747
type = SPUD_DOUBLE;
748-
}
748+
}
749749
rank = 2;
750750
shape[0] = pylistSize;
751751
shape[1] = pysublistSize;
752752
}
753753
}
754-
754+
755755
if (rank == 0){ // scalar
756756
set_option_aux_scalar(secondArg, key, key_len, type, rank, shape);
757757
}
@@ -761,10 +761,10 @@ libspud_set_option(PyObject *self, PyObject *args)
761761
}
762762
else if (type == SPUD_INT) { // list of ints
763763
set_option_aux_list_ints(secondArg, key, key_len, type, rank, shape);
764-
}
764+
}
765765
else if (type == SPUD_DOUBLE){ // list of doubles
766766
set_option_aux_list_doubles(secondArg, key, key_len, type, rank, shape);
767-
}
767+
}
768768
}
769769
else if (rank == 2){ // tensor
770770
if (type == SPUD_DOUBLE) { // tensor of doubles
@@ -907,5 +907,3 @@ initlibspud(void)
907907
#endif
908908

909909
}
910-
911-

python/setup.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
from distutils.core import setup, Extension
2-
import os.path
1+
from os.path import abspath
2+
from setuptools import setup, Extension
33

4-
module1 = Extension('libspud', sources = ['libspud.c'], libraries=["spud"], library_dirs=[os.path.abspath("..")], include_dirs=[os.path.abspath("../include")])
5-
6-
setup (name = 'libspud',
7-
version = '1.1.3',
8-
description = 'Python bindings for libspud',
9-
ext_modules = [module1])
4+
setup(name='libspud',
5+
version='1.1.3',
6+
description='Python bindings for libspud',
7+
ext_modules=[Extension('libspud', sources=['libspud.c'],
8+
libraries=["spud"],
9+
library_dirs=[abspath("..")],
10+
include_dirs=[abspath("../include")])])

0 commit comments

Comments
 (0)