Git Product home page Git Product logo

flake8-encodings's Introduction

flake8-encodings

A Flake8 plugin to identify incorrect use of encodings.

Docs Documentation Build Status Docs Check Status
Tests Linux Test Status Windows Test Status macOS Test Status Coverage
PyPI PyPI - Package Version PyPI - Supported Python Versions PyPI - Supported Implementations PyPI - Wheel
Anaconda Conda - Package Version Conda - Platform
Activity GitHub last commit GitHub commits since tagged version Maintenance PyPI - Downloads
QA CodeFactor Grade Flake8 Status mypy status
Other License GitHub top language Requirements Status

Installation

flake8-encodings can be installed from PyPI or Anaconda.

To install with pip:

$ python -m pip install flake8-encodings

To install with conda:

  • First add the required channels
$ conda config --add channels https://conda.anaconda.org/conda-forge
$ conda config --add channels https://conda.anaconda.org/domdfcoding
  • Then install
$ conda install flake8-encodings

In version 0.5.1 and above the functionality for checking classes (configparser.ConfigParser and pathlib.Path for now) requires the classes extra to be installed:

$ python3 -m pip install flake8-encodings[classes]

The checks for classes are slower and CPU intensive, so only enable them if you use the classes in question.

Motivation

Developers using macOS or Linux may forget that the default encoding is not always UTF-8.

For example, long_description = open("README.md").read() in setup.py is a common mistake. Many Windows users cannot install the package if there is at least one non-ASCII character (e.g. emoji) in the README.md file which is encoded in UTF-8.

For example, 489 packages of the 4000 most downloaded packages from PyPI used non-ASCII characters in README. And 82 packages of them cannot be installed from source package when the locale encoding is ASCII. [1] They used the default encoding to read README or TOML file.

Even Python experts assume that default encoding is UTF-8. It creates bugs that happen only on Windows. See [2], [3], [4], and [5] for example.

PEP 597 proposed adding a new EncodingWarning to Python, which can be used in conjunction with this tool to identify issues at runtime.

[1]"Packages can't be installed when encoding is not UTF-8" (https://github.com/methane/pep597-pypi-ascii)
[2]Packaging tutorial in packaging.python.org didn't specify encoding to read a README.md (pypa/packaging.python.org#682)
[3]json.tool had used locale encoding to read JSON files. (https://bugs.python.org/issue33684)
[4]site: Potential UnicodeDecodeError when handling pth file (https://bugs.python.org/issue33684)
[5]pypa/pip: "Installing packages fails if Python 3 installed into path with non-ASCII characters" (pypa/pip#9054)

flake8-encodings's People

Contributors

domdfcoding avatar pre-commit-ci[bot] avatar repo-helper[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.