Skip to content

Commit

Permalink
Merge branch 'maint/black-v23.11' into 'main'
Browse files Browse the repository at this point in the history
MAINT: Upgrade black to version 23.11 and run it on the codebase

See merge request heka/medkit!236

changelog: MAINT: Upgrade black to version 23.11 and run it on the codebase
  • Loading branch information
ghisvail committed Nov 23, 2023
2 parents f5119ac + 6f945e9 commit e639bd5
Show file tree
Hide file tree
Showing 26 changed files with 103 additions and 106 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: lint

on:
pull_request_target:
push:
branches:
- main
workflow_dispatch:

permissions:
Expand All @@ -15,4 +18,4 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- uses: pre-commit/action@v3.0.0
- uses: pre-commit/action@v3
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: check-yaml

- repo: https://github.com/psf/black-pre-commit-mirror
rev: '22.8.0'
rev: '23.11.0'
hooks:
- id: black

Expand Down
3 changes: 1 addition & 2 deletions medkit/audio/preprocessing/power_normalizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@


class PowerNormalizer(PreprocessingOperation):
"""Normalization operation setting the RMS power of each audio signal to a target value.
"""
"""Normalization operation setting the RMS power of each audio signal to a target value."""

def __init__(
self,
Expand Down
4 changes: 1 addition & 3 deletions medkit/io/spacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
To install them, use `pip install medkit-lib[spacy]`.
"""


__all__ = ["SpacyInputConverter", "SpacyOutputConverter"]

from typing import List, Optional
Expand All @@ -20,8 +19,7 @@


class SpacyInputConverter:
"""Class in charge of converting spacy documents into a collection of TextDocuments.
"""
"""Class in charge of converting spacy documents into a collection of TextDocuments."""

def __init__(
self,
Expand Down
16 changes: 9 additions & 7 deletions medkit/text/context/family_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,16 @@ def __init__(
for rule in self.rules
]
self._exclusion_patterns = [
re.compile(
"|".join(
f"(?:{r})" for r in rule.exclusion_regexps
), # join all exclusions in one pattern
flags=0 if rule.case_sensitive else re.IGNORECASE,
(
re.compile(
"|".join(
f"(?:{r})" for r in rule.exclusion_regexps
), # join all exclusions in one pattern
flags=0 if rule.case_sensitive else re.IGNORECASE,
)
if rule.exclusion_regexps
else None
)
if rule.exclusion_regexps
else None
for rule in self.rules
]
self._has_non_unicode_sensitive_rule = any(
Expand Down
16 changes: 9 additions & 7 deletions medkit/text/context/hypothesis_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,16 @@ def __init__(
for rule in self.rules
]
self._exclusion_patterns = [
re.compile(
"|".join(
f"(?:{r})" for r in rule.exclusion_regexps
), # join all exclusions in one pattern
flags=0 if rule.case_sensitive else re.IGNORECASE,
(
re.compile(
"|".join(
f"(?:{r})" for r in rule.exclusion_regexps
), # join all exclusions in one pattern
flags=0 if rule.case_sensitive else re.IGNORECASE,
)
if rule.exclusion_regexps
else None
)
if rule.exclusion_regexps
else None
for rule in self.rules
]
self._has_non_unicode_sensitive_rule = any(
Expand Down
16 changes: 9 additions & 7 deletions medkit/text/context/negation_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,16 @@ def __init__(
for rule in self.rules
]
self._exclusion_patterns = [
re.compile(
"|".join(
f"(?:{r})" for r in rule.exclusion_regexps
), # join all exclusions in one pattern
flags=0 if rule.case_sensitive else re.IGNORECASE,
(
re.compile(
"|".join(
f"(?:{r})" for r in rule.exclusion_regexps
), # join all exclusions in one pattern
flags=0 if rule.case_sensitive else re.IGNORECASE,
)
if rule.exclusion_regexps
else None
)
if rule.exclusion_regexps
else None
for rule in self.rules
]
self._has_non_unicode_sensitive_rule = any(
Expand Down
1 change: 1 addition & 0 deletions medkit/text/metrics/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module needs extra-dependencies not installed as core dependencies of medkit.
To install them, use `pip install medkit-lib[metrics-text-classification]`.
"""

__all__ = ["TextClassificationEvaluator"]
import logging
from typing import Dict, List, Union
Expand Down
1 change: 1 addition & 0 deletions medkit/text/metrics/irr_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Metrics to assess inter-annotator agreement"""

__all__ = ["krippendorff_alpha"]
from typing import List, Union
import numpy as np
Expand Down
1 change: 1 addition & 0 deletions medkit/text/ner/hf_entity_matcher_trainable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module needs extra-dependencies not installed as core dependencies of medkit.
To install them, use `pip install medkit-lib[hf-entity-matcher]`.
"""

__all__ = ["HFEntityMatcherTrainable"]
import logging
from pathlib import Path
Expand Down
11 changes: 7 additions & 4 deletions medkit/text/ner/regexp_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,14 @@ def __init__(
for rule in self.rules
]
self._exclusion_patterns = [
re.compile(
rule.exclusion_regexp, flags=0 if rule.case_sensitive else re.IGNORECASE
(
re.compile(
rule.exclusion_regexp,
flags=0 if rule.case_sensitive else re.IGNORECASE,
)
if rule.exclusion_regexp is not None
else None
)
if rule.exclusion_regexp is not None
else None
for rule in self.rules
]
self._has_non_unicode_sensitive_rule = any(
Expand Down
66 changes: 33 additions & 33 deletions medkit/text/preprocessing/char_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
#: Rules for ligatures
LIGATURE_RULES = [
("\u00c6", "AE"),
("\u00E6", "ae"),
("\u00e6", "ae"),
("\u0152", "OE"),
("\u0153", "oe"),
]
#: Rules for fraction characters
FRACTION_RULES = [
("\u00BC", "1/4"),
("\u00BD", "1/2"),
("\u00BE", "3/4"),
("\u00bc", "1/4"),
("\u00bd", "1/2"),
("\u00be", "3/4"),
("\u2150", "1/7"),
("\u2151", "1/9"),
("\u2152", "1/10"),
Expand All @@ -30,16 +30,16 @@
("\u2157", "3/5"),
("\u2158", "4/5"),
("\u2159", "1/6"),
("\u215A", "5/6"),
("\u215B", "1/8"),
("\u215C", "3/8"),
("\u215D", "5/8"),
("\u215E", "7/8"),
("\u215a", "5/6"),
("\u215b", "1/8"),
("\u215c", "3/8"),
("\u215d", "5/8"),
("\u215e", "7/8"),
("\u2189", "0/3"),
]
#: Rules for non-standard spaces
SPACE_RULES = [
("\u00A0", " "),
("\u00a0", " "),
("\u1680", " "),
("\u2002", " "),
("\u2003", " "),
Expand All @@ -49,52 +49,52 @@
("\u2007", " "),
("\u2008", " "),
("\u2009", " "),
("\u200A", " "),
("\u200B", " "),
("\u202F", " "),
("\u205F", " "),
("\u200a", " "),
("\u200b", " "),
("\u202f", " "),
("\u205f", " "),
("\u2420", " "),
("\u3000", " "),
("\u303F", " "),
("\uFEFF", " "),
("\u303f", " "),
("\ufeff", " "),
]

#: Rules for sign chars
SIGN_RULES = [
("\u00A9", ""), # copyright
("\u00AE", ""), # registered
("\u00a9", ""), # copyright
("\u00ae", ""), # registered
("\u2122", ""), # trade
]

#: Rules for dot chars
DOT_RULES = [
# horizontal ellipsis
("\u2026", "..."),
("\u22EF", "..."),
("\u22ef", "..."),
]

#: RegexpReplacer quotation marks: replace double and single quotation marks
QUOTATION_RULES = [
("»", '"'), # normalize double quotation marks
("«", '"'), # replace double quotation marks
("\u201C", '"'),
("\u201D", '"'),
("\u201E", '"'),
("\u201F", '"'),
("\u201c", '"'),
("\u201d", '"'),
("\u201e", '"'),
("\u201f", '"'),
("\u2039", '"'),
("\u203A", '"'),
("\u02F5", '"'),
("\u02F6", '"'),
("\u02DD", '"'),
("\uFF02", '"'),
("\u201A", ""), # single low quotation (remove)
("\u203a", '"'),
("\u02f5", '"'),
("\u02f6", '"'),
("\u02dd", '"'),
("\uff02", '"'),
("\u201a", ""), # single low quotation (remove)
("\u2018", "'"), # left side single quotation
("\u2019", "'"), # right side single quotation
("\u201B", "'"), # single high reverse quotation
("\u02CA", "'"), # grave accent
("\u201b", "'"), # single high reverse quotation
("\u02ca", "'"), # grave accent
("\u0060", "'"),
("\u02CB", "'"), # acute accent
("\u00B4", "'"),
("\u02cb", "'"), # acute accent
("\u00b4", "'"),
]

#: All pre-defined rules for CharReplacer
Expand Down
1 change: 0 additions & 1 deletion medkit/text/relations/syntactic_relation_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
To install them, use `pip install medkit-lib[syntactic-relation-extractor]`.
"""


__all__ = ["SyntacticRelationExtractor"]
import logging
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions medkit/text/translation/hf_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
This module needs extra-dependencies not installed as core dependencies of medkit.
To install them, use `pip install medkit-lib[hf-translator]`.
"""

from __future__ import annotations

__all__ = ["HFTranslator"]
Expand Down
8 changes: 5 additions & 3 deletions medkit/tools/mtsamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ def load_mtsamples(

return [
TextDocument(
text=sample["transcription_translated"]
if translated
else sample["transcription"],
text=(
sample["transcription_translated"]
if translated
else sample["transcription"]
),
metadata=dict(
id=sample["id"] if translated else sample[""],
description=sample["description"],
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ build-backend = "poetry_dynamic_versioning.backend"

[tool.black]
line-length = 88
preview = true
target-version = ["py38"]
extend-exclude = ".venv"

[tool.flake8]
Expand Down
4 changes: 2 additions & 2 deletions tests/large/test_mtsamples.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_mt_samples_without_pipeline(caplog):
(r"(?<=[0-9]\s)°", " degrés"),
(r"(?<=[0-9])°", " degrés"),
("\u00c6", "AE"), # ascii
("\u00E6", "ae"), # ascii
("\u00e6", "ae"), # ascii
("\u0152", "OE"), # ascii
("\u0153", "oe"), # ascii
(r"«|»", '"'),
Expand Down Expand Up @@ -97,7 +97,7 @@ def test_mt_samples_with_doc_pipeline():
(r"(?<=[0-9]\s)°", " degrés"),
(r"(?<=[0-9])°", " degrés"),
("\u00c6", "AE"), # ascii
("\u00E6", "ae"), # ascii
("\u00e6", "ae"), # ascii
("\u0152", "OE"), # ascii
("\u0153", "oe"), # ascii
(r"«|»", '"'),
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/audio/transcription/test_hf_transcriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ def test_basic():


def test_no_formatting():
"""No reformatting of transcribed text (raw text as returned by transformers pipeline)
"""
"""No reformatting of transcribed text (raw text as returned by transformers pipeline)"""
transcriber = HFTranscriber(
model="mock-model",
output_label="transcribed_text",
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/core/prov_tracer/test_prov_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def test_multiple_items():


def test_multiple_items_with_sources():
"""Several items generated by an operation, then used as input to another operation
"""
"""Several items generated by an operation, then used as input to another operation"""
tracer = ProvTracer()
# generate 2 items then prefix them
generator = Generator(tracer)
Expand All @@ -66,8 +65,7 @@ def test_multiple_items_with_sources():


def test_intermediate_operation():
"""Input items passed to an intermediate operation, then intermediate items passed to another operatio
"""
"""Input items passed to an intermediate operation, then intermediate items passed to another operatio"""
tracer = ProvTracer()
# generate 2 items and prefix them twice with 2 different operations
generator = Generator(tracer)
Expand Down Expand Up @@ -158,8 +156,7 @@ def test_multiple_source():


def test_partial_provenance():
"""Data items generated from input items for which no provenance info is available
"""
"""Data items generated from input items for which no provenance info is available"""
tracer = ProvTracer()
# generate 2 items then split them it in 2 them merge them
# provenance info will be provided only by Merger operation
Expand Down
Loading

0 comments on commit e639bd5

Please sign in to comment.