calibre/setup/git_post_checkout_hook.py
2025-09-21 12:31:49 +05:30

38 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python
__license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import os
import runpy
import subprocess
import sys
prev_rev, current_rev, flags = sys.argv[1:]
def get_branch_name(rev):
return subprocess.check_output(['git', 'name-rev', '--name-only', '--refs=refs/heads/*', rev]).decode('utf-8').strip()
base = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
os.chdir(base)
if flags == '1': # A branch checkout
prev_branch, cur_branch = list(map(get_branch_name, (prev_rev, current_rev)))
rebase_in_progress = os.path.exists('.git/rebase-apply') or os.path.exists('.git/rebase-merge')
before = sys.argv
try:
sys.argv = ['setup.py', 'gui', '--summary']
runpy.run_path('setup.py', run_name='__main__')
finally:
sys.argv = before
# Remove .pyc files as some of them might have been orphaned
for dirpath, dirnames, filenames in os.walk('.'):
for f in filenames:
fpath = os.path.join(dirpath, f)
if f.endswith('.pyc') and '/chroot/' not in fpath:
os.remove(fpath)