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

style: format with Ruff #740

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
52 changes: 21 additions & 31 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,27 @@ on:
pull_request:

jobs:
# codechecks:
# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3

# - name: Set up Python
# uses: actions/setup-python@v4
# with:
# python-version: "3.10"
# cache: "pip"
# cache-dependency-path: "**/setup.cfg"

# - name: Install dependencies
# run: |
# pip install -e .[dev]

# - name: Lint with flake8
# run: |
# # stop the build if there are Python syntax errors or undefined names
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
# flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

# - name: Format check with isort
# run: |
# isort --check src

# - name: Format check with black
# run: |
# black --check src
cqa:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: pip
cache-dependency-path: '**/pyproject.yaml'

- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install --use-deprecated=legacy-resolver -e .[dev]

- name: Format check with Ruff
run: |
ruff format --check .

test:
runs-on: ubuntu-latest
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff-format
args: [ --check ]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ tox:
.PHONY: reformat
reformat:
@if ! git diff --cached --exit-code >/dev/null; then echo "Repository not clean" 1>&2; exit 1; fi
black src tests
ruff format src tests
isort src tests
git commit -a -m "reformatted with black and isort"
git commit -a -m "reformatted with ruff and isort"

#=> docs -- make sphinx docs
.PHONY: docs
Expand Down
58 changes: 32 additions & 26 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,61 @@
try:
# get release from hgvs if available
import hgvs

release = str(hgvs.__version__)
except ModuleNotFoundError:
# else get release from first tag (raise exception if not available)
import subprocess

release = subprocess.check_output(["git", "describe", "--tags"]).decode().strip().split()[0]
version = re.sub(r"\.post\d+$", "", release)


project = u'HGVS'
authors = project + ' Contributors'
copyright = u'2021, ' + authors
project = "HGVS"
authors = project + " Contributors"
copyright = "2021, " + authors

extlinks = {'issue': ('https://github.com/biocommons/hgvs/issues/%s', 'issue '), }
extlinks = {
"issue": ("https://github.com/biocommons/hgvs/issues/%s", "issue "),
}

man_pages = [('index', project, project + u' Documentation', [project + u' Contributors'], 1)]
man_pages = [("index", project, project + " Documentation", [project + " Contributors"], 1)]

# even for local builds
html_theme = 'sphinx_rtd_theme'
html_theme = "sphinx_rtd_theme"

#
# Boilerplate

autodoc_default_flags = ['members', 'undoc-members', 'show-inheritance'] #, 'inherited-members']
autoclass_content = 'both'
exclude_patterns = ['build', 'static', 'templates', 'themes']
autodoc_default_flags = ["members", "undoc-members", "show-inheritance"] # , 'inherited-members']
autoclass_content = "both"
exclude_patterns = ["build", "static", "templates", "themes"]
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.coverage',
'sphinx.ext.extlinks',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx.ext.coverage",
"sphinx.ext.extlinks",
"sphinx.ext.intersphinx",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
]
html_favicon = 'static/favicon.ico'
html_logo = 'static/hgvs-logo.png'
html_static_path = ['static']
html_title = '{project} {release}'.format(project=project, release=release)
intersphinx_mapping = {'http://docs.python.org/': None, }
master_doc = 'index'
pygments_style = 'sphinx'
source_suffix = '.rst'
templates_path = ['templates']
html_favicon = "static/favicon.ico"
html_logo = "static/hgvs-logo.png"
html_static_path = ["static"]
html_title = "{project} {release}".format(project=project, release=release)
intersphinx_mapping = {
"http://docs.python.org/": None,
}
master_doc = "index"
pygments_style = "sphinx"
source_suffix = ".rst"
templates_path = ["templates"]


# rst_epilog is appended to all rst files
# it's a good place to define global aliases
# If ends in .rst, sphinx will append it to itself :-(
rst_epilog_fn = os.path.join(os.path.dirname(__file__), 'rst_epilog')
rst_epilog_fn = os.path.join(os.path.dirname(__file__), "rst_epilog")
rst_epilog = open(rst_epilog_fn).read()

# <LICENSE>
Expand Down
16 changes: 8 additions & 8 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Highlights
close to it).

* Abide by current `code style`_. Use ``make reformat`` to reformat all
code with `yapf`_ prior to submitting a PR.
code with `ruff`_ prior to submitting a PR.

* Email the `hgvs-discuss`_ mailing list if you have questions.

Expand Down Expand Up @@ -158,11 +158,11 @@ setting UTA_DB_URL. The format is
``postgresql://<user>:<pass>@<host>/<db>/<schema>``. For example:

``postgresql://anonymous:[email protected]/uta/uta_20140210``
explicitly selects the public database, and

explicitly selects the public database, and

``postgresql://localhost/uta/uta_20140210``

selects a local instance. Developers can test connectivity like this:

``$ UTA_DB_URL=postgresql://localhost/uta/uta_20140210 make test-quick``
Expand Down Expand Up @@ -215,7 +215,7 @@ changes::
spaces_before_comment = 4
split_before_named_assigns = True

These code conventions are uniformly enforce by yapf_. The entire code
These code conventions are uniformly enforce by ruff_. The entire code
base is periodically automatically reformatted for consistency.


Expand All @@ -232,13 +232,13 @@ understand the code.
variable names. |eg| ``var_c`` in a function argument list signifies
that a SequenceVariant object with type='c' is expected.

