diff options
Diffstat (limited to 'modules/cabal.py')
-rw-r--r-- | modules/cabal.py | 79 |
1 files changed, 72 insertions, 7 deletions
diff --git a/modules/cabal.py b/modules/cabal.py index 529b023..59c8d48 100644 --- a/modules/cabal.py +++ b/modules/cabal.py @@ -36,7 +36,17 @@ from modules.dirfactory import DirFactory from modules.sourceball import SourceBall class Cabal(Module): + '''A wrapper around common cabal operations + + This provides a useful api for other modules around the cabal build system + ''' def __init__(self, name, root='~/haskell'): + '''creates a new cabal module + + this api is deprecated, because it should be more autodetecting + + name is a Package (Directory) that uses cabal for its build system + ''' self.name = name self.root = expanduser(root) with pwd(self.root): @@ -45,18 +55,32 @@ class Cabal(Module): self.compiler = haskell_compiler def copy_in(self, tarball): + '''copies a tarball into the package + + tarball is a path to some tarball + ''' tarball = abspath(tarball) with pwd(self.root): self.package.add_sourceball(tarball) def darcs_get(self, url, tgt): + '''creates a darcs variant of a cabal package using darcs source + + url is a url to some darcs repo + tgt is the local name of the darcs repo + ''' self.package.checkout(tgt, url) def find_setup(self, orig=''): + '''returns the name of the Setup.?hs script for cabal. + ''' setup_re = compile("Setup\.l?hs") - return one(listdir(getcwd()), setup_re.search) + with pwd(self.package.dir): + return one(listdir(getcwd()), setup_re.search) def compile_setup(self, orig=''): + '''compiles the setup script for faster execution + ''' log.debug('dir is ' + self.package.dir) with pwd(self.package.dir): with log_file('ghc.log') as ghc_out: @@ -70,6 +94,14 @@ class Cabal(Module): p.communicate() def configure(self, target='home', orig=''): + '''runs the configure stage of cabal + + target is either 'home' or 'root' and will configure the package to + install either to the user's home directory, or to the system + wide haskell. + + Some help is needed making this more flexible + ''' user = True if target == 'home' else False self.compile_setup(orig) with pwd(self.package.dir): @@ -83,7 +115,12 @@ class Cabal(Module): p.wait() def build(self, orig=''): - '''This is not safe to run on an unconfigured source dir''' + '''runs the build stage of cabal + + This is not safe to run on an unconfigured source dir, because + this module does not track the state of cabal systems. The user + must do this on their own. + ''' self.compile_setup(orig) with pwd(self.package.dir): with log_file('cabal.log') as cabal_out: @@ -94,7 +131,12 @@ class Cabal(Module): p.wait() def install(self, orig=''): - '''This is not safe to run on an unconfigured source dir''' + '''runs the install stage of cabal + + This is not safe to run on an unconfigured source dir, because + this module does not track the state of cabal systems. The user + must do this on their own. + ''' self.compile_setup(orig) with pwd(self.package.dir): with log_file('cabal.log') as cabal_out: @@ -105,40 +147,62 @@ class Cabal(Module): p.wait() def install_tag(self, tag): + '''assuming a package that supports tagging, install a specific tag + + tag is the name of the tag in the DVCS + ''' with pwd(self.package.dir): with self.package.tag(tag): self.install() def install_source(self, target='home', orig=''): + '''perform configure, build, and install steps in one + ''' self.configure(target, orig) self.build(orig) self.install(orig) def install_sourceball(self, tarball, target='home'): + '''given a tarball, copy it in and install it + ''' self.copy_in(tarball) self.install_source(target, '') def get_from_hackage(self, pkg, ver): + '''get a specific package from hackage + + pkg is the name of the package desired + ver is the version wanted + ''' sb_file = self.hackage_url(pkg, ver) self.copy_in(sb_file) def get_latest(self, pkg): + '''get the latest version of a package from hackage + + pkg is the package desired + ''' ver = self.latest_version(pkg) self.get_from_hackage(pkg, ver) def install_from_hackage(self, pkg, ver, target='home'): + '''get and install a specific package from hackage + + pkg is the desired package + ver is the version wanted + target is the location to install to, either 'home' or 'root' + ''' self.get_from_hackage(pkg, ver) self.install_source(target, '') def install_latest(self, pkg, target='home'): + '''get and install the latest version of a package from hackage''' self.get_latest(pkg) self.install_source(target, '') - def source_dir(self, *args): - with pwd(self.package.dir): - return abspath(self.package.cfg['source'] + (self.orig_src_dir if original else "")) - def latest_version(self, pkg): + '''download information from hackage to find out the latest version of a package + ''' hackage_title = compile(r'<title.*?>HackageDB: (.*)-(.*)</title.*?>', DOTALL) site = 'http://hackage.haskell.org/cgi-bin/hackage-scripts/package/' + pkg u = urlopen(site) @@ -152,6 +216,7 @@ class Cabal(Module): raise ExecutionException("package does not match package name, can't determine version, sorry") def hackage_url(self, pkg, ver): + '''returns the url for tarball for a hackage package''' return 'http://hackage.haskell.org/packages/archive/' + \ pkg + '/' + ver + '/' + pkg + '-' + ver + '.tar.gz' |