Skip to content

Commit

Permalink
🎨 Comply with isort, mypy, flake8 and black (#81)
Browse files Browse the repository at this point in the history
* ❇️ 🎨 Setup lint verifcations GHA

black, isort, flake8 and mypy

* 🎨 mypy, black, isort and flake8 conformance fix

* 🔧 dev_requirements.txt adjustments

Some dev deps should only be installed when py >= 3.6

* 🔥 🔧 for now remove pypy from tests GHA (until resolve dev-requirements.txt conflicts)

* 🎨 switch to relative import
  • Loading branch information
Ousret authored Aug 12, 2021
1 parent d05e10c commit 14c74b4
Show file tree
Hide file tree
Showing 15 changed files with 2,395 additions and 741 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: 🎨 Linters

on: [push, pull_request]

jobs:
lint:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
python-version: [3.8]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip setuptools
pip install -r dev-requirements.txt
pip uninstall -y charset-normalizer
- name: Install the package
run: |
python setup.py install
- name: Type checking (Mypy)
run: |
mypy charset_normalizer
- name: Import sorting check (isort)
run: |
isort --check charset_normalizer
- name: Code format (Black)
run: |
black --check --diff --target-version=py35 charset_normalizer
- name: Style guide enforcement (Flake8)
run: |
flake8 charset_normalizer
3 changes: 0 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ jobs:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10.0-rc.1"]
os: [ubuntu-latest]
include:
- python-version: pypy3
os: ubuntu-latest

steps:
- uses: actions/checkout@v2
Expand Down
38 changes: 26 additions & 12 deletions charset_normalizer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,38 @@
Basic usage:
>>> from charset_normalizer import from_bytes
>>> results = from_bytes('Bсеки човек има право на образование. Oбразованието трябва да бъде безплатно, поне що се отнася до началното и основното образование.'.encode('utf_8'))
>>> "utf_8" in results
True
>>> best_result = results.best()
>>> str(best_result)
'Bсеки човек има право на образование. Oбразованието трябва да бъде безплатно, поне що се отнася до началното и основното образование.'
>>> results = from_bytes('Bсеки човек има право на образование. Oбразованието!'.encode('utf_8'))
>>> best_guess = results.best()
>>> str(best_guess)
'Bсеки човек има право на образование. Oбразованието!'
Others methods and usages are available - see the full documentation
at <https://github.com/Ousret/charset_normalizer>.
:copyright: (c) 2021 by Ahmed TAHRI
:license: MIT, see LICENSE for more details.
"""
from charset_normalizer.api import from_fp, from_path, from_bytes, normalize
from charset_normalizer.legacy import detect
from charset_normalizer.version import __version__, VERSION
from charset_normalizer.models import CharsetMatch, CharsetMatches
import charset_normalizer.api as CharsetDetector

from .api import from_bytes, from_fp, from_path, normalize
from .legacy import detect

# Backward-compatible v1 imports
from charset_normalizer.models import CharsetNormalizerMatch
import charset_normalizer.api as CharsetDetector
from .models import CharsetMatch, CharsetMatches, CharsetNormalizerMatch
from .version import VERSION, __version__

CharsetNormalizerMatches = CharsetDetector


__all__ = (
"from_fp",
"from_path",
"from_bytes",
"normalize",
"detect",
"CharsetMatch",
"CharsetMatches",
"CharsetNormalizerMatch",
"CharsetNormalizerMatches",
"__version__",
"VERSION",
)
Loading

0 comments on commit 14c74b4

Please sign in to comment.