@@ -88,74 +88,55 @@ def find_library(name, vision_include):
88
88
include_folder = None
89
89
library_header = '{0}.h' .format (name )
90
90
91
- print ('Running build on conda-build: {0}' .format (is_conda_build ))
92
- if is_conda_build :
93
- # Add conda headers/libraries
94
- if os .name == 'nt' :
95
- build_prefix = os .path .join (build_prefix , 'Library' )
96
- include_folder = os .path .join (build_prefix , 'include' )
97
- lib_folder = os .path .join (build_prefix , 'lib' )
98
- library_header_path = os .path .join (
99
- include_folder , library_header )
100
- library_found = os .path .isfile (library_header_path )
101
- conda_installed = library_found
102
- else :
103
- # Check if using Anaconda to produce wheels
104
- conda = distutils .spawn .find_executable ('conda' )
105
- is_conda = conda is not None
106
- print ('Running build on conda: {0}' .format (is_conda ))
107
- if is_conda :
108
- python_executable = sys .executable
109
- py_folder = os .path .dirname (python_executable )
91
+ # Lookup in TORCHVISION_INCLUDE or in the package file
92
+ package_path = [os .path .join (this_dir , 'torchvision' )]
93
+ for folder in vision_include + package_path :
94
+ candidate_path = os .path .join (folder , library_header )
95
+ library_found = os .path .exists (candidate_path )
96
+ if library_found :
97
+ break
98
+
99
+ if not library_found :
100
+ print ('Running build on conda-build: {0}' .format (is_conda_build ))
101
+ if is_conda_build :
102
+ # Add conda headers/libraries
110
103
if os .name == 'nt' :
111
- env_path = os .path .join (py_folder , 'Library' )
112
- else :
113
- env_path = os .path .dirname (py_folder )
114
- lib_folder = os .path .join (env_path , 'lib' )
115
- include_folder = os .path .join (env_path , 'include' )
104
+ build_prefix = os .path .join (build_prefix , 'Library' )
105
+ include_folder = os .path .join (build_prefix , 'include' )
106
+ lib_folder = os .path .join (build_prefix , 'lib' )
116
107
library_header_path = os .path .join (
117
108
include_folder , library_header )
118
109
library_found = os .path .isfile (library_header_path )
119
110
conda_installed = library_found
120
-
121
- if not library_found :
122
- if sys .platform == 'linux' :
123
- library_found = os .path .exists ('/usr/include/{0}' .format (
124
- library_header ))
125
- library_found = library_found or os .path .exists (
126
- '/usr/local/include/{0}' .format (library_header ))
127
111
else :
128
- # Lookup in TORCHVISION_INCLUDE or in the package file
129
- package_path = [os .path .join (this_dir , 'torchvision' )]
130
- for folder in vision_include + package_path :
131
- candidate_path = os .path .join (folder , library_header )
132
- library_found = os .path .exists (candidate_path )
133
- if library_found :
134
- break
112
+ # Check if using Anaconda to produce wheels
113
+ conda = distutils .spawn .find_executable ('conda' )
114
+ is_conda = conda is not None
115
+ print ('Running build on conda: {0}' .format (is_conda ))
116
+ if is_conda :
117
+ python_executable = sys .executable
118
+ py_folder = os .path .dirname (python_executable )
119
+ if os .name == 'nt' :
120
+ env_path = os .path .join (py_folder , 'Library' )
121
+ else :
122
+ env_path = os .path .dirname (py_folder )
123
+ lib_folder = os .path .join (env_path , 'lib' )
124
+ include_folder = os .path .join (env_path , 'include' )
125
+ library_header_path = os .path .join (
126
+ include_folder , library_header )
127
+ library_found = os .path .isfile (library_header_path )
128
+ conda_installed = library_found
129
+
130
+ if not library_found :
131
+ if sys .platform == 'linux' :
132
+ library_found = os .path .exists ('/usr/include/{0}' .format (
133
+ library_header ))
134
+ library_found = library_found or os .path .exists (
135
+ '/usr/local/include/{0}' .format (library_header ))
135
136
136
137
return library_found , conda_installed , include_folder , lib_folder
137
138
138
139
139
- def get_linux_distribution ():
140
- release_data = {}
141
- with open ("/etc/os-release" ) as f :
142
- reader = csv .reader (f , delimiter = "=" )
143
- for row in reader :
144
- if row :
145
- release_data [row [0 ]] = row [1 ]
146
- if release_data ["ID" ] in ["debian" , "raspbian" ]:
147
- with open ("/etc/debian_version" ) as f :
148
- debian_version = f .readline ().strip ()
149
- major_version = debian_version .split ("." )[0 ]
150
- version_split = release_data ["VERSION" ].split (" " , maxsplit = 1 )
151
- if version_split [0 ] == major_version :
152
- # Just major version shown, replace it with the full version
153
- release_data ["VERSION" ] = " " .join (
154
- [debian_version ] + version_split [1 :])
155
- print ("{} {}" .format (release_data ["NAME" ], release_data ["VERSION" ]))
156
- return release_data
157
-
158
-
159
140
def get_extensions ():
160
141
this_dir = os .path .dirname (os .path .abspath (__file__ ))
161
142
extensions_dir = os .path .join (this_dir , 'torchvision' , 'csrc' )
@@ -267,14 +248,6 @@ def get_extensions():
267
248
image_library = []
268
249
image_link_flags = []
269
250
270
- # Detect if build is running under conda/conda-build
271
- conda = distutils .spawn .find_executable ('conda' )
272
- is_conda = conda is not None
273
-
274
- build_prefix = os .environ .get ('BUILD_PREFIX' , None )
275
- is_conda_build = build_prefix is not None
276
- running_under_conda = is_conda or is_conda_build
277
-
278
251
# Locating libPNG
279
252
libpng = distutils .spawn .find_executable ('libpng-config' )
280
253
pngfix = distutils .spawn .find_executable ('pngfix' )
@@ -291,20 +264,10 @@ def get_extensions():
291
264
png_version = parse_version (png_version )
292
265
if png_version >= parse_version ("1.6.0" ):
293
266
print ('Building torchvision with PNG image support' )
294
- linux = sys .platform == 'linux'
295
- not_debian = False
296
- libpng_on_conda = False
297
- if linux :
298
- bin_folder = os .path .dirname (sys .executable )
299
- png_bin_folder = os .path .dirname (libpng )
300
- libpng_on_conda = (
301
- running_under_conda and bin_folder == png_bin_folder )
302
- release_info = get_linux_distribution ()
303
- not_debian = release_info ["NAME" ] not in {'Ubuntu' , 'Debian' }
304
- if not linux or libpng_on_conda or not_debian :
305
- png_lib = subprocess .run ([libpng , '--libdir' ],
306
- stdout = subprocess .PIPE )
307
- png_lib = png_lib .stdout .strip ().decode ('utf-8' )
267
+ png_lib = subprocess .run ([libpng , '--libdir' ],
268
+ stdout = subprocess .PIPE )
269
+ png_lib = png_lib .stdout .strip ().decode ('utf-8' )
270
+ if 'disabled' not in png_lib :
308
271
image_library += [png_lib ]
309
272
png_include = subprocess .run ([libpng , '--I_opts' ],
310
273
stdout = subprocess .PIPE )
0 commit comments