Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
First prototype of pypi2cwl
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Khodak committed Jun 26, 2016
1 parent 3eb5ec5 commit c9d9f44
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
Empty file added pypi2cwl/__init__.py
Empty file.
61 changes: 61 additions & 0 deletions pypi2cwl/pypi2cwl.py
@@ -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)

2 comments on commit c9d9f44

@mr-c
Copy link
Member

@mr-c mr-c commented on c9d9f44 Jun 30, 2016

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.

@anton-khodak
Copy link
Collaborator

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 of argparse2cwl, 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)

Please sign in to comment.