Skip to content

Commit

Permalink
style: add ruff formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed May 20, 2024
1 parent 37c7dfe commit a12145b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.DS_Store
*.bak
*.egg
*.egg-info
Expand Down
14 changes: 7 additions & 7 deletions docs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def _format_time(timespan, precision=3):
"""Formats the timespan in a human readable form
>>> _format_time(0.35)
'350 ms'
Expand All @@ -26,31 +26,31 @@ def _format_time(timespan, precision=3):
if timespan >= 60.0:
# we have more than a minute, format that in a human readable form
# Idea from http://snipplr.com/view/5713/
parts = [("d", 60*60*24),("h", 60*60),("min", 60), ("s", 1)]
parts = [("d", 60 * 60 * 24), ("h", 60 * 60), ("min", 60), ("s", 1)]
time = []
leftover = timespan
for suffix, length in parts:
value = int(leftover / length)
if value > 0:
leftover = leftover % length
time.append(u'%s%s' % (str(value), suffix))
time.append("%s%s" % (str(value), suffix))
if leftover < 1:
break
return " ".join(time)

units = [u"s", u"ms", u"us", u"ns"] # the save value
units = ["s", "ms", "us", "ns"] # the save value
scaling = [1, 1e3, 1e6, 1e9]

if timespan > 0.0:
order = min(-int(math.floor(math.log10(timespan)) // 3), 3)
else:
order = 3
return u"%.*g %s" % (precision, timespan * scaling[order], units[order])
return "%.*g %s" % (precision, timespan * scaling[order], units[order])


def hex_to_base64url(s):
return urlsafe_b64encode(unhexlify(s)).decode("ascii")


def base64url_to_hex(s):
return hexlify(urlsafe_b64decode(s)).decode("ascii")

16 changes: 8 additions & 8 deletions misc/threading-tests/threading-verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@


def fetch_in_thread(sr, nsa):
"""fetch a sequence in a thread
"""
"""fetch a sequence in a thread"""

def fetch_seq(q, nsa):
pid, ppid = os.getpid(), os.getppid()
q.put((pid, ppid, sr[nsa]))

q = Queue()
p = Process(target=fetch_seq, args=(q, nsa))
p.start()
Expand All @@ -46,11 +44,13 @@ def fetch_seq(q, nsa):

assert pid != ppid, "sequence was not fetched from thread"
return pid, ppid, seq


def make_seqrepo(writeable):

def make_seqrepo(writeable):
sr = SeqRepo("/tmp/sr", writeable=True)
sr.store("SMELLASSWEET", [{"namespace": "en", "alias": "rose"}, {"namespace": "fr", "alias": "rose"}])
sr.store(
"SMELLASSWEET", [{"namespace": "en", "alias": "rose"}, {"namespace": "fr", "alias": "rose"}]
)

if writeable is False:
del sr
Expand All @@ -70,6 +70,6 @@ def _test(sr):
print("sys.platform: " + sys.platform)
print("sys.version: " + sys.version.replace("\n", " "))
print("sqlite3.sqlite_version: " + sqlite3.sqlite_version)

_test(make_seqrepo(writeable=False))
_test(make_seqrepo(writeable=True))
76 changes: 60 additions & 16 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ dependencies = [

[project.optional-dependencies]
dev = [
"bandit ~= 1.7",
"black ~= 22.3",
"build ~= 0.8",
"flake8 ~= 4.0",
"ipython ~= 8.4",
"isort ~= 5.10",
"mypy-extensions ~= 1.0",
"pre-commit ~= 3.4",
"pylint ~= 2.14",
"pytest-cov ~= 4.1",
"pytest-optional-tests",
"pytest ~= 7.1",
"pyright~=1.1",
"requests_html ~= 0.10",
"ruff ~= 0.4.4",
"tox ~= 3.25",
"vcrpy",
]
Expand Down Expand Up @@ -117,20 +113,68 @@ exclude_lines = [
"if __name__ == .__main__.:",
]

[tool.black]
line-length = 100

[tool.isort]
profile = "black"
src_paths = ["src", "tests"]

[tool.pyright]
include = ["src", "tests"]

[tool.ruff]
src = ["src", "test"]
line-length = 100

[tool.pylint.'MESSAGES CONTROL']
disable = "R0913"
[tool.ruff.lint]
select = [
"F",
"E",
"W",
"I",
"N",
"UP",
"YTT",
"S",
"B",
"A",
"C4",
"DTZ",
"EM",
"LOG",
"G",
"PIE",
"PT",
"RSE",
"RET",
"SIM",
"ARG",
"PTH",
"PL",
"TRY",
"PERF",
"FURB",
"RUF",
]
fixable = [
"F401",
"F541",
"I",
"D",
"UP",
"B",
"C4",
"EM",
"PIE",
"PT",
"RSE",
"RET",
"SIM",
"PERF",
"FURB",
"RUF",
]
ignore = [
# ignore for compatibility with formatter
"W191", "E111", "E114", "E117", "S321",
# other
"PLR0913",
]

[tool.ruff.lint.per-file-ignores]
"tests/*" = ["S101"]

[tool.pylint.format]
max-line-length = 100
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)
8 changes: 2 additions & 6 deletions src/biocommons/seqrepo/fastadir/fastadir.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def __init__(self, root_dir, writeable=False, check_same_thread=True, fd_cache_s
if schema_version != expected_schema_version:
raise RuntimeError(
"""Upgrade required: Database schema
version is {} and code expects {}""".format(
schema_version, expected_schema_version
)
version is {} and code expects {}""".format(schema_version, expected_schema_version)
)

if fd_cache_size == 0:
Expand Down Expand Up @@ -136,9 +134,7 @@ def fetch(self, seq_id, start=None, end=None):
if self._writing and self._writing["relpath"] == rec["relpath"]:
_logger.warning(
"""Fetching from file opened for writing;
closing first ({})""".format(
rec["relpath"]
)
closing first ({})""".format(rec["relpath"])
)
self.commit()

Expand Down
5 changes: 3 additions & 2 deletions src/biocommons/seqrepo/seqaliasdb/seqaliasdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ def __init__(
# if we're not at the expected schema version for this code, bail
if schema_version != expected_schema_version: # pragma: no cover
raise RuntimeError(
"Upgrade required: Database schema"
"version is {} and code expects {}".format(schema_version, expected_schema_version)
"Upgrade required: Database schema" "version is {} and code expects {}".format(
schema_version, expected_schema_version
)
)

# ############################################################################
Expand Down

0 comments on commit a12145b

Please sign in to comment.