Skip to content

Commit

Permalink
Merge pull request #175 from sanogenetics/feature/lint-and-format-wit…
Browse files Browse the repository at this point in the history
…h-ruff

Lint and format with Ruff
  • Loading branch information
apriha authored May 6, 2024
2 parents 77407c0 + 90b5475 commit 83888db
Show file tree
Hide file tree
Showing 26 changed files with 632 additions and 1,141 deletions.
17 changes: 10 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,23 @@ jobs:
- name: Enable workflow based on preconditions
run: echo "Workflow enabled."

lint:
lint-format:
needs: [enable-workflow]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Black
- name: Install Ruff
run: |
pip install black
- name: Lint with Black
pip install ruff
- name: Lint with Ruff
run: |
black --check --diff .
ruff check
- name: Format with Ruff
run: |
ruff format --check
build-docs:
needs: [enable-workflow]
Expand All @@ -57,7 +60,7 @@ jobs:
sphinx-build -W --keep-going -T -E -D language=en docs docs/_build
test:
needs: [lint, build-docs]
needs: [lint-format, build-docs]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -117,7 +120,7 @@ jobs:
uses: codecov/codecov-action@v3

test-extras:
needs: [lint, build-docs]
needs: [lint-format, build-docs]
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ To set up ``snps`` for local development:
.. note:: After running the tests, a coverage report can be viewed by opening
``htmlcov/index.html`` in a browser.

6. Check code formatting::
6. Perform code linting and formatting::

$ pipenv run black --check --diff .
$ pipenv run ruff check --fix
$ pipenv run ruff format

7. Commit your changes and push your branch to GitHub::

Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pytest-cov = "*"
pytest-watch = "*"
sphinx = "*"
sphinx-rtd-theme = "*"
black = "*"
ruff = "*"
matplotlib = "*"

[packages]
Expand Down
1,066 changes: 516 additions & 550 deletions Pipfile.lock

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. image:: https://raw.githubusercontent.com/apriha/snps/master/docs/images/snps_banner.png

|ci| |codecov| |docs| |pypi| |python| |downloads| |black|
|ci| |codecov| |docs| |pypi| |python| |downloads| |ruff|

snps
====
Expand Down Expand Up @@ -269,6 +269,10 @@ Thanks to Mike Agostino, Padma Reddy, Kevin Arvai, `openSNP <https://opensnp.org
``snps`` incorporates code and concepts generated with the assistance of
`OpenAI's <https://openai.com>`_ `ChatGPT <https://chat.openai.com>`_ (GPT-3.5). ✨

License
-------
``snps`` is licensed under the `BSD 3-Clause License <https://github.com/apriha/snps/blob/master/LICENSE.txt>`_.

.. https://github.com/rtfd/readthedocs.org/blob/master/docs/badges.rst
.. |ci| image:: https://github.com/apriha/snps/actions/workflows/ci.yml/badge.svg?branch=master
:target: https://github.com/apriha/snps/actions/workflows/ci.yml
Expand All @@ -282,5 +286,6 @@ Thanks to Mike Agostino, Padma Reddy, Kevin Arvai, `openSNP <https://opensnp.org
:target: https://www.python.org
.. |downloads| image:: https://pepy.tech/badge/snps
:target: https://pepy.tech/project/snps
.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black
.. |ruff| image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff
3 changes: 1 addition & 2 deletions analysis/parse-opensnp-files/get_file.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
""" Get a file from the openSNP datadump for debugging. """
"""Get a file from the openSNP datadump for debugging."""

import os

from atomicwrites import atomic_write

from snps.resources import Resources
from snps.utils import create_dir

Expand Down
8 changes: 4 additions & 4 deletions analysis/parse-opensnp-files/parse_opensnp_files.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
""" Parse openSNP datadump files.
"""Parse openSNP datadump files.
Attempt to parse each file in the openSNP datadump. For files where SNPs were loaded,
save summary statistics to a dataframe and output as a CSV. For files where no SNPs were
loaded, save a message for each file indicating the issue and optionally extract these
files from the datadump for debugging.
"""

import logging
import os
import random

from atomicwrites import atomic_write
import pandas as pd

from atomicwrites import atomic_write
from snps import SNPs
from snps.resources import Resources
from snps.utils import Parallelizer, save_df_as_csv, create_dir, clean_str
from snps.utils import Parallelizer, clean_str, create_dir, save_df_as_csv

OUTPUT_DIR = "output"
EXTRACT_FILES = True
Expand Down
9 changes: 4 additions & 5 deletions analysis/xy-chrom-snp-ratios/xy-chrom-snp-ratios.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import os
import random

from atomicwrites import atomic_write
import numpy as np
from matplotlib import patches
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from atomicwrites import atomic_write
from matplotlib import patches
from snps import SNPs
from snps.resources import Resources
from snps.utils import Parallelizer, save_df_as_csv, create_dir
from snps.utils import Parallelizer, create_dir, save_df_as_csv

OUTPUT_DIR = "output"

Expand Down
4 changes: 2 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import os
import sys

import snps

# http://docs.readthedocs.io/en/latest/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
autodoc_mock_imports = [
"numpy",
Expand All @@ -31,8 +33,6 @@

sys.path.insert(0, os.path.abspath("../"))

import snps

# https://samnicholls.net/2016/06/15/how-to-sphinx-readthedocs/

# -- General configuration ------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta:__legacy__"
build-backend = "setuptools.build_meta:__legacy__"

# https://github.com/astral-sh/ruff/issues/465#issuecomment-1783684428
[tool.ruff.lint]
extend-select = ["I"]
85 changes: 22 additions & 63 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Copyright (c) 2016 The Python Packaging Authority (PyPA)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

"""A setuptools based setup module.
See:
Expand All @@ -6,73 +26,12 @@
"""

"""
Copyright (c) 2016 The Python Packaging Authority (PyPA)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

"""
BSD 3-Clause License
Copyright (c) 2019, Andrew Riha
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

# To use a consistent encoding
from codecs import open
from glob import glob
from os.path import abspath
from os.path import basename
from os.path import dirname
from os.path import join
from os.path import splitext
from os.path import abspath, basename, dirname, join, splitext

from setuptools import find_packages
from setuptools import setup
from setuptools import find_packages, setup

import versioneer

Expand Down
37 changes: 2 additions & 35 deletions src/snps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,10 @@
""" `snps`
"""`snps`
tools for reading, writing, merging, and remapping SNPs
"""

"""
BSD 3-Clause License
Copyright (c) 2019, Andrew Riha
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

from snps.snps import SNPs
from snps.snps import SNPs as SNPs

# set version string with Versioneer
from . import _version
Expand Down
2 changes: 1 addition & 1 deletion src/snps/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
"""Git implementation of _version.py."""

import errno
import functools
import os
import re
import subprocess
import sys
from typing import Any, Callable, Dict, List, Optional, Tuple
import functools


def get_keywords() -> Dict[str, str]:
Expand Down
Loading

0 comments on commit 83888db

Please sign in to comment.