:hgvs*: a string representing an HGVS variant name.
:hgvs*: a string representing an HGVS variant name.

:var*: a :class:`hgvs.variant.SequenceVariant` object

:pos:
:pos:

:posedit:
:posedit:

:hgvs_position:

Expand Down
2 changes: 1 addition & 1 deletion docs/rst_epilog
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.. _peg: http://en.wikipedia.org/wiki/Parsing_expression_grammar
.. _pep8: https://www.python.org/dev/peps/pep-0008/
.. _uta: https://github.com/biocommons/uta/
.. _yapf: https://github.com/google/yapf
.. _ruff: https://docs.astral.sh/ruff/


.. |eg| replace:: *e.g.,*
Expand Down
11 changes: 6 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@ exclude_lines = [
"if __name__ == .__main__.:",
]

[tool.black]
line-length = 100


# [tool.flake8]
# flake8 does not support configuration in pyproject.toml
# https://github.com/PyCQA/flake8/issues/234#issuecomment-812800832
Expand All @@ -120,4 +116,9 @@ disable = "R0913"


[tool.pylint.format]
max-line-length = "120"
max-line-length = "100"


[tool.ruff]
src = ["src", "test"]
line-length = 100
14 changes: 8 additions & 6 deletions sbin/generate_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
grammar_file = os.path.join(hgvs_base_dir, "src/hgvs/_data/hgvs.pymeta")
generated_code_dir = os.path.join(hgvs_base_dir, "src/hgvs/generated")

grammar_hash = hashlib.md5(open(grammar_file, 'rb').read()).hexdigest()
grammar_hash = hashlib.md5(open(grammar_file, "rb").read()).hexdigest()
prefix_length = len(hgvs_base_dir) + 1 # extra to also remove slash

header_template = """# --------------------------------------------------
Expand All @@ -31,11 +31,13 @@
# Python version: {python_version}
# --------------------------------------------------
"""
header = header_template.format(generate_script=script_path[prefix_length:],
grammar_file=grammar_file[prefix_length:],
grammar_hash=grammar_hash,
parsley_version=parsley.__version__,
python_version=sys.version)
header = header_template.format(
generate_script=script_path[prefix_length:],
grammar_file=grammar_file[prefix_length:],
grammar_hash=grammar_hash,
parsley_version=parsley.__version__,
python_version=sys.version,
)

g = OMeta(open(grammar_file).read(), name="Grammar")
tree = g.parseGrammar("Grammar")
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ hgvs =

[options.extras_require]
dev =
black
flake8
ipython
isort
jupyter
pre-commit ~= 3.4
pytest >= 5.3
pytest-cov >= 2.8
pytest-recording
restview
ruff == 0.4.4
setuptools
sphinx
sphinx_rtd_theme
sphinxcontrib-fulltoc >= 1.1
tox
vcrpy
yapf


[aliases]
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from setuptools import setup

setup(use_scm_version=True)
1 change: 0 additions & 1 deletion src/hgvs/alignmentmapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
# g. ... 123 124 125 126 127 128 129 130 131 132 133 ...
#


from bioutils.coordinates import strand_int_to_pm
from six.moves import range

Expand Down
1 change: 1 addition & 0 deletions src/hgvs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import re
from configparser import ConfigParser, ExtendedInterpolation
from copy import copy

try:
from importlib.resources import files as resources_files
except ImportError:
Expand Down
4 changes: 1 addition & 3 deletions src/hgvs/dataproviders/interface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""Defines the abstract data provider interface

"""
"""Defines the abstract data provider interface"""

import abc
import os
Expand Down
4 changes: 1 addition & 3 deletions src/hgvs/dataproviders/seqfetcher.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""provides sequencing fetching from NCBI and Ensembl

"""
"""provides sequencing fetching from NCBI and Ensembl"""

import logging
import os
Expand Down
3 changes: 2 additions & 1 deletion src/hgvs/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
location).

"""

import abc

import attr
Expand Down Expand Up @@ -50,7 +51,7 @@ def _del_ins_lengths(self, ilen):
@property
@abc.abstractmethod
def type(self):
""" return the type of this Edit """
"""return the type of this Edit"""
pass


Expand Down
4 changes: 1 addition & 3 deletions src/hgvs/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""defined exceptions used by the hgvs package

"""
"""defined exceptions used by the hgvs package"""


class HGVSError(Exception):
Expand Down
1 change: 1 addition & 0 deletions src/hgvs/extras/babelfish.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""translate between HGVS and other formats"""

import os

from bioutils.assemblies import make_ac_name_map, make_name_ac_map
Expand Down
4 changes: 1 addition & 3 deletions src/hgvs/hgvsposition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
"""Represent partial HGVS tags that refer to a position without alleles

"""
"""Represent partial HGVS tags that refer to a position without alleles"""

import attr

Expand Down
4 changes: 2 additions & 2 deletions src/hgvs/normalizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
"""hgvs.normalizer
"""
"""hgvs.normalizer"""

import copy
import logging
Expand Down Expand Up @@ -444,6 +443,7 @@ def _normalize_alleles(self, var, boundary):

return base + start, base + stop, (ref, alt)


# <LICENSE>
# Copyright 2018 HGVS Contributors (https://github.com/biocommons/hgvs)
#
Expand Down
Loading
Loading