diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 772aa85..a78886a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest"] - python-version: ["3.7", "3.8"] + python-version: ["3.10", "3.11", "3.12"] defaults: run: @@ -35,20 +35,26 @@ jobs: key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('conda/environment.yml') }} + - name: Set installer URL + id: set-installer-url + run: | + if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then + echo "installer-url=https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh" >> $GITHUB_ENV + fi - uses: conda-incubator/setup-miniconda@v2 with: + installer-url: ${{ env.installer-url }} python-version: ${{ matrix.python-version }} channels: conda-forge, bioconda, defaults channel-priority: true activate-environment: tallytrin environment-file: conda/environment.yml - miniforge-variant: Mambaforge - name: Show conda run: | conda info conda list mamba list - + - name: Install tallytrin run: pip install -e . - name: Lint with flake8 diff --git a/__init__.py b/__init__.py deleted file mode 100644 index 235cec9..0000000 --- a/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from omics.genomics.proj.sca.src.PathController import * \ No newline at end of file diff --git a/tallytrin/entry.py b/tallytrin/entry.py index 3e37b16..cea675c 100644 --- a/tallytrin/entry.py +++ b/tallytrin/entry.py @@ -12,7 +12,7 @@ tallytrin --help -To get help for a specify workflow, type:: +To get help for a specific workflow, type:: tallytrin --help ''' @@ -21,12 +21,12 @@ import sys import re import glob -import imp +import importlib.util import tallytrin -def printListInColumns(l, ncolumns): - '''output list *l* in *ncolumns*.''' +def print_list_in_columns(l, ncolumns): + '''Output list *l* in *ncolumns*.''' ll = len(l) if ll == 0: @@ -34,7 +34,7 @@ def printListInColumns(l, ncolumns): max_width = max([len(x) for x in l]) + 3 n = ll // ncolumns - if ll % 3 != 0: + if ll % ncolumns != 0: n += 1 # build columns @@ -60,7 +60,6 @@ def main(argv=None): argv = sys.argv # paths to look for pipelines: - #print(pipelines.__file__) path = os.path.abspath(os.path.dirname(tallytrin.__file__)) relpath = os.path.abspath("../src") @@ -73,7 +72,7 @@ def main(argv=None): print((globals()["__doc__"])) print("The list of available pipelines are:\n") print("{}\n".format( - printListInColumns( + print_list_in_columns( sorted([os.path.basename(x)[len("pipeline_"):-len(".py")] for x in pipelines]), 2))) return @@ -85,9 +84,21 @@ def main(argv=None): # remove 'tallytrin' from sys.argv del sys.argv[0] - (file, pathname, description) = imp.find_module(pipeline, paths) - - module = imp.load_module(pipeline, file, pathname, description) + spec = None + for path in paths: + try: + spec = importlib.util.spec_from_file_location(pipeline, os.path.join(path, f"{pipeline}.py")) + if spec is not None: + break + except FileNotFoundError: + continue + + if spec is None or spec.loader is None: + print(f"Error: pipeline '{command}' not found.") + sys.exit(1) + + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) module.main(sys.argv) diff --git a/tests/test_style.py b/tests/test_style.py index 0968da8..0bd86ca 100644 --- a/tests/test_style.py +++ b/tests/test_style.py @@ -1,78 +1,50 @@ -'''test_style -============= - -Purpose -------- - -Runs pep8 style tests - could be removed if you dont want to -conform to pep8 for this project? - -This script is best run within nosetests:: - - nosetests tests/test_style.py - -''' -import pep8 +import pycodestyle import glob import os -from nose.tools import ok_ # DIRECTORIES to examine EXPRESSIONS = ( ('FirstLevel', 'scpipelines/*.py'), ('SecondLevel', 'scpipelines/version.py')) -# Codes to ignore in the pep8 BaseReport -IGNORE = set(('E101', # indentation contains mixed spaces and tabs - 'E201', # whitespace after '(' - 'E202', # whitespace before ')' - 'E122', # continuation line missing indentation or outdented - 'E265', # block comment should start with '# ' - 'E501', # line too long (82 > 79 characters) - 'E502', # the backslash is redundant between brackets - 'E731', # do not assign a lambda expression, use a def - 'W191', - 'W291', - 'W293', - 'W391', - 'W503', # line break before binary operator - 'W601', - 'W602', - 'files', - 'directories', - 'physical lines', - 'logical lines',)) +# Codes to ignore in the pycodestyle BaseReport +IGNORE = { + 'E101', # indentation contains mixed spaces and tabs + 'E201', # whitespace after '(' + 'E202', # whitespace before ')' + 'E122', # continuation line missing indentation or outdented + 'E265', # block comment should start with '# ' + 'E501', # line too long (82 > 79 characters) + 'E502', # the backslash is redundant between brackets + 'E731', # do not assign a lambda expression, use a def + 'W191', + 'W291', + 'W293', + 'W391', + 'W503', # line break before binary operator + 'W601', + 'W602' +} def check_style(filename): - '''check style of filename. - ''' + '''check style of filename.''' - p = pep8.StyleGuide(quiet=True) - report = p.check_files([filename]) + style_guide = pycodestyle.StyleGuide(quiet=True, ignore=IGNORE) + report = style_guide.check_files([filename]) - # count errors/warning excluding - # those to ignore - take = [y for x, y - in list(report.counters.items()) if x not in IGNORE] - found = ['%s:%i' % (x, y) for x, y - in list(report.counters.items()) if x not in IGNORE] - total = sum(take) - ok_(total == 0, - 'pep8 style violations: %s' % ','.join(found)) + # count errors/warnings excluding those to ignore + assert report.total_errors == 0, f"Style violations in {filename}" def test_style(): - '''test style of scripts - ''' + '''test style of scripts''' for label, expression in EXPRESSIONS: - files = glob.glob(expression) files.sort() for f in files: if os.path.isdir(f): continue - check_style.description = os.path.abspath(f) - yield(check_style, os.path.abspath(f)) + yield check_style, os.path.abspath(f)