diff options
author | nfnty <git@nfnty.se> | 2017-02-10 05:01:48 +0100 |
---|---|---|
committer | nfnty <git@nfnty.se> | 2017-02-10 06:48:15 +0100 |
commit | d8b807c5a9ef74856b1ece387a21692118c34984 (patch) | |
tree | 6b4e008e9bd1368f0b8452f03464a945939cfe8d | |
parent | 144de5540dc118f9d1cd50d0b16e817616f367bc (diff) | |
download | ranger-d8b807c5a9ef74856b1ece387a21692118c34984.tar.gz |
setup.py: Fix build scripts for PyPI
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | setup.py | 36 |
2 files changed, 27 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore index 6d54530a..02a51413 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ /.cache /build +/build_scripts /dist /doc/ranger.1.html /install_log.txt diff --git a/setup.py b/setup.py index 0ed861eb..75189cc9 100755 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ from __future__ import (absolute_import, division, print_function) +from hashlib import sha512 import os import shutil @@ -15,17 +16,35 @@ except ImportError: import ranger +SCRIPTS_PATH = 'build_scripts' +SCRIPTS = ( + ('ranger.py', 'ranger'), + ('ranger/ext/rifle.py', 'rifle'), +) + + def findall(directory): return [os.path.join(directory, f) for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))] -def script(src_path, name): - if not os.path.exists('build/scripts_tmp'): - os.makedirs('build/scripts_tmp') - dest_path = os.path.join('build/scripts_tmp', name) - shutil.copy(src_path, dest_path) - return dest_path +def hash_path(path): + with open(path, 'rb') as fobj: + return sha512(fobj.read()).digest() + + +def scripts_hack(): + ''' Hack around `pip install` temporary directories ''' + if not os.path.exists(SCRIPTS_PATH): + os.makedirs(SCRIPTS_PATH) + scripts = [] + for src_path, basename in SCRIPTS: + dest_path = os.path.join(SCRIPTS_PATH, basename) + if not os.path.exists(dest_path) or \ + (os.path.exists(src_path) and hash_path(src_path) != hash_path(dest_path)): + shutil.copy(src_path, dest_path) + scripts += [dest_path] + return scripts def main(): @@ -39,10 +58,7 @@ def main(): license=ranger.__license__, url='http://ranger.nongnu.org', - scripts=[ - script('ranger.py', 'ranger'), - script('ranger/ext/rifle.py', 'rifle'), - ], + scripts=scripts_hack(), data_files=[ ('share/applications', [ 'doc/ranger.desktop', |