Skip to content

Commit

Permalink
feat: add ci, versioning (#1)
Browse files Browse the repository at this point in the history
* feat: add version

* fix tests

* feat: add ci

* refactor: rewrite tests

* refactor: rewrite tests

* feat: add pylint config

* fix ci

* fix ci
  • Loading branch information
balajtimate authored Oct 10, 2023
1 parent 4247366 commit a468331
Show file tree
Hide file tree
Showing 30 changed files with 106 additions and 57 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
auto-activate-base: false

- name: Update scrnasim env with dev packages
run: mamba env update -n scrnasim -f environment.dev.yml
run: mamba env update -n scrnasim -f environment-dev.yml

- name: display environment info
run: |
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
auto-activate-base: false

- name: update scrnasim env with dev packages
run: mamba env update -n scrnasim -f environment.dev.yml
run: mamba env update -n scrnasim -f environment-dev.yml

- name: display environment info
run: |
Expand All @@ -85,4 +85,4 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
verbose: true
fail_ci_if_error: false
fail_ci_if_error: false
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ dependencies:
- pandas>=1.4.4
- pip>=20.2.3
- python>=3.6, <=3.10
- pyarrow
- pip:
- -e .
2 changes: 2 additions & 0 deletions pylint.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES CONTROL]
disable=C0103,E1101,I1101,R0801
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
argparse
biopython
biopython>=1.78
numpy>=1.23.3
pandas>=1.4.4
polars==0.16.17
gtfparse
setuptools
cli_test_helpers
6 changes: 5 additions & 1 deletion scRNAsim_toolz/cdna_generator/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Receive command line arguments."""

import argparse
import logging
from scRNAsim_toolz.version import __version__

logging.basicConfig(
format='[%(asctime)s: %(levelname)s] %(message)s \
Expand Down Expand Up @@ -41,6 +41,10 @@ def main():
parser.add_argument(
"-ocsv", "--output_csv", help="output fasta file", required=True
)
parser.add_argument(
'-v', '--version', action='version',
version=f'scRNAsim version: {__version__}'
)
args = parser.parse_args()

LOG.info("Running cDNA generator...")
Expand Down
6 changes: 5 additions & 1 deletion scRNAsim_toolz/fragment_selector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from Bio import SeqIO # type: ignore
import numpy as np # type: ignore
import pandas as pd # type: ignore

from scRNAsim_toolz.version import __version__

from .fragmentation import fragmentation
from .utils import check_positive
Expand Down Expand Up @@ -124,6 +124,10 @@ def parse_arguments() -> argparse.Namespace:
help="Chunk size for batch processing")
parser.add_argument('--sep', required=False, default=",",
help="Sequence counts file separator.")
parser.add_argument(
'-v', '--version', action='version',
version=f'scRNAsim version: {__version__}'
)
args = parser.parse_args()

return args
Expand Down
5 changes: 5 additions & 0 deletions scRNAsim_toolz/priming_site_predictor/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Receive command line arguments."""
import argparse
import logging
from scRNAsim_toolz.version import __version__
from .psp import CreatePrimer
from .psp import PrimingSitePredictor

Expand Down Expand Up @@ -65,6 +66,10 @@ def parse_args():
"-o", "--output-filename",
help="Path where the output gtf should be written"
)
parser.add_argument(
'-v', '--version', action='version',
version=f'scRNAsim version: {__version__}'
)
args = parser.parse_args()

return args
Expand Down
5 changes: 5 additions & 0 deletions scRNAsim_toolz/read_sequencer/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Receive command line arguments."""
import argparse
import logging
from scRNAsim_toolz.version import __version__
from .read_sequencer import ReadSequencer

logging.basicConfig(
Expand Down Expand Up @@ -52,6 +53,10 @@ def main():
type=int,
help="chunk_size for batch processing",
)
parser.add_argument(
'-v', '--version', action='version',
version=f'scRNAsim version: {__version__}'
)
args = parser.parse_args()
LOG.info("Read sequencer started.")
if args.input is not None:
Expand Down
6 changes: 5 additions & 1 deletion scRNAsim_toolz/sequence_extractor/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""CLI to be run on output fasta file from bedtools getfasta."""
import argparse
import logging
from scRNAsim_toolz.version import __version__
from .pre_bedtools import pre_bedtools_mode
from .exon_concat import exon_concatenation
from .poly_a import poly_a_addition_to_fasta_list
Expand Down Expand Up @@ -82,7 +83,10 @@ def parse_args():
dest="output_bed_file",
help="Bed file with only exons with strandedness"
"taken into account for 'pre_bedtools' mode.")

parser.add_argument(
'-v', '--version', action='version',
version=f'scRNAsim version: {__version__}'
)
args = parser.parse_args()
return args

Expand Down
7 changes: 5 additions & 2 deletions scRNAsim_toolz/structure_generator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import argparse
import logging
from pathlib import Path

from scRNAsim_toolz.version import __version__
from .main import sample_transcripts


Expand Down Expand Up @@ -76,7 +76,10 @@ def build_arg_parser() -> argparse.Namespace:
help='Level of logging. Can be one of \
["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG"]',
)

parser.add_argument(
'-v', '--version', action='version',
version=f'scRNAsim version: {__version__}'
)
args = parser.parse_args()

assert args.prob_inclusion >= 0
Expand Down
5 changes: 5 additions & 0 deletions scRNAsim_toolz/transcript_sampler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import time
import logging
from scRNAsim_toolz.version import __version__

logging.basicConfig(
format='[%(asctime)s: %(levelname)s] %(message)s \
Expand Down Expand Up @@ -45,6 +46,10 @@ def main():
"-n", "--n_to_sample", required=True, default=None,
help="Total number of transcripts to sample"
)
parser.add_argument(
'-v', '--version', action='version',
version=f'scRNAsim version: {__version__}'
)
args = parser.parse_args()

