File: 0004-Do-not-use-distutils.patch

package info (click to toggle)
python-ltfatpy 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 41,408 kB
  • sloc: ansic: 8,546; python: 6,470; makefile: 15
file content (185 lines) | stat: -rw-r--r-- 6,664 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
From: Antonio Valentino <antonio.valentino@tiscali.it>
Date: Sun, 3 Dec 2023 14:32:55 +0000
Subject: Do not use distutils

---
 setup.py | 99 +++++++++++++++++++++++++++++++---------------------------------
 1 file changed, 48 insertions(+), 51 deletions(-)

diff --git a/setup.py b/setup.py
index 6d7f72b..4d19b94 100755
--- a/setup.py
+++ b/setup.py
@@ -57,16 +57,13 @@
 import sys
 import os
 import shutil
+import subprocess
 from pathlib import Path
 
-
-import distutils.spawn as ds
-import distutils.dir_util as dd
-
 # Always prefer setuptools over distutils
 from setuptools import setup, Extension
-from distutils.command.clean import clean
-from distutils.command.sdist import sdist
+# from distutils.command.clean import clean
+# from distutils.command.sdist import sdist
 
 # Test if Cython is installed
 USE_CYTHON = True
@@ -74,7 +71,7 @@ try:
     from Cython.Distutils import build_ext
 except ImportError:
     USE_CYTHON = False
-    from distutils.command.build_ext import build_ext
+    from setuptools.command.build_ext import build_ext
 
 USE_COPYRIGHT = True
 try:
@@ -121,18 +118,18 @@ def remove_generated_c_file():
 #################
 def run_cmake(root_dir):
     """ Runs CMake to determine configuration for this build """
-    if ds.find_executable('cmake') is None:
+    if shutil.which('cmake') is None:
         print("CMake is required to build ltfatpy")
         print("Please install cmake version >= 2.6 and re-run setup")
         sys.exit(-1)
     print("Configuring ltfatpy build with CMake.... ")
     print("Root dir : " + root_dir)
     new_dir = os.path.join(root_dir, 'build')
-    dd.mkpath(new_dir)
+    os.makedirs(new_dir, exist_ok=True)
     os.chdir(new_dir)
     try:
-        ds.spawn(['cmake', '..'])
-    except ds.DistutilsExecError:
+        subprocess.run(['cmake', '..'], check=True)
+    except subprocess.CalledProcessError:
         print("Error while running cmake")
         print("run 'setup.py build --help' for build options")
         print("You may also try editing the settings in CMakeLists.txt file " + 
@@ -169,8 +166,8 @@ def run_make(root_dir):
     build_dir = os.path.join(root_dir, 'build')
     os.chdir(build_dir)
     try:
-        ds.spawn(['make', 'VERBOSE=TRUE'])
-    except ds.DistutilsExecError:
+        subprocess.run(['make', 'VERBOSE=TRUE'], check=True)
+    except subprocess.CalledProcessError:
         print("Error while running make")
         print("run 'setup.py build --help' for build options")
         print("You may also try editing the settings in CMakeLists.txt file " + 
@@ -187,9 +184,9 @@ def run_make_install(root_dir):
     build_dir = os.path.join(root_dir, 'build')
     os.chdir(build_dir)
     try:
-        ds.spawn(['make', 'install'])
+        subprocess.run(['make', 'install'], check=True)
         # +cmake_args.split())
-    except ds.DistutilsExecError:
+    except subprocess.CalledProcessError:
         print("Error while running make install")
         print("run 'setup.py build --help' for build options")
         print("You may also try editing the settings in CMakeLists.txt file " + 
@@ -206,8 +203,8 @@ def run_uninstall(root_dir):
     build_dir = os.path.join(root_dir, 'build')
     os.chdir(build_dir)
     try:
-        ds.spawn(['make', 'uninstall'])
-    except ds.DistutilsExecError:
+        subprocess.run(['make', 'uninstall'], caller=True)
+    except subprocess.CalledProcessError:
         print("Error while running make uninstall")
         print("run 'setup.py build --help' for build options")
         print("You may also try editing the settings in CMakeLists.txt file " + 
@@ -286,43 +283,43 @@ def makeExtension(extName, fileExt, lib_dir, path_includes):
 ######################
 # Custom clean command
 ######################
-class m_clean(clean):
-    """ Remove build directories, and compiled file in the source tree"""
-
-    def run(self):
-        clean.run(self)
-        if os.path.exists('build'):
-            shutil.rmtree('build')
-        if os.path.exists('doc' + os.path.sep + '_build'):
-            shutil.rmtree('doc' + os.path.sep + '_build')
-        for dirpath, dirnames, filenames in os.walk('.'):
-            for filename in filenames:
-                if (filename.endswith('.so') or
-                        filename.endswith('.pyd') or
-                        filename.endswith('.dll') or
-                        filename.endswith('.pyc')):
-                    os.unlink(os.path.join(dirpath, filename))
-            for dirname in dirnames:
-                if dirname == '__pycache__':
-                    shutil.rmtree(os.path.join(dirpath, dirname))
+# class m_clean(clean):
+#     """ Remove build directories, and compiled file in the source tree"""
+#
+#     def run(self):
+#         clean.run(self)
+#         if os.path.exists('build'):
+#             shutil.rmtree('build')
+#         if os.path.exists('doc' + os.path.sep + '_build'):
+#             shutil.rmtree('doc' + os.path.sep + '_build')
+#         for dirpath, dirnames, filenames in os.walk('.'):
+#             for filename in filenames:
+#                 if (filename.endswith('.so') or
+#                         filename.endswith('.pyd') or
+#                         filename.endswith('.dll') or
+#                         filename.endswith('.pyc')):
+#                     os.unlink(os.path.join(dirpath, filename))
+#             for dirname in dirnames:
+#                 if dirname == '__pycache__':
+#                     shutil.rmtree(os.path.join(dirpath, dirname))
 
 
 ##############################
 # Custom sdist command
 ##############################
-class m_sdist(sdist):
-    """ Build source package
-
-    WARNING : The stamping must be done on an default utf8 machine !
-    """
-
-    def run(self):
-        if USE_COPYRIGHT:
-            writeStamp()
-            sdist.run(self)
-            # eraseStamp()
-        else:
-            sdist.run(self)
+# class m_sdist(sdist):
+#     """ Build source package
+#
+#     WARNING : The stamping must be done on an default utf8 machine !
+#     """
+#
+#     def run(self):
+#         if USE_COPYRIGHT:
+#             writeStamp()
+#             sdist.run(self)
+#             # eraseStamp()
+#         else:
+#             sdist.run(self)
 
 
 ####################
@@ -374,8 +371,8 @@ def setup_package():
           extras_require=extras_require,
           tests_require=['nose', 'coverage'],
           cmdclass={'build_ext': m_build_ext,
-                    'clean': m_clean, 'sdist': m_sdist},
-             )
+                    },  # 'clean': m_clean, 'sdist': m_sdist},
+          )
 
 
 if __name__ == "__main__":