Skip to content
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
7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

41 changes: 7 additions & 34 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
repos:
# Modifiers
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand All @@ -21,27 +10,11 @@ repos:
- id: check-yaml
- id: end-of-file-fixer

- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py39-plus]

- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
args: ["--filter-files"]

- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8

# Static Checkers
- repo: https://github.com/PyCQA/bandit
rev: 1.7.10
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.1
hooks:
- id: bandit
additional_dependencies: [".[toml]"]
args: ["-c", "bandit.yml"]
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
2 changes: 0 additions & 2 deletions bandit.yml

This file was deleted.

37 changes: 24 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,11 @@ python = ["3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.pre-commit]
dependencies = [
"bandit",
"black",
"flake8",
"flake8-bugbear == 22.*",
"flake8-docstrings",
"isort",
"pep8-naming",
"ruff",
"pre-commit",
"pre-commit-hooks",
"pyupgrade",
]

[tool.hatch.envs.pre-commit.scripts]
run = [
"pre-commit run --all-files --show-diff-on-failure",
Expand All @@ -92,6 +86,7 @@ dependencies = [
"pytest",
"freezegun",
]

[tool.hatch.envs.mypy.scripts]
run = [
"mypy src/ tests/ docs/conf.py",
Expand All @@ -105,6 +100,7 @@ dependencies = [
"pygments",
"freezegun",
]

[tool.hatch.envs.tests.scripts]
run = [
"coverage run --parallel -m pytest"
Expand All @@ -114,11 +110,13 @@ run = [
dependencies = [
"coverage[toml]",
]

[tool.hatch.envs.coverage.scripts]
run = [
"- coverage combine",
"coverage report",
]

run-xml = [
"coverage xml"
]
Expand All @@ -131,6 +129,7 @@ dependencies = [
"typeguard",
"pygments",
]

[tool.hatch.envs.typeguard.scripts]
run = [
"pytest --typeguard-packages=human_readable",
Expand All @@ -140,6 +139,7 @@ run = [
dependencies = [
"xdoctest[colors]",
]

[tool.hatch.envs.xdoctest.scripts]
run = [
"python -m xdoctest human_readable all",
Expand All @@ -151,6 +151,7 @@ dependencies = [
"furo",
"myst-parser",
]

[tool.hatch.envs.docs-build.scripts]
run = [
"rm -rf docs/_build",
Expand All @@ -164,6 +165,7 @@ dependencies = [
"furo",
"myst-parser",
]

[tool.hatch.envs.docs.scripts]
run = [
"rm -rf docs/_build",
Expand All @@ -182,10 +184,20 @@ source = ["human_readable", "tests"]
show_missing = true
fail_under = 100

[tool.isort]
profile = "black"
force_single_line = true
lines_after_imports = 2
[tool.ruff]
line-length = 80

[tool.ruff.lint]
select = ["B", "B9", "C", "D", "E", "F", "N", "W"]
ignore = ["E203", "E501", "B905"]
per-file-ignores = { "times.py" = ["N806"] }

[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.ruff.lint.isort]
force-single-line = true
lines-after-imports = 2

[tool.mypy]
strict = true
Expand All @@ -195,7 +207,6 @@ show_column_numbers = true
show_error_codes = true
show_error_context = true


[[tool.mypy.overrides]]
module = ["pytest_mock"]
ignore_missing_imports = true
Expand Down
12 changes: 11 additions & 1 deletion src/human_readable/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ def file_size(

Returns:
str: file size in natural language.

"""
if gnu:
suffixes = ("K", "M", "G", "T", "P", "E", "Z", "Y")
elif binary:
suffixes = (" KiB", " MiB", " GiB", " TiB", " PiB", " EiB", " ZiB", " YiB")
suffixes = (
" KiB",
" MiB",
" GiB",
" TiB",
" PiB",
" EiB",
" ZiB",
" YiB",
)
else:
suffixes = (" KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB")

Expand Down
13 changes: 11 additions & 2 deletions src/human_readable/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def get_translation() -> gettext_module.NullTranslations:
return _TRANSLATIONS[""]


def activate(locale: str, path: str | None = None) -> gettext_module.NullTranslations:
def activate(
locale: str, path: str | None = None
) -> gettext_module.NullTranslations:
"""Activate internationalisation.

Set `locale` as current locale. Search for locale in directory `path`.
Expand All @@ -43,6 +45,7 @@ def activate(locale: str, path: str | None = None) -> gettext_module.NullTransla

Raises:
Exception: If human readable cannot find the locale folder.

"""
if path is None:
path = _get_default_locale_path()
Expand All @@ -53,7 +56,9 @@ def activate(locale: str, path: str | None = None) -> gettext_module.NullTransla
"folder. You need to pass the path explicitly."
)
if locale not in _TRANSLATIONS:
translation = gettext_module.translation("human_readable", path, [locale])
translation = gettext_module.translation(
"human_readable", path, [locale]
)
_TRANSLATIONS[locale] = translation
_CURRENT.locale = locale
return _TRANSLATIONS[locale]
Expand All @@ -72,6 +77,7 @@ def gettext(message: str) -> str:

Returns:
Translated text.

"""
return get_translation().gettext(message)

Expand All @@ -88,6 +94,7 @@ def pgettext(msgctxt: str, message: str) -> str:

Returns:
Translated text.

"""
return get_translation().pgettext(msgctxt, message)

Expand All @@ -103,6 +110,7 @@ def ngettext(message: str, plural: str, num: int) -> str:

Returns:
Translated text.

"""
return get_translation().ngettext(message, plural, num)

Expand All @@ -120,5 +128,6 @@ def gettext_noop(message: str) -> str:

Returns:
Original text, unchanged.

"""
return message
1 change: 1 addition & 0 deletions src/human_readable/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def listing(items: list[str], separator: str, conjunction: str = "") -> str:

Returns:
str: list in natural language.

"""
len_items = len(items)
if len_items == 0:
Expand Down
7 changes: 7 additions & 0 deletions src/human_readable/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def _thousands_separator() -> str:

Returns:
str: Thousands separator.

"""
try:
sep = _THOUSANDS_SEPARATOR[i18n._CURRENT.locale]
Expand All @@ -45,6 +46,7 @@ def ordinal(value: int | str) -> str:

Returns:
str: ordinal string.

"""
suffixes = (
P_("0", "th"),
Expand Down Expand Up @@ -76,6 +78,7 @@ def int_comma(value: str | float) -> str:

Returns:
str: formatted number with commas.

"""
sep = _thousands_separator()
if isinstance(value, str):
Expand Down Expand Up @@ -123,6 +126,7 @@ def int_word(value: float, formatting: str = ".1f") -> str:

Returns:
str: number formatted with scale words.

"""
if value < POWERS[0]:
return str(value)
Expand All @@ -147,6 +151,7 @@ def ap_number(value: float | str) -> str | float:

Returns:
Union[str, float]: spelled 1-9 numbers or original number.

"""
value = int(value)
if not 0 <= value < 10:
Expand Down Expand Up @@ -194,6 +199,7 @@ def fractional(value: str | float) -> str:

Returns:
str: human readable number.

"""
number = float(value)
whole_number = int(number)
Expand Down Expand Up @@ -233,6 +239,7 @@ def scientific_notation(value: float | str, precision: int = 2) -> str:

Returns:
str: Number in scientific notation z.wq x 10ⁿ.

"""
exponents = {
"0": "⁰",
Expand Down
Loading
Loading