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

230 basic linting #231

Merged
merged 6 commits into from
Jun 18, 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
46 changes: 46 additions & 0 deletions .github/workflows/_run_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# reusable workflow to run tests on different installation types and OS
name: run-tests

on:
workflow_call:
inputs:
os:
required: true
type: string
python-version:
required: true
type: string
install-script:
required: true
type: string
test-script:
required: true
type: string
jobs:
run-unit-tests-stable-ubuntu:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
miniconda-version: "latest"
auto-update-conda: true
python-version: ${{ inputs.python-version }}
- name: Setup pip cache
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
- name: Conda info
shell: bash -l {0}
run: conda info
- name: Perform pip installation with all stable dependencies
shell: bash -l {0}
run: |
cd misc
. ./${{ inputs.install-script }}
- name: Run tests
shell: bash -l {0}
run: |
cd tests
. ./${{ inputs.test-script }}
26 changes: 26 additions & 0 deletions .github/workflows/branch-checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# checks to run on branches for each pull request
name: branch-checks

on:
pull_request:

jobs:
pre-commit:
name: Run all pre-commit hooks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
# For feature branches, we don't test the full matrix (os x [stable, loose]) in order to save time & resources.
run-tests-stable:
name: Test stable pip installation on ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest]
uses: ./.github/workflows/_run_tests.yml
with:
python-version: ${{ matrix.python-version }}
os: ${{ matrix.os }}
install-script: ./pip_install.sh stable,test
test-script: ./run_unit_tests.sh
94 changes: 34 additions & 60 deletions .github/workflows/pip_installation.yml
Original file line number Diff line number Diff line change
@@ -1,71 +1,45 @@
# Perform pip installation (stable, loose) and run tests on all three OS

# For feature branches, we don't test the full matrix (os x [stable, loose]) in order to save time & resources.
# On each push to develop, the whole test matrix runs, additionally, its success is mandatory for merging to main.
# In the (assumed to be rare case) that these full matrix tests fail but the reduced matrix tests passed,
# we will learn about it latest before pushing to main. The merge that caused the issue can then be identified
# from the tests that ran on develop.

on:
push:
branches: [ main, development ]
pull_request:
branches: [ main ]
workflow_dispatch:

name: Perform installation and run tests
name: Perform pip installation and run unit tests

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
cancel-in-progress: false

jobs:
stable_installation:
name: Test stable pip installation on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
run-unit-tests-stable:
name: Test stable pip installation on 3 OS
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
uses: ./.github/workflows/_run_tests.yml
with:
python-version: ${{ matrix.python-version }}
os: ${{ matrix.os }}
install-script: ./pip_install.sh stable,test
test-script: ./run_unit_tests.sh

run-unit-tests-loose:
name: Test loose pip installation on 3 OS
strategy:
matrix:
os: [ubuntu-latest, macos-13, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Setup pip cache
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
- name: Conda info
shell: bash -l {0}
run: conda info
- name: Test pip installation with all stable dependencies
shell: bash -l {0}
run: |
cd misc
. ./pip_install.sh stable,test
- name: Unittests
shell: bash -l {0}
run: |
cd tests
. ./run_unit_tests.sh
# loose_installation:
# name: Test loose pip installation on ${{ matrix.os }}
# runs-on: ${{ matrix.os }}
# strategy:
# matrix:
# os: [ubuntu-latest, macos-13, windows-latest]
# steps:
# - uses: actions/checkout@v4
# - name: Setup pip cache
# uses: actions/cache@v3
# with:
# path: ~/.cache/pip
# key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements*.txt') }}
# - uses: conda-incubator/setup-miniconda@v3
# with:
# auto-update-conda: true
# python-version: ${{ matrix.python-version }}
# - name: Conda info
# shell: bash -l {0}
# run: conda info
# - name: Test pip installation with all loose dependencies
# shell: bash -l {0}
# run: |
# cd misc
# . ./pip_install.sh loose,test
# - name: Unittests
# shell: bash -l {0}
# run: |
# cd tests
# . ./run_unit_tests.sh
os: [ ubuntu-latest, macos-13, windows-latest ]
uses: ./.github/workflows/_run_tests.yml
with:
python-version: ${{ matrix.python-version }}
os: ${{ matrix.os }}
install-script: ./pip_install.sh test
test-script: ./run_unit_tests.sh
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.0
rev: v0.4.9
hooks:
- id: ruff-format
#- id: ruff
8 changes: 4 additions & 4 deletions alphadia/grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def group_and_parsimony(
----------
precursor_idx : np.array[int]
Array containing unique integer indices corresponding to each peptide precursor
precursor_ids : np.array[str]
precursor_ids : np.array[str]
Array of variable length semicolon separated str belonging to a given peptide precursor id

Returns
Expand Down Expand Up @@ -91,7 +91,7 @@ def group_and_parsimony(
# check that all return_dict keys are unique. Assume same length and unique keys constitutes match to precursor_idx
if len(return_dict) != len(set(return_dict.keys())):
raise ValueError(
"""Not all precursors were found in the output of the grouping function.
"""Not all precursors were found in the output of the grouping function.
Duplicate precursors were found."""
)

Expand Down Expand Up @@ -125,7 +125,7 @@ def perform_grouping(

Returns
-------
pd.DataFrame :
pd.DataFrame :
Precursor table with grouped proteins

"""
Expand All @@ -144,7 +144,7 @@ def perform_grouping(
# TODO: consider removing check for duplicates since duplicate masking is implemented above
if upsm.duplicated(subset=["precursor_idx"]).any():
raise ValueError(
"""The same precursor was found annotated to different proteins.
"""The same precursor was found annotated to different proteins.
Please make sure all precursors were searched with the same library."""
)

Expand Down
4 changes: 3 additions & 1 deletion alphadia/outputaccumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ def parse_output_folder(

# ----------------- Fragment -----------------
# Filer fragments that are not used in the precursors
frag_df = frag_df[frag_df["precursor_idx"].isin(self._precursor_df["precursor_idx"])]
frag_df = frag_df[
frag_df["precursor_idx"].isin(self._precursor_df["precursor_idx"])
]
self._fragment_df = frag_df[
["mz", "intensity", "precursor_idx", "frag_idx", "correlation"]
].copy()
Expand Down
Loading