Last active
January 2, 2016 09:39
-
-
Save nh2/8284831 to your computer and use it in GitHub Desktop.
Uploads haddocks to Hackage.Use it when Hackage can't build your documentation (e.g. missing libraries).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
""" | |
Uploads haddocks to Hackage. | |
Use it when Hackage can't build your documentation (e.g. missing libraries). | |
Inspired by: | |
http://fuuzetsu.co.uk/blog/posts/2014-01-06-Fix-your-Hackage-documentation.html | |
""" | |
import getpass | |
import glob | |
import os | |
import re | |
import sys | |
# Find package version | |
print "Finding package name and version" | |
cabalfile = glob.glob('*.cabal')[0] | |
package = cabalfile.rstrip('.cabal') | |
version = re.search(r'^version:\s*(\S+)', open(cabalfile).read(), re.MULTILINE | re.IGNORECASE).group(1) | |
raw_input("Using '%s-%s'. Confirm with Enter..." % (package, version)) | |
def run(cmd): | |
print cmd | |
c = os.system(cmd) | |
if c != 0: # fail early | |
sys.exit(c) | |
# Build haddocks | |
print "Building haddocks" | |
run('cabal haddock --hyperlink-source --html-location="http://hackage.haskell.org/package/$pkg/docs"') | |
# Go to doc directory | |
print 'cd dist/doc/html/'; os.chdir('dist/doc/html/') | |
# Tar the docs | |
run('rm -rf %s-%s-docs' % (package, version)) | |
run('mv %s %s-%s-docs' % (package, package, version)) | |
run('tar -c -v -z --format=ustar -f %s-%s-docs.tar.gz %s-%s-docs' % (package, version, package, version)) | |
# Upload the docs | |
print "\nReady to upload.\n" | |
username = raw_input('Hackage username: ') | |
pw = getpass.getpass('Hackage password: ') | |
# Don't use run() to not show the pw | |
print "curl -X PUT -H 'Content-Type: application/x-tar' -H 'Content-Encoding: gzip' --data-binary '@%s-%s-docs.tar.gz' 'http://%s:%[email protected]/package/%s-%s/docs'" % (package, version, username, '***', package, version) | |
os.system("curl -X PUT -H 'Content-Type: application/x-tar' -H 'Content-Encoding: gzip' --data-binary '@%s-%s-docs.tar.gz' 'http://%s:%[email protected]/package/%s-%s/docs'" % (package, version, username, pw, package, version)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment