Skip to content
This repository was archived by the owner on Feb 13, 2021. It is now read-only.

Commit 870f1a2

Browse files
author
Thiago C. D'Ávila
authored
Merge pull request #50 from staticdev/pre-commit
Pre-commit, docstrings, type-hinting
2 parents 6d94806 + fe699e2 commit 870f1a2

14 files changed

Lines changed: 446 additions & 158 deletions

.pre-commit-config.yaml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,31 @@ repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
33
rev: v2.5.0
44
hooks:
5+
- id: check-toml
56
- id: check-yaml
67
- id: end-of-file-fixer
78
- id: trailing-whitespace
89
- id: check-added-large-files
9-
- id: check-toml
1010
- repo: https://github.com/prettier/prettier
1111
rev: 2.0.5
1212
hooks:
1313
- id: prettier
14-
- repo: local
14+
- repo: https://github.com/psf/black
15+
rev: 19.10b0
1516
hooks:
1617
- id: black
17-
name: black
18-
entry: poetry run black
19-
language: system
20-
types: [python]
18+
- repo: https://gitlab.com/pycqa/flake8
19+
rev: 3.7.9
20+
hooks:
2121
- id: flake8
22-
name: flake8
23-
entry: poetry run flake8
24-
language: system
25-
types: [python]
26-
- id: mypy
27-
name: mypy
28-
entry: poetry run mypy
29-
language: system
30-
types: [python]
31-
require_serial: true
22+
additional_dependencies:
23+
- flake8-bandit==2.1.2
24+
- flake8-bugbear==20.1.4
25+
- flake8-docstrings==1.5.0
26+
- pep8-naming==0.10.0
27+
- darglint==1.2.3
28+
- repo: https://github.com/asottile/reorder_python_imports
29+
rev: v2.3.0
30+
hooks:
31+
- id: reorder-python-imports
32+
args: [--application-directories=src]

noxfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212

1313
def install_with_constraints(session: Session, *args: str, **kwargs: Any) -> None:
1414
"""Install packages constrained by Poetry's lock file.
15+
1516
This function is a wrapper for nox.sessions.Session.install. It
1617
invokes pip to install packages inside of the session's virtualenv.
1718
Additionally, pip is passed a constraints file generated from
1819
Poetry's lock file, to ensure that the packages are pinned to the
1920
versions specified in poetry.lock. This allows you to manage the
2021
packages as Poetry development dependencies.
22+
2123
Arguments:
2224
session: The Session object.
2325
args: Command-line arguments for pip.

poetry.lock

Lines changed: 113 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pytest = "^5.4.2"
3434
coverage = {extras = ["toml"], version = "^5.0.4"}
3535
pytest-cov = "^2.8.1"
3636
typeguard = "^2.7.1"
37+
pre-commit = "^2.4.0"
3738

3839
[tool.coverage.paths]
3940
source = ["src", "*/site-packages"]

src/humanizer_portugues/filesize.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
43
"""Bits & Bytes related humanization."""
54

65

7-
def natural_size(value, binary=False, gnu=False, formatting="%.1f"):
8-
"""Format a number of byteslike a human readable filesize (eg. 10 kB). By
6+
def natural_size(
7+
value: int, binary: bool = False, gnu: bool = False, formatting: str = "%.1f"
8+
) -> str:
9+
"""Returns human-readable file size.
10+
11+
Format a number of byteslike a human readable filesize (eg. 10 kB). By
912
default, decimal suffixes (kB, MB) are used. Passing binary=true will use
1013
binary suffixes (KiB, MiB) are used and the base will be 2**10 instead of
1114
10**3. If ``gnu`` is True, the binary argument is ignored and GNU-style
1215
(ls -sh style) prefixes are used (K, M) with the 2**10 definition.
13-
Non-gnu modes are compatible with jinja2's ``filesizeformat`` filter."""
16+
Non-gnu modes are compatible with jinja2's ``filesizeformat`` filter.
17+
18+
Args:
19+
value (int): size number.
20+
binary (bool): binary format. Defaults to False.
21+
gnu (bool): GNU format. Defaults to False.
22+
formatting (str): format pattern. Defaults to "%.1f".
23+
24+
Returns:
25+
str: file size in natural language.
26+
"""
1427
if gnu:
1528
sufs = ("K", "M", "G", "T", "P", "E", "Z", "Y")
1629
elif binary:

src/humanizer_portugues/list.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
43
"""Lists related humanization."""
4+
from typing import List
55

66
__all__ = ["natural_list"]
77

88

9-
def natural_list(itens, separator, conjunction=None):
10-
"""
11-
Returns human readable list separated by separator
12-
Optional argument is conjuntion that substitutes the last separator
9+
def natural_list(items: List, separator: str, conjunction: str = None) -> str:
10+
"""Returns human readable list separated by separator.
11+
12+
Optional argument is conjuntion that substitutes the last separator.
13+
14+
Args:
15+
items (List): list of items.
16+
separator (str): separator of items.
17+
conjunction (str): word/string as last separator. Defaults to None.
18+
19+
Returns:
20+
str: list in natural language.
1321
"""
14-
len_itens = len(itens)
15-
if len_itens == 0:
22+
len_items = len(items)
23+
if len_items == 0:
1624
return ""
17-
if len_itens == 1:
18-
return itens[0]
19-
phrase = itens[0]
25+
if len_items == 1:
26+
return items[0]
27+
phrase = items[0]
2028
if conjunction:
21-
for i in range(1, len_itens - 1):
22-
phrase += "%s %s" % (separator, itens[i])
23-
phrase += " %s %s" % (conjunction, itens[len_itens - 1])
29+
for i in range(1, len_items - 1):
30+
phrase += "%s %s" % (separator, items[i])
31+
phrase += " %s %s" % (conjunction, items[len_items - 1])
2432
else:
25-
for i in range(1, len_itens):
26-
phrase += "%s %s" % (separator, itens[i])
33+
for i in range(1, len_items):
34+
phrase += "%s %s" % (separator, items[i])
2735
return phrase

0 commit comments

Comments
 (0)