log = logging.getLogger("main")
Expand Down
2 changes: 2 additions & 0 deletions scRNAsim_toolz/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"""Version of scRNAsim_toolz."""
__version__ = "0.1.0"
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""scRNAsim package definition."""
from pathlib import Path
from setuptools import setup, find_packages # type: ignore
from scRNAsim_toolz.version import __version__

# Read long description from file
with open("README.md", "r", encoding="utf-8") as fh:
Expand All @@ -14,8 +15,8 @@
INSTALL_REQUIRES = fh.read().splitlines()

setup(
name="scrnasim",
version="0.1.0",
name="scrnasim_toolz",
version=__version__,
description=(
"Repository for the tools used by scRNAsim"
),
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Initialise tests."""
2 changes: 1 addition & 1 deletion tests/cdna_generator/test_cdna.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tests for cDNA functions."""
import pytest # type: ignore
from ...scRNAsim_toolz.cdna_generator.cdna import ( # type: ignore
from scRNAsim_toolz.cdna_generator.cdna import (
complement, seq_complement
)

Expand Down
15 changes: 8 additions & 7 deletions tests/fragment_selector/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"""Test cli.py functions."""
from pathlib import Path
import pytest # type: ignore

from ...scRNAsim_toolz.fragment_selector.cli import ( # type: ignore
from scRNAsim_toolz.fragment_selector.cli import (
file_validation, main
)

FASTA_FILE = "tests/test_files/test.fasta"
CSV_FILE = "tests/test_files/test.csv"
TAB_FILE = "tests/test_files/test_tab.csv"
TEST_FILES_DIR = Path(__file__).resolve().parent / "test_files"
FASTA_FILE = TEST_FILES_DIR / "test.fasta"
CSV_FILE = TEST_FILES_DIR / "test.csv"
TAB_FILE = TEST_FILES_DIR / "test_tab.csv"

_, csv_counts = file_validation(FASTA_FILE, CSV_FILE, ",")
_, tab_counts = file_validation(FASTA_FILE, TAB_FILE, "\t")
_, csv_counts = file_validation(str(FASTA_FILE), str(CSV_FILE), ",")
_, tab_counts = file_validation(str(FASTA_FILE), str(TAB_FILE), "\t")


def test_file():
Expand Down
9 changes: 5 additions & 4 deletions tests/fragment_selector/test_frag.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Test utils.py functions."""
from pathlib import Path
import pandas as pd # type: ignore
import pytest # type: ignore
from Bio import SeqIO # type: ignore

from ...scRNAsim_toolz.fragment_selector.fragmentation import ( # type: ignore
from scRNAsim_toolz.fragment_selector.fragmentation import (
fragmentation
)

FASTA_FILE = "tests/test_files/test.fasta"
CSV_FILE = "tests/test_files/test.csv"
TEST_FILES_DIR = Path(__file__).resolve().parent / "test_files"
FASTA_FILE = TEST_FILES_DIR / "test.fasta"
CSV_FILE = TEST_FILES_DIR / "test.csv"

fasta_dict = {}
with open(FASTA_FILE, "r", encoding="utf-8") as handle:
Expand Down
3 changes: 1 addition & 2 deletions tests/fragment_selector/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Test utils.py functions."""
import argparse
import pytest # type: ignore

from ...scRNAsim_toolz.fragment_selector.utils import ( # type: ignore
from scRNAsim_toolz.fragment_selector.utils import (
check_positive
)

Expand Down
4 changes: 2 additions & 2 deletions tests/priming_site_predictor/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Test functions for cli.py."""
import unittest
from unittest.mock import patch
from ...scRNAsim_toolz.priming_site_predictor import cli # type: ignore
from ...scRNAsim_toolz.priming_site_predictor.cli import ( # type: ignore
from scRNAsim_toolz.priming_site_predictor import cli
from scRNAsim_toolz.priming_site_predictor.cli import (
setup_logging
)

Expand Down
4 changes: 3 additions & 1 deletion tests/priming_site_predictor/test_psp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import unittest
from unittest.mock import patch, mock_open
from unittest import mock
import os
import math
import pandas as pd # type: ignore
import pytest # type: ignore
from ...scRNAsim_toolz.priming_site_predictor.psp import ( # type: ignore
from scRNAsim_toolz.priming_site_predictor.psp import (
CreatePrimer, PrimingSitePredictor
)

Expand Down Expand Up @@ -95,6 +96,7 @@ def test_generate_gtf(self):
print(expected_output)
# self.assertEqual(self.post_processor.generate_gtf(),
# expected_output)
os.remove("test_output.gtf")

def test_calculate_energy(self):
"""Test the calculate_energy() method."""
Expand Down
8 changes: 4 additions & 4 deletions tests/read_sequencer/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
"""Test cli.py."""
import pytest # type: ignore
from cli_test_helpers import ArgvContext, shell # type: ignore
from ...scRNAsim_toolz.read_sequencer import cli # type: ignore
from scRNAsim_toolz.read_sequencer import cli


def test_entrypoint():
"""Test if entrypoint script is installed (setup.py)."""
result = shell('readsequencer --help')
result = shell('read-sequencer --help')
assert result.exit_code == 0


def test_usage_no_args():
"""Test if CLI aborts w/o arguments, displaying usage instructions."""
with ArgvContext('readsequencer'), pytest.raises(SystemExit):
with ArgvContext('read-sequencer'), pytest.raises(SystemExit):
cli.main()

result = shell('readsequencer')
result = shell('read-sequencer')

assert 'usage:' in result.stderr
Loading

0 comments on commit a468331

Please sign in to comment.