<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from collections import defaultdict , OrderedDict <EOL> from contextlib import contextmanager <EOL> from fabric . api import env , local , run , sudo , cd , hide , task <EOL> from fabric . contrib . files import exists <EOL> from fabric . colors import blue , red , green <EOL> from fabric . utils import error , warn <EOL> try : <EOL> env . colorize_errors = True <EOL> except AttributeError : <EOL> pass <EOL> try : <EOL> import requests <EOL> from requests . auth import HTTPBasicAuth <EOL> from requests_oauthlib import OAuth2 <EOL> except ImportError : <EOL> warn ( "<STR_LIT>" ) <EOL> requests = False <EOL> import unicodedata <EOL> import json <EOL> from getpass import getpass <EOL> import os <EOL> import stat <EOL> import sys <EOL> import time <EOL> import ConfigParser <EOL> try : <EOL> from fabvenv import virtualenv , make_virtualenv <EOL> except ImportError : <EOL> error ( "<STR_LIT>" ) <EOL> env . use_ssh_config = True <EOL> def full_path_split ( path ) : <EOL> """<STR_LIT>""" <EOL> rest , tail = os . path . split ( path ) <EOL> if not rest or rest == os . path . sep : <EOL> return ( tail , ) <EOL> return full_path_split ( rest ) + ( tail , ) <EOL> @ contextmanager <EOL> def use_venv ( pyversion ) : <EOL> """<STR_LIT>""" <EOL> pyversion = str ( pyversion ) <EOL> if pyversion == '<STR_LIT:2>' : <EOL> yield <EOL> elif pyversion == '<STR_LIT:3>' : <EOL> oldvenv = env . virtualenv <EOL> env . virtualenv = '<STR_LIT>' <EOL> yield <EOL> env . virtualenv = oldvenv <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % pyversion ) <EOL> @ task <EOL> def prepare ( ) : <EOL> """<STR_LIT>""" <EOL> prepare_apt ( ) <EOL> checkout_cache ( ) <EOL> @ task <EOL> def prepare_apt ( ) : <EOL> """<STR_LIT>""" <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> sudo ( "<STR_LIT>" ) <EOL> @ task <EOL> def remove_userspace ( ) : <EOL> """<STR_LIT>""" <EOL> run ( "<STR_LIT>" ) <EOL> if os . path . exists ( "<STR_LIT>" ) : <EOL> error ( "<STR_LIT>" ) <EOL> @ task <EOL> def checkout_cache ( ) : <EOL> """<STR_LIT>""" <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def gitrepos ( branch = None , fork = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> if not exists ( "<STR_LIT>" ) : <EOL> error ( "<STR_LIT>" ) <EOL> if not branch : <EOL> branch = local ( "<STR_LIT>" , capture = True ) <EOL> if branch == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" . format ( fork = fork ) ) <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" % branch ) <EOL> @ task <EOL> def get_sympy_version ( version_cache = [ ] ) : <EOL> """<STR_LIT>""" <EOL> if version_cache : <EOL> return version_cache [ <NUM_LIT:0> ] <EOL> if not exists ( "<STR_LIT>" ) : <EOL> gitrepos ( ) <EOL> with cd ( "<STR_LIT>" ) : <EOL> version = run ( '<STR_LIT>' ) <EOL> assert '<STR_LIT:\n>' not in version <EOL> assert '<STR_LIT:U+0020>' not in version <EOL> assert '<STR_LIT:\t>' not in version <EOL> version_cache . append ( version ) <EOL> return version <EOL> @ task <EOL> def get_sympy_short_version ( ) : <EOL> """<STR_LIT>""" <EOL> version = get_sympy_version ( ) <EOL> parts = version . split ( '<STR_LIT:.>' ) <EOL> non_rc_parts = [ i for i in parts if i . isdigit ( ) ] <EOL> return '<STR_LIT:.>' . join ( non_rc_parts ) <EOL> @ task <EOL> def test_sympy ( ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def test_tarball ( release = '<STR_LIT:2>' ) : <EOL> """<STR_LIT>""" <EOL> if release not in { '<STR_LIT:2>' , '<STR_LIT:3>' } : <EOL> raise ValueError ( "<STR_LIT>" % release ) <EOL> venv = "<STR_LIT>" . format ( release = release ) <EOL> tarball_formatter_dict = tarball_formatter ( ) <EOL> with use_venv ( release ) : <EOL> make_virtualenv ( venv ) <EOL> with virtualenv ( venv ) : <EOL> run ( "<STR_LIT>" . format ( ** tarball_formatter_dict ) ) <EOL> run ( "<STR_LIT>" ) <EOL> with cd ( "<STR_LIT>" . format ( ** tarball_formatter_dict ) ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( '<STR_LIT>' ) <EOL> @ task <EOL> def release ( branch = None , fork = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> remove_userspace ( ) <EOL> gitrepos ( branch , fork ) <EOL> local ( "<STR_LIT>" ) <EOL> test_sympy ( ) <EOL> source_tarball ( ) <EOL> build_docs ( ) <EOL> copy_release_files ( ) <EOL> test_tarball ( '<STR_LIT:2>' ) <EOL> test_tarball ( '<STR_LIT:3>' ) <EOL> compare_tar_against_git ( ) <EOL> print_authors ( ) <EOL> @ task <EOL> def source_tarball ( ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" . format ( ** tarball_formatter ( ) ) ) <EOL> @ task <EOL> def build_docs ( ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> venv = "<STR_LIT>" <EOL> make_virtualenv ( venv , dependencies = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> with virtualenv ( venv ) : <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" . format ( ** tarball_formatter ( ) ) ) <EOL> run ( "<STR_LIT>" . format ( ** tarball_formatter ( ) ) ) <EOL> run ( "<STR_LIT>" . format ( ** tarball_formatter ( ) ) ) <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" . format ( ** tarball_formatter ( ) ) ) <EOL> @ task <EOL> def copy_release_files ( ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def show_files ( file , print_ = True ) : <EOL> """<STR_LIT>""" <EOL> if file == '<STR_LIT:source>' : <EOL> ret = local ( "<STR_LIT>" . format ( ** tarball_formatter ( ) ) , capture = True ) <EOL> elif file == '<STR_LIT>' : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> elif file == '<STR_LIT:html>' : <EOL> ret = local ( "<STR_LIT>" . format ( ** tarball_formatter ( ) ) , capture = True ) <EOL> else : <EOL> raise ValueError ( file + "<STR_LIT>" ) <EOL> if print_ : <EOL> print ( ret ) <EOL> return ret <EOL> git_whitelist = { <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> } <EOL> tarball_whitelist = { <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> } <EOL> @ task <EOL> def compare_tar_against_git ( ) : <EOL> """<STR_LIT>""" <EOL> with hide ( "<STR_LIT>" ) : <EOL> with cd ( "<STR_LIT>" ) : <EOL> git_lsfiles = set ( [ i . strip ( ) for i in run ( "<STR_LIT>" ) . split ( "<STR_LIT:\n>" ) ] ) <EOL> tar_output_orig = set ( show_files ( '<STR_LIT:source>' , print_ = False ) . split ( "<STR_LIT:\n>" ) ) <EOL> tar_output = set ( ) <EOL> for file in tar_output_orig : <EOL> split_path = full_path_split ( file ) <EOL> if split_path [ - <NUM_LIT:1> ] : <EOL> tar_output . add ( os . path . join ( * split_path [ <NUM_LIT:1> : ] ) ) <EOL> fail = False <EOL> print ( ) <EOL> print ( blue ( "<STR_LIT>" , <EOL> bold = True ) ) <EOL> print ( ) <EOL> for line in sorted ( tar_output . intersection ( git_whitelist ) ) : <EOL> fail = True <EOL> print ( line ) <EOL> print ( ) <EOL> print ( blue ( "<STR_LIT>" , bold = True ) ) <EOL> print ( ) <EOL> for line in sorted ( git_lsfiles - tar_output - git_whitelist ) : <EOL> fail = True <EOL> print ( line ) <EOL> print ( ) <EOL> print ( blue ( "<STR_LIT>" , bold = True ) ) <EOL> print ( ) <EOL> for line in sorted ( tar_output - git_lsfiles - tarball_whitelist ) : <EOL> fail = True <EOL> print ( line ) <EOL> if fail : <EOL> error ( "<STR_LIT>" ) <EOL> @ task <EOL> def md5 ( file = '<STR_LIT:*>' , print_ = True ) : <EOL> """<STR_LIT>""" <EOL> out = local ( "<STR_LIT>" + file , capture = True ) <EOL> out = [ i . split ( ) for i in out . strip ( ) . split ( '<STR_LIT:\n>' ) ] <EOL> out = '<STR_LIT:\n>' . join ( [ "<STR_LIT>" % ( i , os . path . split ( j ) [ <NUM_LIT:1> ] ) for i , j in out ] ) <EOL> if print_ : <EOL> print ( out ) <EOL> return out <EOL> descriptions = OrderedDict ( [ <EOL> ( '<STR_LIT:source>' , "<STR_LIT>" , ) , <EOL> ( '<STR_LIT:win32>' , "<STR_LIT>" , ) , <EOL> ( '<STR_LIT:html>' , '''<STR_LIT>''' , ) , <EOL> ( '<STR_LIT>' , '''<STR_LIT>''' , ) , <EOL> ] ) <EOL> @ task <EOL> def size ( file = '<STR_LIT:*>' , print_ = True ) : <EOL> """<STR_LIT>""" <EOL> out = local ( "<STR_LIT>" + file , capture = True ) <EOL> out = [ i . split ( ) for i in out . strip ( ) . split ( '<STR_LIT:\n>' ) ] <EOL> out = '<STR_LIT:\n>' . join ( [ "<STR_LIT>" % ( i , os . path . split ( j ) [ <NUM_LIT:1> ] ) for i , j in out ] ) <EOL> if print_ : <EOL> print ( out ) <EOL> return out <EOL> @ task <EOL> def table ( ) : <EOL> """<STR_LIT>""" <EOL> tarball_formatter_dict = tarball_formatter ( ) <EOL> shortversion = get_sympy_short_version ( ) <EOL> tarball_formatter_dict [ '<STR_LIT:version>' ] = shortversion <EOL> md5s = [ i . split ( '<STR_LIT:\t>' ) for i in md5 ( print_ = False ) . split ( '<STR_LIT:\n>' ) ] <EOL> md5s_dict = { name : md5 for md5 , name in md5s } <EOL> sizes = [ i . split ( '<STR_LIT:\t>' ) for i in size ( print_ = False ) . split ( '<STR_LIT:\n>' ) ] <EOL> sizes_dict = { name : size for size , name in sizes } <EOL> table = [ ] <EOL> @ contextmanager <EOL> def tag ( name ) : <EOL> table . append ( "<STR_LIT>" % name ) <EOL> yield <EOL> table . append ( "<STR_LIT>" % name ) <EOL> with tag ( '<STR_LIT>' ) : <EOL> with tag ( '<STR_LIT>' ) : <EOL> for headname in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:size>" , "<STR_LIT>" ] : <EOL> with tag ( "<STR_LIT>" ) : <EOL> table . append ( headname ) <EOL> for key in descriptions : <EOL> name = get_tarball_name ( key ) <EOL> with tag ( '<STR_LIT>' ) : <EOL> with tag ( '<STR_LIT>' ) : <EOL> with tag ( '<STR_LIT:b>' ) : <EOL> table . append ( name ) <EOL> with tag ( '<STR_LIT>' ) : <EOL> table . append ( descriptions [ key ] . format ( ** tarball_formatter_dict ) ) <EOL> with tag ( '<STR_LIT>' ) : <EOL> table . append ( sizes_dict [ name ] ) <EOL> with tag ( '<STR_LIT>' ) : <EOL> table . append ( md5s_dict [ name ] ) <EOL> out = '<STR_LIT:U+0020>' . join ( table ) <EOL> return out <EOL> @ task <EOL> def get_tarball_name ( file ) : <EOL> """<STR_LIT>""" <EOL> version = get_sympy_version ( ) <EOL> doctypename = defaultdict ( str , { '<STR_LIT:html>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> winos = defaultdict ( str , { '<STR_LIT:win32>' : '<STR_LIT:win32>' , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> if file in { '<STR_LIT>' , '<STR_LIT:source>' } : <EOL> name = '<STR_LIT>' <EOL> elif file == '<STR_LIT>' : <EOL> name = "<STR_LIT>" <EOL> elif file in { '<STR_LIT:win32>' , '<STR_LIT>' } : <EOL> name = "<STR_LIT>" <EOL> elif file in { '<STR_LIT:html>' , '<STR_LIT>' , '<STR_LIT>' } : <EOL> name = "<STR_LIT>" <EOL> if file == '<STR_LIT>' : <EOL> file = '<STR_LIT:html>' <EOL> else : <EOL> name += "<STR_LIT>" <EOL> elif file == '<STR_LIT>' : <EOL> name = "<STR_LIT>" <EOL> else : <EOL> raise ValueError ( file + "<STR_LIT>" ) <EOL> ret = name . format ( version = version , type = file , <EOL> extension = doctypename [ file ] , wintype = winos [ file ] ) <EOL> return ret <EOL> tarball_name_types = { <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:source>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:win32>' , <EOL> '<STR_LIT:html>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> } <EOL> def tarball_formatter ( ) : <EOL> return { name : get_tarball_name ( name ) for name in tarball_name_types } <EOL> @ task <EOL> def get_previous_version_tag ( ) : <EOL> """<STR_LIT>""" <EOL> shortversion = get_sympy_short_version ( ) <EOL> curcommit = "<STR_LIT>" <EOL> with cd ( "<STR_LIT>" ) : <EOL> while True : <EOL> curtag = run ( "<STR_LIT>" + <EOL> curcommit ) . strip ( ) <EOL> if shortversion in curtag : <EOL> parents = local ( "<STR_LIT>" + curtag , <EOL> capture = True ) . strip ( ) . split ( ) <EOL> assert len ( parents ) == <NUM_LIT:2> , curtag <EOL> curcommit = curtag + "<STR_LIT>" <EOL> else : <EOL> print ( blue ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( tag = curtag ) , bold = True ) ) <EOL> return curtag <EOL> error ( "<STR_LIT>" ) <EOL> @ task <EOL> def get_authors ( ) : <EOL> """<STR_LIT>""" <EOL> def lastnamekey ( name ) : <EOL> """<STR_LIT>""" <EOL> text = unicode ( name . strip ( ) . split ( ) [ - <NUM_LIT:1> ] , encoding = '<STR_LIT:utf-8>' ) . lower ( ) <EOL> return unicodedata . normalize ( '<STR_LIT>' , text ) . encode ( '<STR_LIT:ascii>' , '<STR_LIT:ignore>' ) <EOL> old_release_tag = get_previous_version_tag ( ) <EOL> with cd ( "<STR_LIT>" ) , hide ( '<STR_LIT>' ) : <EOL> releaseauthors = set ( run ( '<STR_LIT>' . format ( tag = old_release_tag ) ) . strip ( ) . split ( '<STR_LIT:\n>' ) ) <EOL> priorauthors = set ( run ( '<STR_LIT>' . format ( tag = old_release_tag ) ) . strip ( ) . split ( '<STR_LIT:\n>' ) ) <EOL> releaseauthors = { name . strip ( ) for name in releaseauthors if name . strip ( ) } <EOL> priorauthors = { name . strip ( ) for name in priorauthors if name . strip ( ) } <EOL> newauthors = releaseauthors - priorauthors <EOL> starred_newauthors = { name + "<STR_LIT:*>" for name in newauthors } <EOL> authors = releaseauthors - newauthors | starred_newauthors <EOL> return ( sorted ( authors , key = lastnamekey ) , len ( releaseauthors ) , len ( newauthors ) ) <EOL> @ task <EOL> def print_authors ( ) : <EOL> """<STR_LIT>""" <EOL> authors , authorcount , newauthorcount = get_authors ( ) <EOL> print ( blue ( "<STR_LIT>" <EOL> "<STR_LIT>" , bold = True ) ) <EOL> print ( ) <EOL> print ( """<STR_LIT>""" . format ( authorcount = authorcount , newauthorcount = newauthorcount ) ) <EOL> for name in authors : <EOL> print ( "<STR_LIT>" + name ) <EOL> print ( ) <EOL> @ task <EOL> def check_tag_exists ( ) : <EOL> """<STR_LIT>""" <EOL> version = get_sympy_version ( ) <EOL> tag = '<STR_LIT>' + version <EOL> with cd ( "<STR_LIT>" ) : <EOL> all_tags = run ( "<STR_LIT>" ) <EOL> return tag in all_tags <EOL> @ task <EOL> def update_websites ( ) : <EOL> """<STR_LIT>""" <EOL> update_docs ( ) <EOL> update_sympy_org ( ) <EOL> def get_location ( location ) : <EOL> """<STR_LIT>""" <EOL> locations_file = os . path . expanduser ( '<STR_LIT>' ) <EOL> config = ConfigParser . SafeConfigParser ( ) <EOL> config . read ( locations_file ) <EOL> the_location = config . has_option ( "<STR_LIT>" , location ) and config . get ( "<STR_LIT>" , location ) <EOL> if not the_location : <EOL> the_location = raw_input ( "<STR_LIT>" . format ( location = location ) ) <EOL> if not config . has_section ( "<STR_LIT>" ) : <EOL> config . add_section ( "<STR_LIT>" ) <EOL> config . set ( "<STR_LIT>" , location , the_location ) <EOL> save = raw_input ( "<STR_LIT>" ) <EOL> if save . lower ( ) . strip ( ) in [ '<STR_LIT>' , '<STR_LIT:y>' , '<STR_LIT:yes>' ] : <EOL> print ( "<STR_LIT>" , locations_file ) <EOL> with open ( locations_file , '<STR_LIT:w>' ) as f : <EOL> config . write ( f ) <EOL> else : <EOL> print ( "<STR_LIT>" . format ( location = location ) ) <EOL> return os . path . abspath ( os . path . expanduser ( the_location ) ) <EOL> @ task <EOL> def update_docs ( docs_location = None ) : <EOL> """<STR_LIT>""" <EOL> docs_location = docs_location or get_location ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" , docs_location ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location ) ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location ) ) <EOL> current_version = get_sympy_version ( ) <EOL> previous_version = get_previous_version_tag ( ) . lstrip ( '<STR_LIT>' ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> previous_version = previous_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> previous_version = previous_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> release_dir = os . path . abspath ( os . path . expanduser ( os . path . join ( os . path . curdir , '<STR_LIT>' ) ) ) <EOL> docs_zip = os . path . abspath ( os . path . join ( release_dir , get_tarball_name ( '<STR_LIT:html>' ) ) ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> docs_zip = docs_zip ) ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> docs_zip_name = get_tarball_name ( "<STR_LIT>" ) , version = current_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> with open ( os . path . join ( docs_location , "<STR_LIT>" ) , '<STR_LIT:a>' ) as f : <EOL> f . write ( "<STR_LIT>" . format ( version = current_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location ) ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> version = current_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> version = current_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> version = current_version ) ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location , <EOL> version = current_version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( docs_location = docs_location ) ) <EOL> @ task <EOL> def update_sympy_org ( website_location = None ) : <EOL> """<STR_LIT>""" <EOL> website_location = website_location or get_location ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( website_location = website_location ) ) <EOL> local ( "<STR_LIT>" . format ( website_location = website_location ) ) <EOL> release_date = time . gmtime ( os . path . getctime ( os . path . join ( "<STR_LIT>" , <EOL> tarball_formatter ( ) [ '<STR_LIT:source>' ] ) ) ) <EOL> release_year = str ( release_date . tm_year ) <EOL> release_month = str ( release_date . tm_mon ) <EOL> release_day = str ( release_date . tm_mday ) <EOL> version = get_sympy_version ( ) <EOL> with open ( os . path . join ( website_location , "<STR_LIT>" , "<STR_LIT>" ) , '<STR_LIT:r>' ) as f : <EOL> lines = f . read ( ) . split ( '<STR_LIT:\n>' ) <EOL> try : <EOL> news = lines . index ( r"<STR_LIT>" ) <EOL> except ValueError : <EOL> error ( "<STR_LIT>" ) <EOL> lines . insert ( news + <NUM_LIT:2> , <EOL> r"""<STR_LIT>""" + release_year + """<STR_LIT:U+002CU+0020>""" + release_month + """<STR_LIT:U+002CU+0020>""" + release_day + """<STR_LIT>""" + version + """<STR_LIT>""" + version + """<STR_LIT>""" ) <EOL> with open ( os . path . join ( website_location , "<STR_LIT>" , "<STR_LIT>" ) , '<STR_LIT:w>' ) as f : <EOL> print ( "<STR_LIT>" ) <EOL> f . write ( '<STR_LIT:\n>' . join ( lines ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( website_location = website_location ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( website_location = website_location , <EOL> version = version ) ) <EOL> print ( "<STR_LIT>" ) <EOL> local ( "<STR_LIT>" . format ( website_location = website_location ) ) <EOL> @ task <EOL> def upload ( ) : <EOL> """<STR_LIT>""" <EOL> distutils_check ( ) <EOL> GitHub_release ( ) <EOL> pypi_register ( ) <EOL> pypi_upload ( ) <EOL> test_pypi ( <NUM_LIT:2> ) <EOL> test_pypi ( <NUM_LIT:3> ) <EOL> @ task <EOL> def distutils_check ( ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def pypi_register ( ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def pypi_upload ( ) : <EOL> """<STR_LIT>""" <EOL> with cd ( "<STR_LIT>" ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def test_pypi ( release = '<STR_LIT:2>' ) : <EOL> """<STR_LIT>""" <EOL> version = get_sympy_version ( ) <EOL> release = str ( release ) <EOL> if release not in { '<STR_LIT:2>' , '<STR_LIT:3>' } : <EOL> raise ValueError ( "<STR_LIT>" % release ) <EOL> venv = "<STR_LIT>" . format ( release = release ) <EOL> with use_venv ( release ) : <EOL> make_virtualenv ( venv ) <EOL> with virtualenv ( venv ) : <EOL> run ( "<STR_LIT>" ) <EOL> run ( '<STR_LIT>' . format ( version = version ) ) <EOL> @ task <EOL> def GitHub_release_text ( ) : <EOL> """<STR_LIT>""" <EOL> shortversion = get_sympy_short_version ( ) <EOL> htmltable = table ( ) <EOL> out = """<STR_LIT>""" <EOL> out = out . format ( shortversion = shortversion , htmltable = htmltable ) <EOL> print ( blue ( "<STR_LIT>" <EOL> "<STR_LIT>" , bold = True ) ) <EOL> print ( ) <EOL> print ( out ) <EOL> return out <EOL> @ task <EOL> def GitHub_release ( username = None , user = '<STR_LIT>' , token = None , <EOL> token_file_path = "<STR_LIT>" , repo = '<STR_LIT>' , draft = False ) : <EOL> """<STR_LIT>""" <EOL> if not requests : <EOL> error ( "<STR_LIT>" ) <EOL> release_text = GitHub_release_text ( ) <EOL> version = get_sympy_version ( ) <EOL> short_version = get_sympy_short_version ( ) <EOL> tag = '<STR_LIT>' + version <EOL> prerelease = short_version != version <EOL> urls = URLs ( user = user , repo = repo ) <EOL> if not username : <EOL> username = raw_input ( "<STR_LIT>" ) <EOL> token = load_token_file ( token_file_path ) <EOL> if not token : <EOL> username , password , token = GitHub_authenticate ( urls , username , token ) <EOL> if not check_tag_exists ( ) : <EOL> error ( "<STR_LIT>" ) <EOL> post = { } <EOL> post [ '<STR_LIT>' ] = tag <EOL> post [ '<STR_LIT:name>' ] = "<STR_LIT>" + version <EOL> post [ '<STR_LIT:body>' ] = release_text <EOL> post [ '<STR_LIT>' ] = draft <EOL> post [ '<STR_LIT>' ] = prerelease <EOL> print ( "<STR_LIT>" , tag , end = '<STR_LIT:U+0020>' ) <EOL> result = query_GitHub ( urls . releases_url , username , password = None , <EOL> token = token , data = json . dumps ( post ) ) . json ( ) <EOL> release_id = result [ '<STR_LIT:id>' ] <EOL> print ( green ( "<STR_LIT>" ) ) <EOL> for key in descriptions : <EOL> tarball = get_tarball_name ( key ) <EOL> params = { } <EOL> params [ '<STR_LIT:name>' ] = tarball <EOL> if tarball . endswith ( '<STR_LIT>' ) : <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> elif tarball . endswith ( '<STR_LIT>' ) : <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> elif tarball . endswith ( '<STR_LIT>' ) : <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> else : <EOL> headers = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } <EOL> print ( "<STR_LIT>" , tarball , end = '<STR_LIT:U+0020>' ) <EOL> sys . stdout . flush ( ) <EOL> with open ( os . path . join ( "<STR_LIT>" , tarball ) , '<STR_LIT:rb>' ) as f : <EOL> result = query_GitHub ( urls . release_uploads_url % release_id , username , <EOL> password = None , token = token , data = f , params = params , <EOL> headers = headers ) . json ( ) <EOL> print ( green ( "<STR_LIT>" ) ) <EOL> def GitHub_check_authentication ( urls , username , password , token ) : <EOL> """<STR_LIT>""" <EOL> query_GitHub ( urls . api_url , username , password , token ) <EOL> def GitHub_authenticate ( urls , username , token = None ) : <EOL> _login_message = """<STR_LIT>""" <EOL> if username : <EOL> print ( "<STR_LIT>" % username ) <EOL> else : <EOL> print ( _login_message ) <EOL> username = raw_input ( "<STR_LIT>" ) <EOL> authenticated = False <EOL> if token : <EOL> print ( "<STR_LIT>" ) <EOL> try : <EOL> GitHub_check_authentication ( urls , username , None , token ) <EOL> except AuthenticationFailed : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> password = None <EOL> authenticated = True <EOL> while not authenticated : <EOL> password = getpass ( "<STR_LIT>" ) <EOL> try : <EOL> print ( "<STR_LIT>" ) <EOL> GitHub_check_authentication ( urls , username , password , None ) <EOL> except AuthenticationFailed : <EOL> print ( "<STR_LIT>" ) <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> authenticated = True <EOL> if password : <EOL> generate = raw_input ( "<STR_LIT>" ) <EOL> if generate . lower ( ) in [ "<STR_LIT:y>" , "<STR_LIT>" , "<STR_LIT:yes>" , "<STR_LIT>" ] : <EOL> name = raw_input ( "<STR_LIT>" ) <EOL> if name == "<STR_LIT>" : <EOL> name = "<STR_LIT>" <EOL> token = generate_token ( urls , username , password , name = name ) <EOL> print ( "<STR_LIT>" , token ) <EOL> print ( "<STR_LIT>" + token + <EOL> "<STR_LIT>" + username ) <EOL> print ( red ( "<STR_LIT>" ) ) <EOL> save = raw_input ( "<STR_LIT>" ) <EOL> if save . lower ( ) . strip ( ) in [ '<STR_LIT:y>' , '<STR_LIT:yes>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> save_token_file ( token ) <EOL> return username , password , token <EOL> def generate_token ( urls , username , password , OTP = None , name = "<STR_LIT>" ) : <EOL> enc_data = json . dumps ( <EOL> { <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : name <EOL> } <EOL> ) <EOL> url = urls . authorize_url <EOL> rep = query_GitHub ( url , username = username , password = password , <EOL> data = enc_data ) . json ( ) <EOL> return rep [ "<STR_LIT>" ] <EOL> def save_token_file ( token ) : <EOL> token_file = raw_input ( "<STR_LIT>" ) <EOL> token_file = token_file or "<STR_LIT>" <EOL> token_file_expand = os . path . expanduser ( token_file ) <EOL> token_file_expand = os . path . abspath ( token_file_expand ) <EOL> token_folder , _ = os . path . split ( token_file_expand ) <EOL> try : <EOL> if not os . path . isdir ( token_folder ) : <EOL> os . mkdir ( token_folder , <NUM_LIT> ) <EOL> with open ( token_file_expand , '<STR_LIT:w>' ) as f : <EOL> f . write ( token + '<STR_LIT:\n>' ) <EOL> os . chmod ( token_file_expand , stat . S_IREAD | stat . S_IWRITE ) <EOL> except OSError as e : <EOL> print ( "<STR_LIT>" , e ) <EOL> return <EOL> except IOError as e : <EOL> print ( "<STR_LIT>" , e ) <EOL> return <EOL> return token_file <EOL> def load_token_file ( path = "<STR_LIT>" ) : <EOL> print ( "<STR_LIT>" % path ) <EOL> path = os . path . expanduser ( path ) <EOL> path = os . path . abspath ( path ) <EOL> if os . path . isfile ( path ) : <EOL> try : <EOL> with open ( path ) as f : <EOL> token = f . readline ( ) <EOL> except IOError : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> else : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> return token . strip ( ) <EOL> class URLs ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , user = "<STR_LIT>" , repo = "<STR_LIT>" , <EOL> api_url = "<STR_LIT>" , <EOL> authorize_url = "<STR_LIT>" , <EOL> uploads_url = '<STR_LIT>' , <EOL> main_url = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> self . user = user <EOL> self . repo = repo <EOL> self . api_url = api_url <EOL> self . authorize_url = authorize_url <EOL> self . uploads_url = uploads_url <EOL> self . main_url = main_url <EOL> self . pull_list_url = api_url + "<STR_LIT>" + "<STR_LIT:/>" + user + "<STR_LIT:/>" + repo + "<STR_LIT>" <EOL> self . issue_list_url = api_url + "<STR_LIT>" + user + "<STR_LIT:/>" + repo + "<STR_LIT>" <EOL> self . releases_url = api_url + "<STR_LIT>" + user + "<STR_LIT:/>" + repo + "<STR_LIT>" <EOL> self . single_issue_template = self . issue_list_url + "<STR_LIT>" <EOL> self . single_pull_template = self . pull_list_url + "<STR_LIT>" <EOL> self . user_info_template = api_url + "<STR_LIT>" <EOL> self . user_repos_template = api_url + "<STR_LIT>" <EOL> self . issue_comment_template = ( api_url + "<STR_LIT>" + "<STR_LIT:/>" + user + "<STR_LIT:/>" + repo + "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> self . release_uploads_url = ( uploads_url + "<STR_LIT>" + user + "<STR_LIT:/>" + <EOL> repo + "<STR_LIT>" + "<STR_LIT>" ) <EOL> self . release_download_url = ( main_url + "<STR_LIT:/>" + user + "<STR_LIT:/>" + repo + <EOL> "<STR_LIT>" ) <EOL> class AuthenticationFailed ( Exception ) : <EOL> pass <EOL> def query_GitHub ( url , username = None , password = None , token = None , data = None , <EOL> OTP = None , headers = None , params = None , files = None ) : <EOL> """<STR_LIT>""" <EOL> headers = headers or { } <EOL> if OTP : <EOL> headers [ '<STR_LIT>' ] = OTP <EOL> if token : <EOL> auth = OAuth2 ( client_id = username , token = dict ( access_token = token , <EOL> token_type = '<STR_LIT>' ) ) <EOL> else : <EOL> auth = HTTPBasicAuth ( username , password ) <EOL> if data : <EOL> r = requests . post ( url , auth = auth , data = data , headers = headers , <EOL> params = params , files = files ) <EOL> else : <EOL> r = requests . get ( url , auth = auth , headers = headers , params = params , stream = True ) <EOL> if r . status_code == <NUM_LIT> : <EOL> two_factor = r . headers . get ( '<STR_LIT>' ) <EOL> if two_factor : <EOL> print ( "<STR_LIT>" , two_factor . split ( '<STR_LIT:;>' ) [ <NUM_LIT:1> ] . strip ( ) ) <EOL> OTP = raw_input ( "<STR_LIT>" ) <EOL> return query_GitHub ( url , username = username , password = password , <EOL> token = token , data = data , OTP = OTP ) <EOL> raise AuthenticationFailed ( "<STR_LIT>" ) <EOL> r . raise_for_status ( ) <EOL> return r <EOL> @ task <EOL> def vagrant ( ) : <EOL> """<STR_LIT>""" <EOL> vc = get_vagrant_config ( ) <EOL> env . user = vc [ '<STR_LIT>' ] <EOL> env . hosts = [ '<STR_LIT>' % ( vc [ '<STR_LIT>' ] , vc [ '<STR_LIT>' ] ) ] <EOL> env . key_filename = vc [ '<STR_LIT>' ] . strip ( '<STR_LIT:">' ) <EOL> env . forward_agent = vc . get ( '<STR_LIT>' , '<STR_LIT>' ) == '<STR_LIT:yes>' <EOL> def get_vagrant_config ( ) : <EOL> """<STR_LIT>""" <EOL> result = local ( '<STR_LIT>' , capture = True ) <EOL> conf = { } <EOL> for line in iter ( result . splitlines ( ) ) : <EOL> parts = line . split ( ) <EOL> conf [ parts [ <NUM_LIT:0> ] ] = '<STR_LIT:U+0020>' . join ( parts [ <NUM_LIT:1> : ] ) <EOL> return conf <EOL> @ task <EOL> def restart_network ( ) : <EOL> """<STR_LIT>""" <EOL> run ( "<STR_LIT>" ) <EOL> @ task <EOL> def uname ( ) : <EOL> """<STR_LIT>""" <EOL> run ( '<STR_LIT>' ) </s>
