Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github actions for tests and pre-commit #1

Merged
merged 19 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/pre-commit-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

name: Pre-commit

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files
43 changes: 43 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install packagge
run: |
python -m pip install --upgrade pip pytest pytest-cov
python -m pip install -e .

- name: Create tasks needed for testing
run: |
python scripts/tasks_retrival/gene2gene_task_creation.py --allow-downloads True
python scripts/tasks_retrival/Genecorpus_tasks_creation.py --allow-downloads True
python scripts/tasks_retrival/HLA_task_creation.py --allow-downloads True
python scripts/tasks_retrival/HPA_tasks_creation.py --allow-downloads True
python scripts/tasks_retrival/humantfs_task_creation.py --allow-downloads True
python scripts/tasks_retrival/Reactome_tasks_creation.py --use-local-files False

- name: Test with pytest
run: |
python -m pytest -v --durations=40 --cov=gene_benchmark--cov-fail-under=70 gene_benchmark
48 changes: 11 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,3 @@
###################################
# GETTING STARTED WITH PRE-COMMIT #
###################################
# To start using this pre-commit file instapp pre-commit:
# pip install pre-commit
# Install hooks:
# pre-commit install
# Note: Multiple changes to the same file by a hook will block git commits.
# Therefore hooks should be added one at a time.
# Apply to all files without commiting:
# pre-commit run --all-files
# For more info, see https://pre-commit.com/

##########
# UPDATE #
##########
# Update this file (will change version numbers of tools, which could lead to
# simultaneous changes that require manual resolution):
# pre-commit autoupdate

#############
# CUSTOMIZE #
#############
# To customize per-hook behavior you can use:
# 1) the `args` option to pass cli args to the tool
# 2) per-tool config files such as mypy.ini, .pylintrc etc in repo root
# 3) the shared config file pyproject.toml in repo root

#############
# UNINSTALL #
#############
# pre-commit uninstall
repos:
# default hooks provided by the pre-commit project
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand All @@ -48,14 +16,20 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending

# mypy: type checking - caution this can be hard to satisfy also slow
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.910-1
# hooks:
# - id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.4
rev: v0.4.9
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
types_or: [ python, pyi, jupyter ]
# Run the formatter.
- id: ruff-format
types_or: [ python, pyi, jupyter ]
# black: automatic pep8 compliance code formatting
- repo: https://github.com/psf/black
rev: 24.4.2
hooks:
- id: black
16 changes: 4 additions & 12 deletions gene_benchmark/tests/test_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,9 @@ def test_sentenceTransformerEncoder_series(self):
encoder = SentenceTransformerEncoder(mpnet_name)
txt1 = "It was originally taken from a Latin text written by a Roman Scholar, Sceptic and Philosopher\
by the name of Marcus Tullius Cicero, who influenced the Latin language greatly."
txt2 = (
"The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
txt2 = "The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
Latin word. It is suggested that the reason that the text starts with Lorem is because there was a\
page break spanning the word"
)
txt3 = "Do-lorem. If you a re looking for a translation of the text, it's meaningless. The original text\
talks about the pain and love involved in the pursuit of pleasure or something like that."
txt4 = "The reason we use Lorem Ipsum is simple. If we used real text, it would possibly distract from\
Expand All @@ -255,11 +253,9 @@ def test_sentenceTransformerEncoder_series_with_none(self):
encoder = SentenceTransformerEncoder(mpnet_name)
txt1 = "It was originally taken from a Latin text written by a Roman Scholar, Sceptic and Philosopher\
by the name of Marcus Tullius Cicero, who influenced the Latin language greatly."
txt2 = (
"The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
txt2 = "The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
Latin word. It is suggested that the reason that the text starts with Lorem is because there was a\
page break spanning the word"
)
txt3 = "Do-lorem. If you a re looking for a translation of the text, it's meaningless. The original text\
talks about the pain and love involved in the pursuit of pleasure or something like that."
txt4 = "The reason we use Lorem Ipsum is simple. If we used real text, it would possibly distract from\
Expand All @@ -277,11 +273,9 @@ def test_entenceTransformerEncoder_df(self):
encoder = SentenceTransformerEncoder(mpnet_name)
txt1 = "It was originally taken from a Latin text written by a Roman Scholar, Sceptic and Philosopher\
by the name of Marcus Tullius Cicero, who influenced the Latin language greatly."
txt2 = (
"The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
txt2 = "The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
Latin word. It is suggested that the reason that the text starts with Lorem is because there was a\
page break spanning the word"
)
txt3 = "Do-lorem. If you a re looking for a translation of the text, it's meaningless. The original text\
talks about the pain and love involved in the pursuit of pleasure or something like that."
txt4 = "The reason we use Lorem Ipsum is simple. If we used real text, it would possibly distract from\
Expand All @@ -300,11 +294,9 @@ def test_sentenceTransformerEncoder_pdseries(self):
encoder = SentenceTransformerEncoder(mpnet_name)
txt1 = "It was originally taken from a Latin text written by a Roman Scholar, Sceptic and Philosopher\
by the name of Marcus Tullius Cicero, who influenced the Latin language greatly."
txt2 = (
"The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
txt2 = "The filler text we know today has been altered over the years (in fact Lorem isn't actually a\
Latin word. It is suggested that the reason that the text starts with Lorem is because there was a\
page break spanning the word"
)
txt3 = "Do-lorem. If you a re looking for a translation of the text, it's meaningless. The original text\
talks about the pain and love involved in the pursuit of pleasure or something like that."
txt4 = "The reason we use Lorem Ipsum is simple. If we used real text, it would possibly distract from\
Expand Down
2 changes: 1 addition & 1 deletion gene_benchmark/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def test_list_subtests(self):
def test_get_task_names(self):
tasks_folder = _get_tasks_folder()
names = list(get_tasks_definition_names(tasks_folder))
assert len(names) >= 81
assert len(names) >= 70
assert "RNA cancer distribution" in names
assert "bivalent vs non-methylated" in names

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies = [
"mygene",
"sentence_transformers",
"scikit-learn",
"click",
]

[project.optional-dependencies]
Expand Down
6 changes: 2 additions & 4 deletions scripts/tasks_retrival/HPA_tasks_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def save_task_to_dir(main_task_directory, task_name, entities, outcomes):
"--columns-to-use-yaml",
type=click.STRING,
help="A path to a yaml file containing the column names to be used as tasks",
default="scripts/hpa_column_names_for_tasks.yaml",
default="scripts/tasks_retrival/hpa_column_names_for_tasks.yaml",
)
@click.option(
"--main-task-directory",
Expand All @@ -110,9 +110,7 @@ def save_task_to_dir(main_task_directory, task_name, entities, outcomes):
default=False,
)
@click.option(
"--input-file",
type=click.STRING,
help="The path to the data file",
"--input-file", type=click.STRING, help="The path to the data file", default=None
)
def main(columns_to_use_yaml, main_task_directory, allow_downloads, input_file):
if allow_downloads:
Expand Down
Loading