Skip to content

Commit

Permalink
Merge e406de6 into 5f046e9
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Oct 8, 2022
2 parents 5f046e9 + e406de6 commit 4cbabf8
Show file tree
Hide file tree
Showing 13 changed files with 448 additions and 224 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Testing
on: [pull_request, push]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
test:
name: Testing on
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", 3.9, 3.8, 3.7, pypy-3.9]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-${{ matrix.python-version }}-
- name: pip version
run: pip --version
- name: Install dependencies
run: python -m pip install -r requirements.txt
# formatters
- name: Run pyupgrade
if: matrix.python-version == '3.9'
run: pyupgrade --py37-plus *.py
- name: Run isort
if: matrix.python-version == '3.9'
run: isort --check-only *.py
- name: Run black
if: matrix.python-version == '3.9'
run: black --check --skip-string-normalization *.py
# linters
- name: Lint with bandit
if: matrix.python-version == '3.9'
run: bandit --skip B101 *.py # B101 is assert statements
- name: Lint with codespell
if: matrix.python-version == '3.9'
run: codespell *.rst *.py
- name: Lint with flake8
if: matrix.python-version == '3.9'
run: flake8 *.py --count --max-complexity=18 --max-line-length=88 --show-source --statistics
- name: Lint with mypy
if: matrix.python-version == '3.9'
run: |
mkdir --parents --verbose .mypy_cache
mypy --ignore-missing-imports --install-types --non-interactive *.py || true
- name: Lint with safety
if: matrix.python-version == '3.9'
run: safety check || true
# tests and coverage
- name: Test
run: pytest run_tests.py --cov --cov-report term-missing
- name: Coverage
run: coveralls --service=github
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*.egg-info
*.pyc

.cache
.coverage
.installed.cfg
.hypothesis
bin
develop-eggs
include
Expand Down
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

9 changes: 8 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ Changelog
1.3.1 (unreleased)
------------------

- Nothing changed yet.
- Update dependencies. [gforcada]

- Test the code on GitHub actions. [gforcada]

- Drop python 2.7 and only support python 3.7+. [gforcada]

- Use linters and formatters to keep code sane and beautiful. [gforcada]

- Simplify the amount of code to write a test. [gforcada]

1.3.0 (2019-12-15)
------------------
Expand Down
17 changes: 0 additions & 17 deletions LICENSE.rst

This file was deleted.

12 changes: 10 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
include MANIFEST.in LICENSE *.rst *.py *.ini
exclude .installed.cfg .coveragerc *.pyc
include MANIFEST.in
include LICENSE
include setup.cfg
include *.rst
include *.py
include *requirements.txt

exclude .installed.cfg
exclude .coveragerc
exclude *.pyc
exclude *.in
20 changes: 12 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
.. -*- coding: utf-8 -*-
.. image:: https://travis-ci.org/gforcada/flake8-pep3101.svg?branch=master
:target: https://travis-ci.org/gforcada/flake8-pep3101
.. image:: https://github.com/gforcada/flake8-pep3101/actions/workflows/testing.yml/badge.svg?event=push
:target: https://github.com/gforcada/flake8-pep3101/actions/workflows/testing.yml

.. image:: https://coveralls.io/repos/gforcada/flake8-pep3101/badge.svg?branch=master&service=github
:target: https://coveralls.io/github/gforcada/flake8-pep3101?branch=master

Flake8 PEP 3101 plugin
======================
Python has two string formatting options,
either the old percent operator or the new ``.format()`` string method.
Python has three string formatting options:

Being the new one more powerful, expressive and a drop-in replacement
over the old one.
- the old percent operator
- the ``.format()`` string method
- `f-strings`_ (only since python 3.6+)

See `pyformat website`_ for lots of examples of old vs new formatting.
Although f-strings are more ergonomic, there a certain scenarios where the
``.format()`` method is still the only viable option.

See `pyformat website`_ for examples of the percent operator vs the ``format()`` method.

For a more format definition see the `PEP 3101`_.

Expand All @@ -28,7 +31,7 @@ Install with pip::

Requirements
------------
- Python 2.7, 3.5, 3.6
- Python 3.7, 3.8, 3.9, 3.10 and pypy3
- flake8

Extras
Expand All @@ -42,5 +45,6 @@ GPL 2.0

.. _`pyformat website`: https://pyformat.info
.. _`PEP 3101`: https://www.python.org/dev/peps/pep-3101
.. _`f-strings`: https://peps.python.org/pep-0498/
.. _`flake8-string-format`: https://pypi.python.org/pypi/flake8-string-format
.. _`plone.recipe.codeanalysis`: https://pypi.python.org/pypi/plone.recipe.codeanalysis
18 changes: 7 additions & 11 deletions flake8_pep3101.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
import ast
import pycodestyle

import pycodestyle
from flake8 import utils as stdin_utils

class Flake8Pep3101(object):

class Flake8Pep3101:
name = 'flake8_pep3101'
version = '1.2.1'
message = 'S001 found modulo formatter'
Expand All @@ -14,14 +14,11 @@ def __init__(self, tree, filename):
self.tree = tree

def run(self):
tree = self.tree

if self.filename == 'stdin':
lines = pycodestyle.stdin_get_value()
lines = stdin_utils.stdin_get_value()
tree = ast.parse(lines)
elif self.tree:
tree = self.tree
else:
with open(self.filename) as f:
tree = ast.parse(f.read())

for stmt in ast.walk(tree):
if self._is_module_operation(stmt):
Expand Down Expand Up @@ -50,5 +47,4 @@ def _is_left_hand_number(stmt):
@staticmethod
def _is_modulo_variable_and_number(stmt):
"""Check if it is a case of `var % 44`."""
return isinstance(stmt.right, ast.Num) and \
isinstance(stmt.left, ast.Name)
return isinstance(stmt.right, ast.Num) and isinstance(stmt.left, ast.Name)
25 changes: 25 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
bandit
black
codespell
coveralls
flake8-blind-except
flake8-builtins
flake8-bugbear
flake8-comprehensions
flake8-debugger
flake8-deprecated
flake8-isort
flake8-pep3101
flake8-print
flake8-quotes
flake8-todo
importlib-metadata; python_version < '3.8'
isort
mypy
pytest
pytest-cov
pyupgrade
safety
testfixtures
typed-ast; python_version < '3.8' # dependency of black and mypy
zipp; python_version < '3.8' # dependency of importlib-metadata

0 comments on commit 4cbabf8

Please sign in to comment.