<s> """<STR_LIT>""" <EOL> import contextlib <EOL> import datetime <EOL> import io <EOL> import optparse <EOL> import os <EOL> import os . path <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import threading <EOL> import time <EOL> from pip . baseparser import create_main_parser <EOL> from pip . commands import commands <EOL> from pip . exceptions import PipError <EOL> from pip . locations import src_prefix <EOL> from pip . log import Logger , logger <EOL> from pip . util import backup_dir <EOL> from pip . vcs import vcs <EOL> from pip . vcs . git import Git <EOL> from setuptools . sandbox import run_setup <EOL> from . branch import Branch <EOL> from . commit import Commit <EOL> from . logger import LoggerProviderMixin <EOL> __all__ = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> PYPI_INDEX_URLS = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> capture_stdout_lock = threading . Lock ( ) <EOL> @ contextlib . contextmanager <EOL> def capture_stdout ( ) : <EOL> """<STR_LIT>""" <EOL> with capture_stdout_lock : <EOL> stdout = sys . stdout <EOL> sys . stdout = io . BytesIO ( ) <EOL> yield sys . stdout <EOL> sys . stdout = stdout <EOL> class Dist ( LoggerProviderMixin ) : <EOL> """<STR_LIT>""" <EOL> app = None <EOL> branch = None <EOL> commit = None <EOL> def __init__ ( self , branch , commit ) : <EOL> if not isinstance ( branch , Branch ) : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' + repr ( branch ) ) <EOL> elif not isinstance ( commit , Commit ) : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' + repr ( commit ) ) <EOL> elif branch . app is not commit . app : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' . format ( branch , commit ) ) <EOL> self . branch = branch <EOL> self . commit = commit <EOL> self . app = commit . app <EOL> @ contextlib . contextmanager <EOL> def archive_package ( self , cache = True ) : <EOL> """<STR_LIT>""" <EOL> logger_ = self . get_logger ( '<STR_LIT>' ) <EOL> with self . branch . fetch ( self . commit . ref ) as path : <EOL> setup_script = os . path . join ( path , '<STR_LIT>' ) <EOL> if not os . path . isfile ( setup_script ) : <EOL> raise IOError ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( self . commit ) ) <EOL> tag = '<STR_LIT>' . format ( <EOL> self . branch . label , <EOL> self . commit . committed_at . astimezone ( UTC ( ) ) , <EOL> self . commit <EOL> ) <EOL> with capture_stdout ( ) as buffer_ : <EOL> run_setup ( setup_script , [ '<STR_LIT>' ] ) <EOL> fullname = buffer_ . getvalue ( ) . rstrip ( ) . splitlines ( ) [ - <NUM_LIT:1> ] <EOL> package_name = fullname + tag <EOL> filename = package_name + '<STR_LIT>' <EOL> if cache : <EOL> cache_dir_path = os . path . join ( <EOL> tempfile . gettempdir ( ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> if not os . path . isdir ( cache_dir_path ) : <EOL> os . makedirs ( cache_dir_path ) <EOL> cache_path = os . path . join ( cache_dir_path , filename ) <EOL> if os . path . isfile ( cache_path ) : <EOL> logger_ . info ( '<STR_LIT>' , <EOL> cache_path ) <EOL> yield package_name , filename , cache_path <EOL> return <EOL> run_setup ( setup_script , [ <EOL> '<STR_LIT>' , '<STR_LIT>' , tag , <EOL> '<STR_LIT>' , '<STR_LIT>' <EOL> ] ) <EOL> filepath = os . path . join ( path , '<STR_LIT>' , filename ) <EOL> logger_ . info ( '<STR_LIT>' , filepath ) <EOL> if cache : <EOL> logger_ . info ( '<STR_LIT>' , cache_path ) <EOL> shutil . copyfile ( filepath , cache_path ) <EOL> yield package_name , filename , filepath <EOL> @ contextlib . contextmanager <EOL> def bundle_package ( self , cache = True ) : <EOL> """<STR_LIT>""" <EOL> asuka_logger = self . get_logger ( '<STR_LIT>' ) <EOL> if not getattr ( type ( self ) , '<STR_LIT>' , False ) : <EOL> type ( self ) . initialized = True <EOL> logger . consumers . extend ( [ <EOL> ( Logger . FATAL , asuka_logger . critical ) , <EOL> ( Logger . ERROR , asuka_logger . error ) , <EOL> ( Logger . WARN , asuka_logger . warn ) , <EOL> ( Logger . NOTIFY , asuka_logger . info ) , <EOL> ( Logger . INFO , asuka_logger . info ) , <EOL> ( Logger . DEBUG , asuka_logger . debug ) , <EOL> ( Logger . VERBOSE_DEBUG , asuka_logger . debug ) <EOL> ] ) <EOL> vcs . register ( Git ) <EOL> main_parser = create_main_parser ( ) <EOL> bundle = commands [ '<STR_LIT>' ] ( main_parser ) <EOL> with self . archive_package ( ) as ( package_name , filename , filepath ) : <EOL> bundle_filename = package_name + '<STR_LIT>' <EOL> if cache : <EOL> cache_dir_path = os . path . join ( <EOL> tempfile . gettempdir ( ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> if not os . path . isdir ( cache_dir_path ) : <EOL> os . makedirs ( cache_dir_path ) <EOL> cache_path = os . path . join ( cache_dir_path , bundle_filename ) <EOL> if os . path . isfile ( cache_path ) : <EOL> asuka_logger . info ( '<STR_LIT>' , <EOL> cache_path ) <EOL> yield package_name , bundle_filename , cache_path <EOL> return <EOL> tempdir = tempfile . gettempdir ( ) <EOL> bundle_path = os . path . join ( <EOL> os . path . dirname ( filepath ) , <EOL> bundle_filename <EOL> ) <EOL> asuka_logger . info ( '<STR_LIT>' , bundle_path ) <EOL> options = optparse . Values ( ) <EOL> options . editables = [ ] <EOL> options . requirements = [ ] <EOL> options . find_links = [ ] <EOL> options . index_url = PYPI_INDEX_URLS [ <NUM_LIT:0> ] <EOL> options . extra_index_urls = PYPI_INDEX_URLS [ <NUM_LIT:1> : ] <EOL> options . no_index = False <EOL> options . use_mirrors = False <EOL> options . mirrors = True <EOL> options . build_dir = os . path . join ( <EOL> tempdir , <EOL> '<STR_LIT>' <EOL> ) <EOL> options . target_dir = None <EOL> options . download_dir = None <EOL> options . download_cache = os . path . join ( <EOL> tempdir , <EOL> '<STR_LIT>' <EOL> ) <EOL> options . src_dir = backup_dir ( src_prefix , '<STR_LIT>' ) <EOL> options . upgrade = False <EOL> options . force_reinstall = False <EOL> options . ignore_dependencies = False <EOL> options . no_install = True <EOL> options . no_download = False <EOL> options . install_options = [ ] <EOL> options . global_options = [ ] <EOL> options . use_user_site = False <EOL> options . as_egg = False <EOL> asuka_logger . debug ( '<STR_LIT>' , bundle_path , filepath ) <EOL> retrial = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> shutil . rmtree ( options . build_dir ) <EOL> except ( OSError , IOError ) : <EOL> pass <EOL> try : <EOL> bundle . run ( options , [ bundle_path , filepath ] ) <EOL> except PipError as e : <EOL> asuka_logger . exception ( e ) <EOL> retrial += <NUM_LIT:1> <EOL> if retrial < <NUM_LIT:3> : <EOL> asuka_logger . error ( <EOL> '<STR_LIT>' , <EOL> retrial , retrial ** <NUM_LIT:2> <EOL> ) <EOL> options . index_url = PYPI_INDEX_URLS [ retrial ] <EOL> options . extra_index_urls = PYPI_INDEX_URLS [ retrial + <NUM_LIT:1> : ] <EOL> time . sleep ( retrial ** <NUM_LIT:2> ) <EOL> continue <EOL> raise <EOL> finally : <EOL> if os . path . isdir ( options . build_dir ) : <EOL> shutil . rmtree ( options . build_dir ) <EOL> break <EOL> asuka_logger . debug ( '<STR_LIT>' , bundle_path , filepath ) <EOL> if cache : <EOL> asuka_logger . info ( '<STR_LIT>' , cache_path ) <EOL> shutil . copyfile ( bundle_path , cache_path ) <EOL> yield package_name , os . path . basename ( bundle_path ) , bundle_path <EOL> class UTC ( datetime . tzinfo ) : <EOL> """<STR_LIT>""" <EOL> def utcoffset ( self , value ) : <EOL> return datetime . timedelta ( <NUM_LIT:0> ) <EOL> def tzname ( self , value ) : <EOL> return '<STR_LIT>' <EOL> def dst ( self , value ) : <EOL> return datetime . timedelta ( <NUM_LIT:0> ) </s>
