This repository has been archived by the owner on Nov 30, 2020. It is now read-only.
forked from hexylena/argparse2tool
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anton Khodak
committed
Jun 26, 2016
1 parent
3eb5ec5
commit c9d9f44
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# /usr/bin/python3 | ||
import imp | ||
import os | ||
import subprocess | ||
import sys | ||
|
||
import argparse as ap | ||
|
||
|
||
help_text = """ | ||
pypi2cwl generates a bunch of CWL command line tools out of scripts from a given PyPi package or GitHub repo | ||
Example: $ pypi2cwl PYPI_PACKAGE <options> | ||
""" | ||
parser = ap.ArgumentParser(description=help_text, | ||
formatter_class=ap.RawDescriptionHelpFormatter) | ||
parser.add_argument('repo', | ||
help='PyPi repository or direct Github link') | ||
parser.add_argument('-d', '--directory', | ||
help='Directory to store CWL tool descriptions') | ||
parser.add_argument('-go', '--generate_outputs', action='store_true', | ||
help='Form output section from args than contain `output` keyword in their names') | ||
parser.add_argument('--no-install', action='store_true', | ||
help="Uninstall package after tool generation ") | ||
|
||
args = parser.parse_args() | ||
|
||
repo = args.repo | ||
if len(repo.split('/')) > 1: | ||
# GitHub repo | ||
pass | ||
else: | ||
setuptools = imp.new_module('setuptools') | ||
sys.modules['setuptools'] = setuptools | ||
params = None | ||
|
||
# TODO: cover all setuptools functions | ||
|
||
def setup(*args, **kwargs): | ||
global params | ||
params = kwargs | ||
|
||
def find_packages(*args, **kwargs): | ||
return | ||
|
||
setuptools.setup = setup | ||
setuptools.find_packages = find_packages | ||
subprocess.call(['sudo','pip2', 'install', repo]) # TODO: check pip version | ||
""" | ||
TODO: Downloading repo from GitHub via API and unzipping | ||
""" | ||
DIR = "/home/anton/phylotoast-master" # has nothing to do with production version, just for the sake of quicker prototyping! | ||
sys.path.insert(0, DIR) | ||
os.chdir(DIR) | ||
# importing setup from the target repo and parsing scripts | ||
import setup | ||
if params['scripts']: | ||
for script in list(map(lambda script: script.split('/')[-1], params['scripts'])): | ||
command = [script, '--generate_cwl_tool'] | ||
if args.directory: | ||
command.extend(['-d', args.directory]) | ||
subprocess.call(command) |
c9d9f44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
This should probably go in a separate repository.
It would be better to just download the source tarball from PyPI, as not all projects use GitHub. There are options to
pip install
to do this.c9d9f44
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though
pypi2cwl
does not use the code ofargparse2cwl
, it just invokes it as any guest program, but generally it serves the same purpose, so I think it is a good idea to serve them together. Although if it is more reasonable to keep them separately - no problem)