def release(): """Release/publish the code. """ # Rebase and push the master with tags to origin. print("Here are the remaining TODO items:") print(bash('TODO.sh')) print() if not util.yes( "Do you still want to rebase and push the master with tags " "to origin (y/n)?"): util.delayed_exit() git.rebase('-i', 'origin/master') git.push('--tags', 'origin', 'master') # Upload to PyPI. if not util.yes("Do you want to upload to PyPI (this is permanent!) " "(y/n)?"): util.delayed_exit() setup.sdist.upload() # Reset the version number. # In modelicares/__init__.py: set_version('None') # In CHANGES.txt: newheading = 'vx.x.x_ (YYYY-MM-DD) -- Updates:' newlink = ('.. _vx.x.x: ' 'https://github.com/kdavies4/ModelicaRes/archive/vx.x.x.zip') rpls = [(r'(<http://semver.org>`_\.)', r'\1\n\n' + newheading), (r'(Initial release\n\n\n)', r'\1%s\n' % newlink)] util.replace('CHANGES.txt', rpls)
def html(): """Build/make the HTML documentation. """ # Rebuild the static images. if util.yes("Do you want to rebuild the static images (y/n)?"): static() # Update the download link. try: commit = git('rev-list', '--tags', '--max-count=1').stdout.rstrip() lastversion = git.describe('--tags', commit).stdout.rstrip() # This is simpler but doesn't always return the latest tag: # lastversion = git.describe('--tag', abbrev=0).stdout.rstrip() except ErrorReturnCode_128: pass # No tags recorded; leave download link as is else: date = git.log('-1', lastversion, date='short', format='%ad').stdout[8:18] rpls = [ (r'(ModelicaRes)-.+(\.tar)', r'\1-%s\2' % lastversion[1:]), (r'(Latest version<br>\().+(\)</a>)', r'\1%s, %s\2' % (lastversion, date)), ] util.replace('_templates/download.html', rpls) # Build the documentation. make_dirs() sphinx = sphinx_build.bake(b='html', d='build/doctrees') print(sphinx('.', BUILD_DIR)) # Spellcheck. if util.yes("Do you want to spellcheck the HTML documentation (y/n)?"): spellcheck()
def build(): """Build/make the code. """ # Check that README.txt is a valid ReST file (otherwise, the PyPI page will # not show correctly). readme = 'README.txt' error_start = 'Docutils System Messages\n' with open(readme, 'r') as rstfile: parsed = publish_string(rstfile.read()) if error_start in parsed: print("Errors in " + readme) util.delayed_exit() # Run other setup tests. if setup.check('-rms').exit_code: print("The setup.py check failed.") util.delayed_exit() # Update the version number. commit = git('rev-list', '--tags', '--max-count=1').stdout.rstrip() lastversion = git.describe('--tags', commit).stdout.rstrip().lstrip('v') # This is simpler but doesn't always return the latest tag: # lastversion = git.describe('--tag', abbrev=0).stdout.rstrip() version = raw_input("Enter the version number (last was %s): " % lastversion) # In modelicares/__init__.py: set_version("'%s'" % version) # In CHANGES.txt: date = strftime('%Y-%-m-%-d') rpls = [(r'vx\.x\.x_ \(YYYY-MM-DD\)( -- Updates:)', r'v{v}_ ({d})\1'.format(v=version, d=date)), (r'v%s_ \(.+\)( -- Updates:)' % version, r'v{v}_ ({d})\1'.format(v=version, d=date)), (r'(.. _)vx\.x\.x(.+)vx\.x\.x(\.zip)', r'\1v{v}\2v{v}\3'.format(v=version))] util.replace('CHANGES.txt', rpls) # Build, install, and test the code. setup.build() os.system('sudo python setup.py install') os.system('sudo python3 setup.py install') print(bash('runtests.sh')) # Create a tarball and zip (*.tar.gz and *.zip). setup.sdist(formats='gztar,zip') # Tag the version (will prompt for message). git.tag('-af', 'v' + version)
def set_version(version, fname='modelicares/__init__.py'): """Update the version in a file. """ util.replace(fname, [('(__version__) *= *.+', r"\1 = %s" % version)])
def release(): """Release/publish the documentation to the webpage. """ # Save the current state. branch = git('rev-parse', '--abbrev-ref', 'HEAD').stdout.rstrip() git.stash('save', "Work in progress while updating gh-pages branch") # Check out the gh-pages branch. try: git.checkout('gh-pages') except ErrorReturnCode_128: # Create the branch if necessary. git.checkout('-b', 'gh-pages') # Remove the existing files in the base folder. extensions = ['*.html', '*.inv'] fnames = util.multiglob('..', extensions) for fname in fnames: os.remove(fname) # Copy the new files to the base folder. fnames = util.multiglob(BUILD_DIR, extensions) for fname in fnames: shutil.copy(fname, '..') # Track the new files. fnames = util.multiglob('..', extensions) git.add(*fnames) # Copy but rename the folders referenced in the HTML files. # Github only recognizes images, stylesheets, and javascripts as folders. folders = [ ('_images', 'images'), ('_static', 'javascripts'), ] for (src, dst) in folders: dst = os.path.join('..', dst) # Remove the existing folder. shutil.rmtree(dst, ignore_errors=True) # Copy the new folder. shutil.copytree(os.path.join(BUILD_DIR, src), dst) # Track the new folder. git.add(dst) # Update the HTML files to reference the new folder names. html_fnames = glob(os.path.join('..', '*.html')) util.replace(html_fnames, folders) # Copy and rename the examples folder. src = os.path.join(BUILD_DIR, 'examples') dst = '../examples2' # Remove the existing folder. shutil.rmtree(dst, ignore_errors=True) # Copy the new files. os.mkdir(dst) for fname in os.listdir(src): shutil.copy(os.path.join(src, fname), os.path.join(dst, fname)) # Track the new folder. git.add(dst) # Update the HTML files to reference the new folder names. util.replace(html_fnames, [(r'"\./examples/', r'"./examples2/')]) # Update the sitemap. print(python('sitemap_gen.py', config="sitemap_conf.xml")) # Commit the changes. try: git.commit('-a', m="Rebuilt documentation") except ErrorReturnCode_1: pass # No changes to commit # If desired, push the changes to origin. print("The gh-pages branch has been updated and is currently checked out.") if util.yes("Do you want to rebase it and push the changes to " "origin (y/n)?"): git.rebase('-i', 'origin/gh-pages') git.push.origin('gh-pages') # Return to the original state. git.checkout(branch) try: git.stash.pop() except ErrorReturnCode_1: pass # No stash was necessary in the first place. print("Now back on " + branch)