From eb67f5174b67c22a5d6126fa7afdd7c149be210b Mon Sep 17 00:00:00 2001 From: Danny Colligan Date: Fri, 28 Oct 2016 11:26:52 -0400 Subject: [PATCH] Use newer ga4gh-* packages Also add codecov --- .travis.yml | 5 +- ga4gh_client/cli.py | 108 +++++++++++++------------------------------- requirements.txt | 4 +- setup.py | 60 ++++++++++++++++++++---- 4 files changed, 87 insertions(+), 90 deletions(-) diff --git a/.travis.yml b/.travis.yml index e40285f..a6c599d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,6 @@ cache: install: - pip install pip --upgrade - pip install setuptools - - pip install ga4gh-common # need ga4gh_common.setup for sdist - python setup.py sdist - pip install dist/ga4gh_client*.tar.gz # every installable in setup.py's entry_points should be tested here @@ -29,3 +28,7 @@ script: --cover-branches --cover-erase - make clean -C docs - make html -C docs + +after_success: +# run codecov + - bash <(curl -s https://codecov.io/bash) diff --git a/ga4gh_client/cli.py b/ga4gh_client/cli.py index e96a4fc..a5387c7 100644 --- a/ga4gh_client/cli.py +++ b/ga4gh_client/cli.py @@ -8,14 +8,14 @@ import json import logging import requests -import argparse -import operator import ga4gh_client import ga4gh_client.client as client import ga4gh_client.exceptions as exceptions import ga4gh_client.protocol as protocol +import ga4gh_common.cli as cli + ############### # Common @@ -25,52 +25,12 @@ AVRO_LONG_MAX = 2**31 - 1 -class SortedHelpFormatter(argparse.HelpFormatter): - """ - An argparse HelpFormatter that sorts the flags and subcommands - in alphabetical order - """ - def add_arguments(self, actions): - """ - Sort the flags alphabetically - """ - actions = sorted( - actions, key=operator.attrgetter('option_strings')) - super(SortedHelpFormatter, self).add_arguments(actions) - - def _iter_indented_subactions(self, action): - """ - Sort the subcommands alphabetically - """ - try: - get_subactions = action._get_subactions - except AttributeError: - pass - else: - self._indent() - if isinstance(action, argparse._SubParsersAction): - for subaction in sorted( - get_subactions(), key=lambda x: x.dest): - yield subaction - else: - for subaction in get_subactions(): - yield subaction - self._dedent() - - def addDisableUrllibWarningsArgument(parser): parser.add_argument( "--disable-urllib-warnings", default=False, action="store_true", help="Disable urllib3 warnings") -def createArgumentParser(description): - parser = argparse.ArgumentParser( - description=description, - formatter_class=SortedHelpFormatter) - return parser - - def addVersionArgument(parser): # TODO argparse strips newlines from version output versionString = ( @@ -81,12 +41,6 @@ def addVersionArgument(parser): "--version", version=versionString, action="version") -def addSubparser(subparsers, subcommand, description): - parser = subparsers.add_parser( - subcommand, description=description, help=description) - return parser - - ############### # Client ############### @@ -1262,7 +1216,7 @@ def addHelpParser(subparsers): def addVariantsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "variants-search", "Search for variants") parser.set_defaults(runner=SearchVariantsRunner) addUrlArgument(parser) @@ -1272,7 +1226,7 @@ def addVariantsSearchParser(subparsers): def addVariantSetsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "variantsets-search", "Search for variantSets") parser.set_defaults(runner=SearchVariantSetsRunner) addOutputFormatArgument(parser) @@ -1308,42 +1262,42 @@ def addVariantAnnotationSetsSearchParser(subparsers): def addVariantAnnotationSetsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "variantannotationsets-get", "Get a variantAnnotationSet") parser.set_defaults(runner=GetVariantAnnotationSetRunner) addGetArguments(parser) def addVariantSetsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "variantsets-get", "Get a variantSet") parser.set_defaults(runner=GetVariantSetRunner) addGetArguments(parser) def addFeaturesGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "features-get", "Get a feature by ID") parser.set_defaults(runner=GetFeatureRunner) addGetArguments(parser) def addFeatureSetsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "featuresets-get", "Get a featureSet by ID") parser.set_defaults(runner=GetFeatureSetRunner) addGetArguments(parser) def addBioSamplesGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "biosamples-get", "Get a biosample by ID") parser.set_defaults(runner=GetBioSampleRunner) addGetArguments(parser) def addIndividualsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "individuals-get", "Get a individual by ID") parser.set_defaults(runner=GetIndividualRunner) addGetArguments(parser) @@ -1405,7 +1359,7 @@ def addFeatureSetsSearchParser(subparsers): def addReferenceSetsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "referencesets-search", "Search for referenceSets") parser.set_defaults(runner=SearchReferenceSetsRunner) addUrlArgument(parser) @@ -1420,7 +1374,7 @@ def addReferenceSetsSearchParser(subparsers): def addReferencesSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "references-search", "Search for references") parser.set_defaults(runner=SearchReferencesRunner) addUrlArgument(parser) @@ -1433,7 +1387,7 @@ def addReferencesSearchParser(subparsers): def addReadGroupSetsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "readgroupsets-search", "Search for readGroupSets") parser.set_defaults(runner=SearchReadGroupSetsRunner) addUrlArgument(parser) @@ -1446,7 +1400,7 @@ def addReadGroupSetsSearchParser(subparsers): def addCallSetsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "callsets-search", "Search for callSets") parser.set_defaults(runner=SearchCallSetsRunner) addUrlArgument(parser) @@ -1459,7 +1413,7 @@ def addCallSetsSearchParser(subparsers): def addReadsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "reads-search", "Search for reads") parser.set_defaults(runner=SearchReadsRunner) addOutputFormatArgument(parser) @@ -1468,14 +1422,14 @@ def addReadsSearchParser(subparsers): def addDatasetsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "datasets-get", "Get a dataset") parser.set_defaults(runner=GetDatasetRunner) addGetArguments(parser) def addDatasetsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "datasets-search", "Search for datasets") parser.set_defaults(runner=SearchDatasetsRunner) addUrlArgument(parser) @@ -1498,49 +1452,49 @@ def addReadsSearchParserArguments(parser): def addReferenceSetsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "referencesets-get", "Get a referenceset") parser.set_defaults(runner=GetReferenceSetRunner) addGetArguments(parser) def addReferencesGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "references-get", "Get a reference") parser.set_defaults(runner=GetReferenceRunner) addGetArguments(parser) def addReadGroupSetsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "readgroupsets-get", "Get a read group set") parser.set_defaults(runner=GetReadGroupSetRunner) addGetArguments(parser) def addReadGroupsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "readgroups-get", "Get a read group") parser.set_defaults(runner=GetReadGroupRunner) addGetArguments(parser) def addCallSetsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "callsets-get", "Get a callSet") parser.set_defaults(runner=GetCallSetRunner) addGetArguments(parser) def addVariantsGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "variants-get", "Get a variant") parser.set_defaults(runner=GetVariantRunner) addGetArguments(parser) def addRnaQuantificationSetGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "rnaquantificationsets-get", "Get a rna quantification set") parser.set_defaults(runner=GetRnaQuantificationSetRunner) @@ -1548,21 +1502,21 @@ def addRnaQuantificationSetGetParser(subparsers): def addRnaQuantificationGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "rnaquantifications-get", "Get a rna quantification") parser.set_defaults(runner=GetRnaQuantificationRunner) addGetArguments(parser) def addExpressionLevelGetParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "expressionlevels-get", "Get a expression level") parser.set_defaults(runner=GetExpressionLevelRunner) addGetArguments(parser) def addReferencesBasesListParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "references-list-bases", "List bases of a reference") parser.add_argument( "--outputFormat", "-O", choices=['text', 'fasta'], default="text", @@ -1625,7 +1579,7 @@ def addExpressionLevelsSearchParser(subparsers): def addGenotypePhenotypeSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "genotypephenotype-search", "Search for genotype to phenotype associations") parser.set_defaults(runner=SearchGenotypePhenotypeRunner) @@ -1637,7 +1591,7 @@ def addGenotypePhenotypeSearchParser(subparsers): def addPhenotypeSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "phenotype-search", "Search for phenotypes") parser.set_defaults(runner=SearchPhenotypeRunner) addUrlArgument(parser) @@ -1648,7 +1602,7 @@ def addPhenotypeSearchParser(subparsers): def addPhenotypeAssociationSetsSearchParser(subparsers): - parser = addSubparser( + parser = cli.addSubparser( subparsers, "phenotypeassociationsets-search", "Search for phenotypeassociationsets") parser.set_defaults(runner=SearchPhenotypeAssociationSetsRunner) @@ -1659,7 +1613,7 @@ def addPhenotypeAssociationSetsSearchParser(subparsers): def getClientParser(): - parser = createArgumentParser("GA4GH reference client") + parser = cli.createArgumentParser("GA4GH reference client") addClientGlobalOptions(parser) subparsers = parser.add_subparsers(title='subcommands',) addHelpParser(subparsers) diff --git a/requirements.txt b/requirements.txt index 172d860..1fe6185 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ # # These requirements are read directly into setup.py, so specify them # in the order that they should be in in setup.py -ga4gh_common -ga4gh_schemas +ga4gh_common==0.0.4 +ga4gh_schemas==0.0.7 requests protobuf==3.0.0b3 diff --git a/setup.py b/setup.py index 04ed837..093733d 100644 --- a/setup.py +++ b/setup.py @@ -1,17 +1,57 @@ # Don't import __future__ packages here; they make setup fail -import ga4gh_common.setup as setup +# First, we try to use setuptools. If it's not available locally, +# we fall back on ez_setup. +try: + from setuptools import setup +except ImportError: + from ez_setup import use_setuptools + use_setuptools() + from setuptools import setup -packageDict = { - "name": "ga4gh_client", - "description": "A client for the GA4GH reference server", - "packages": ["ga4gh_client"], - "url": "https://github.com/ga4gh/ga4gh-client", - "use_scm_version": {"write_to": "ga4gh_client/_version.py"}, - "entry_points": { +with open("README.pypi.rst") as readmeFile: + long_description = readmeFile.read() + +install_requires = [] +with open("requirements.txt") as requirementsFile: + for line in requirementsFile: + line = line.strip() + if len(line) == 0: + continue + if line[0] == '#': + continue + pinnedVersion = line.split()[0] + install_requires.append(pinnedVersion) + +setup( + # END BOILERPLATE + name="ga4gh_client", + description="A client for the GA4GH reference server", + packages=["ga4gh_client"], + url="https://github.com/ga4gh/ga4gh-client", + use_scm_version={"write_to": "ga4gh_client/_version.py"}, + entry_points={ 'console_scripts': [ 'ga4gh_client=ga4gh_client.cli:client_main', ] }, -} -setup.doSetup(packageDict) + # BEGIN BOILERPLATE + long_description=long_description, + install_requires=install_requires, + license='Apache License 2.0', + include_package_data=True, + zip_safe=True, + author="Global Alliance for Genomics and Health", + author_email="theglobalalliance@genomicsandhealth.org", + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Science/Research', + 'License :: OSI Approved :: Apache Software License', + 'Natural Language :: English', + 'Programming Language :: Python :: 2.7', + 'Topic :: Scientific/Engineering :: Bio-Informatics', + ], + keywords=['genomics', 'reference'], + # Use setuptools_scm to set the version number automatically from Git + setup_requires=['setuptools_scm'], +)