<s> from operator import attrgetter <EOL> import inspect <EOL> import subprocess <EOL> import os <EOL> import sys <EOL> from functools import partial <EOL> REVISION_CMD = '<STR_LIT>' <EOL> def _get_git_revision ( ) : <EOL> try : <EOL> revision = subprocess . check_output ( REVISION_CMD . split ( ) ) . strip ( ) <EOL> except subprocess . CalledProcessError : <EOL> print ( '<STR_LIT>' ) <EOL> return None <EOL> return revision . decode ( '<STR_LIT:utf-8>' ) <EOL> def _linkcode_resolve ( domain , info , package , url_fmt , revision ) : <EOL> """<STR_LIT>""" <EOL> if revision is None : <EOL> return <EOL> if domain not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return <EOL> if not info . get ( '<STR_LIT>' ) or not info . get ( '<STR_LIT>' ) : <EOL> return <EOL> class_name = info [ '<STR_LIT>' ] . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> if type ( class_name ) != str : <EOL> class_name = class_name . encode ( '<STR_LIT:utf-8>' ) <EOL> module = __import__ ( info [ '<STR_LIT>' ] , fromlist = [ class_name ] ) <EOL> obj = attrgetter ( info [ '<STR_LIT>' ] ) ( module ) <EOL> try : <EOL> fn = inspect . getsourcefile ( obj ) <EOL> except Exception : <EOL> fn = None <EOL> if not fn : <EOL> try : <EOL> fn = inspect . getsourcefile ( sys . modules [ obj . __module__ ] ) <EOL> except Exception : <EOL> fn = None <EOL> if not fn : <EOL> return <EOL> fn = os . path . relpath ( fn , <EOL> start = os . path . dirname ( __import__ ( package ) . __file__ ) ) <EOL> try : <EOL> lineno = inspect . getsourcelines ( obj ) [ <NUM_LIT:1> ] <EOL> except Exception : <EOL> lineno = '<STR_LIT>' <EOL> return url_fmt . format ( revision = revision , package = package , <EOL> path = fn , lineno = lineno ) <EOL> def make_linkcode_resolve ( package , url_fmt ) : <EOL> """<STR_LIT>""" <EOL> revision = _get_git_revision ( ) <EOL> return partial ( _linkcode_resolve , revision = revision , package = package , <EOL> url_fmt = url_fmt ) </s>
