@@ -332,21 +332,33 @@ def decompress_file(src, dst, comtype, stat=None):
332
332
compression_type = _createrepo_c .compression_type
333
333
334
334
335
- DATA = os .path .join (os .path .dirname (__file__ ), 'data' )
335
+ # If we have been built as a Python package, e.g. "setup.py", this is
336
+ # where the binaries will be located.
337
+ _DATA_DIR = os .path .join (os .path .dirname (__file__ ), 'data' )
336
338
337
- # Support running tests from the source tree
338
- if not os .path .exists (DATA ):
339
- from skbuild .constants import CMAKE_INSTALL_DIR as SKBUILD_CMAKE_INSTALL_DIR
340
- _data = os .path .abspath (os .path .join (
341
- os .path .dirname (__file__ ), '..' , SKBUILD_CMAKE_INSTALL_DIR , 'src/python/data' ))
342
- if os .path .exists (_data ):
343
- DATA = _data
339
+ # Where we will look for the binaries. Default to looking on the system PATH.
340
+ # If one of the following test succeeds, we can change this to look somewhere else.
341
+ # Otherwise, probably, we were not built as a Python package, e.g. RPM, "cmake ..; make"
342
+ # In that case, let's just assume that the binary will be on the PATH somewhere.
343
+ _BIN_DIR = ""
344
344
345
- BIN_DIR = os .path .join (DATA , 'bin' )
345
+ # Support running tests from the source tree
346
+ if not os .path .exists (_DATA_DIR ):
347
+ # We can't find it. This might mean we've been built as an "editable" Python installation
348
+ # Try building the path manually.
349
+ try :
350
+ from skbuild .constants import CMAKE_INSTALL_DIR as SKBUILD_CMAKE_INSTALL_DIR
351
+ _data = os .path .abspath (os .path .join (
352
+ os .path .dirname (__file__ ), '..' , SKBUILD_CMAKE_INSTALL_DIR , 'src/python/createrepo_c/data' ))
353
+ if os .path .exists (_data ):
354
+ _BIN_DIR = os .path .join (_data , 'bin' )
355
+ except ImportError :
356
+ # Scikit isn't available
357
+ pass
346
358
347
359
348
360
def _program (name , args ):
349
- return subprocess .call ([os .path .join (BIN_DIR , name )] + args )
361
+ return subprocess .call ([os .path .join (_BIN_DIR , name )] + args )
350
362
351
363
352
364
def createrepo_c ():
0 commit comments