<s> import sys <EOL> import tempfile <EOL> import subprocess <EOL> from pathlib import Path <EOL> import click <EOL> import requests <EOL> from . nixpkgs_repo import get_repo , packages , packages_for_sha <EOL> def build_in_path ( args , attrs , path ) : <EOL> """<STR_LIT>""" <EOL> if not attrs : <EOL> click . echo ( '<STR_LIT>' ) <EOL> return <EOL> canonical_path = str ( Path ( path ) . resolve ( ) ) <EOL> result_dir = tempfile . mkdtemp ( prefix = '<STR_LIT>' ) <EOL> click . echo ( '<STR_LIT>' . format ( click . style ( result_dir , bold = True ) , <EOL> click . style ( '<STR_LIT:U+0020>' . join ( attrs ) , bold = True ) ) ) <EOL> command = [ '<STR_LIT>' ] <EOL> command += args <EOL> for a in attrs : <EOL> command . append ( '<STR_LIT>' ) <EOL> command . append ( a ) <EOL> command . append ( canonical_path ) <EOL> try : <EOL> subprocess . check_call ( command , cwd = result_dir ) <EOL> except subprocess . CalledProcessError : <EOL> click . secho ( '<STR_LIT>' . format ( '<STR_LIT:U+0020>' . join ( command ) ) , fg = '<STR_LIT>' ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> click . echo ( '<STR_LIT>' . format ( click . style ( result_dir , bold = True ) ) ) <EOL> subprocess . check_call ( [ '<STR_LIT>' , '<STR_LIT>' , result_dir ] ) <EOL> def build_sha ( args , attrs , sha ) : <EOL> """<STR_LIT>""" <EOL> repo = get_repo ( ) <EOL> repo . checkout ( sha ) <EOL> build_in_path ( args , attrs , repo . path ) <EOL> def differences ( old , new ) : <EOL> """<STR_LIT>""" <EOL> raw = new - old <EOL> return { l . split ( ) [ <NUM_LIT:0> ] for l in raw } <EOL> @ click . group ( ) <EOL> @ click . option ( '<STR_LIT>' , '<STR_LIT>' , is_flag = True , help = '<STR_LIT>' ) <EOL> @ click . pass_context <EOL> def cli ( ctx , keep_going ) : <EOL> """<STR_LIT>""" <EOL> if keep_going : <EOL> ctx . obj = { '<STR_LIT>' : [ '<STR_LIT>' ] } <EOL> else : <EOL> ctx . obj = { '<STR_LIT>' : [ ] } <EOL> @ cli . command ( short_help = '<STR_LIT>' ) <EOL> @ click . option ( '<STR_LIT>' , default = '<STR_LIT>' ) <EOL> @ click . pass_context <EOL> def wip ( ctx , against ) : <EOL> """<STR_LIT>""" <EOL> if not Path ( '<STR_LIT>' ) . exists ( ) : <EOL> click . secho ( '<STR_LIT>' , fg = '<STR_LIT>' ) <EOL> return <EOL> dirty_working_tree = subprocess . call ( '<STR_LIT>' . split ( ) ) <EOL> if not dirty_working_tree : <EOL> if against == '<STR_LIT>' : <EOL> click . secho ( '<STR_LIT>' ) <EOL> return <EOL> sha = subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , against ] ) . decode ( ) . strip ( ) <EOL> attrs = differences ( packages_for_sha ( sha ) , <EOL> packages ( '<STR_LIT:.>' ) ) <EOL> build_in_path ( ctx . obj [ '<STR_LIT>' ] , attrs , '<STR_LIT:.>' ) <EOL> @ cli . command ( '<STR_LIT>' , short_help = '<STR_LIT>' ) <EOL> @ click . argument ( '<STR_LIT>' , type = click . INT ) <EOL> @ click . pass_context <EOL> def review_pr ( ctx , pr ) : <EOL> """<STR_LIT>""" <EOL> pr_url = '<STR_LIT>' . format ( pr ) <EOL> payload = requests . get ( pr_url ) . json ( ) <EOL> click . echo ( '<STR_LIT>' . format ( <EOL> click . style ( str ( pr ) , bold = True ) , <EOL> click . style ( payload . get ( '<STR_LIT:title>' , '<STR_LIT>' ) , bold = True ) ) ) <EOL> base_ref = payload [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> repo = get_repo ( ) <EOL> click . echo ( '<STR_LIT>' . format ( base_ref ) ) <EOL> base_refspec = '<STR_LIT>' . format ( payload [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> repo . fetch ( base_refspec ) <EOL> base = repo . sha ( '<STR_LIT>' ) <EOL> click . echo ( '<STR_LIT>' ) <EOL> head_refspec = '<STR_LIT>' . format ( pr ) <EOL> repo . fetch ( head_refspec ) <EOL> head = repo . sha ( '<STR_LIT>' ) <EOL> click . echo ( '<STR_LIT>' ) <EOL> depth = <NUM_LIT:10> <EOL> while not repo . merge_base ( head , base ) : <EOL> repo . fetch ( base_refspec , depth = depth ) <EOL> repo . fetch ( head_refspec , depth = depth ) <EOL> depth *= <NUM_LIT:2> <EOL> repo . fetch ( base_refspec , depth = depth ) <EOL> click . echo ( '<STR_LIT>' ) <EOL> repo . checkout ( base ) <EOL> repo . git ( [ '<STR_LIT>' , head , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> merged = repo . sha ( '<STR_LIT>' ) <EOL> attrs = differences ( packages_for_sha ( base ) , <EOL> packages_for_sha ( merged ) ) <EOL> build_sha ( ctx . obj [ '<STR_LIT>' ] , attrs , merged ) </s>
