From 21b8708196a66d71fcd8cb2f9b35c13b46e4f69d Mon Sep 17 00:00:00 2001 From: Haibao Tang Date: Wed, 8 May 2024 05:54:38 -0700 Subject: [PATCH] remove set_usage() --- jcvi/apps/base.py | 10 +++++----- jcvi/apps/fetch.py | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jcvi/apps/base.py b/jcvi/apps/base.py index f7079dc3..b69946d7 100644 --- a/jcvi/apps/base.py +++ b/jcvi/apps/base.py @@ -12,6 +12,7 @@ import sys import time +from argparse import ArgumentParser, SUPPRESS from collections.abc import Iterable from configparser import ( ConfigParser, @@ -20,14 +21,13 @@ NoSectionError, ParsingError, ) - -from argparse import ArgumentParser, SUPPRESS from http.client import HTTPSConnection from socket import gethostname from subprocess import CalledProcessError, PIPE, call, check_output from time import ctime from typing import Any, Collection, List, Optional, Tuple, Union from urllib.parse import urlencode + from natsort import natsorted from rich.console import Console from rich.logging import RichHandler @@ -277,7 +277,7 @@ def set_outfile(self, outfile: Optional[str] = "stdout"): """ self.add_argument("-o", "--outfile", default=outfile, help="Outfile name") - def set_outdir(self, outdir="."): + def set_outdir(self, outdir: Optional[str] = "."): self.add_argument("--outdir", default=outdir, help="Specify output directory") def set_email(self): @@ -735,7 +735,7 @@ def set_pairs(self): part, e.g. /1, /2, or .f, .r, default behavior is to truncate until last char. """ - self.set_usage(self.set_pairs.__doc__) + self.usage = self.set_pairs.__doc__ self.add_argument( "--pairsfile", default=None, help="Write valid pairs to pairsfile" @@ -2225,7 +2225,7 @@ def inspect(object): print("{}: {}".format(k, details), file=sys.stderr) -def sample_N(a: Collection[Any], N: int, seed: Optional[int] = None) -> List[Any]: +def sample_N(a: Collection, N: int, seed: Optional[int] = None) -> List: """ When size of N is > size of a, random.sample() will emit an error: ValueError: sample larger than population diff --git a/jcvi/apps/fetch.py b/jcvi/apps/fetch.py index 41b18037..3ce134ca 100644 --- a/jcvi/apps/fetch.py +++ b/jcvi/apps/fetch.py @@ -158,7 +158,7 @@ def ensembl(args): valid_species = [x for x in ls_ftp(fasta_url) if "." not in x] doc = "\n".join((ensembl.__doc__, tile(valid_species))) - p.set_usage(doc) + p.usage = doc if len(args) != 1: sys.exit(not p.print_help()) @@ -273,7 +273,7 @@ def phytozome(args): downloader=downloader, ) g = GlobusXMLParser(directory_listing) - except: + except Exception as _: logger.error("Error downloading directory listing ... cleaning up") cleanup(directory_listing, cookies) sys.exit(1) @@ -281,7 +281,7 @@ def phytozome(args): genomes = g.get_genomes() valid_species = genomes.keys() species_tile = tile(valid_species) - p.set_usage("\n".join((phytozome.__doc__, species_tile))) + p.usage = "\n".join((phytozome.__doc__, species_tile)) if len(args) != 1: sys.exit(not p.print_help()) @@ -383,7 +383,7 @@ def phytozome9(args): valid_species = [x for x in ls_ftp(url) if "." not in x] doc = "\n".join((phytozome9.__doc__, tile(valid_species))) - p.set_usage(doc) + p.usage = doc if len(args) != 1: sys.exit(not p.print_help())