From b570abb2d47e815930a2e8d2a7a72b6e2b140df2 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 10:47:12 +0200 Subject: [PATCH 1/8] GitHub Action to lint Python code * `print()` is a function in Python 3. * `basestring` and `unicode` were removed in Python 3. --- .github/workflows/lint_python.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/lint_python.yml diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 0000000..54c4be3 --- /dev/null +++ b/.github/workflows/lint_python.yml @@ -0,0 +1,20 @@ +name: lint_python +on: [pull_request, push] +jobs: + lint_python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade safety + - run: bandit --recursive --skip B101 . || true # B101 is assert statements + - run: black --check . || true + - run: codespell || true # --ignore-words-list="" --skip="" + - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + - run: isort --check-only --profile black . || true + - run: pip install -r requirements.txt || true + - run: mypy --ignore-missing-imports . || true + - run: pytest . || true + - run: pytest --doctest-modules . || true + - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true + - run: safety check From 6f9618803293cd7a529a40cda4c7364a729c1b02 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 13:19:28 +0200 Subject: [PATCH 2/8] Declare strCode = "" before using it --- pynfe/utils/bar_code_128.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pynfe/utils/bar_code_128.py b/pynfe/utils/bar_code_128.py index e5d0cae..f3def0a 100644 --- a/pynfe/utils/bar_code_128.py +++ b/pynfe/utils/bar_code_128.py @@ -162,6 +162,7 @@ class Code128: current_charset = None pos=sum=0 skip=False + strCode="" for c in range(len(code)): if skip: skip=False From 2cd19154075b9b797be186e51b6266a1c5b80213 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 13:27:24 +0200 Subject: [PATCH 3/8] Define basestring and unicode in Python 3 --- pynfe/utils/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pynfe/utils/__init__.py b/pynfe/utils/__init__.py index 2aeeab6..9a62c18 100644 --- a/pynfe/utils/__init__.py +++ b/pynfe/utils/__init__.py @@ -16,6 +16,13 @@ try: except ImportError: raise Exception('Falhou ao importar flags') +try: + basestring + unicode +except NameError: + basestring = str + unicode = str + # @memoize def so_numeros(texto): From f4064bcfa81ee6d21e9f97c320e2f9cbcb2a5810 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 13:29:17 +0200 Subject: [PATCH 4/8] Use ==/!= to compare constant literals (str, bytes, int, float, tuple) --- pynfe/processamento/serializacao.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pynfe/processamento/serializacao.py b/pynfe/processamento/serializacao.py index 0cc56be..b13b889 100644 --- a/pynfe/processamento/serializacao.py +++ b/pynfe/processamento/serializacao.py @@ -460,7 +460,7 @@ class SerializacaoXML(Serializacao): etree.SubElement(pis_item, 'CST').text = produto_servico.pis_modalidade etree.SubElement(pis_item, 'vBC').text = '{:.2f}'.format(produto_servico.pis_valor_base_calculo or 0) etree.SubElement(pis_item, 'pPIS').text = '{:.2f}'.format(produto_servico.pis_aliquota_percentual or 0) - if produto_servico.pis_modalidade is not '99': + if produto_servico.pis_modalidade != '99': etree.SubElement(pis_item, 'qBCProd').text = '{:.4f}'.format(produto_servico.quantidade_comercial) etree.SubElement(pis_item, 'vAliqProd').text = '{:.4f}'.format(produto_servico.pis_aliquota_percentual or 0) etree.SubElement(pis_item, 'vPIS').text = '{:.2f}'.format(produto_servico.pis_valor_base_calculo or 0) @@ -496,7 +496,7 @@ class SerializacaoXML(Serializacao): etree.SubElement(cofins_item, 'CST').text = produto_servico.cofins_modalidade etree.SubElement(cofins_item, 'vBC').text = '{:.2f}'.format(produto_servico.cofins_valor_base_calculo or 0) etree.SubElement(cofins_item, 'pCOFINS').text = '{:.2f}'.format(produto_servico.cofins_aliquota_percentual or 0) - if produto_servico.cofins_modalidade is not '99': + if produto_servico.cofins_modalidade != '99': etree.SubElement(cofins_item, 'vAliqProd').text = '{:.4f}'.format(produto_servico.cofins_aliquota_percentual or 0) etree.SubElement(cofins_item, 'vCOFINS').text = '{:.2f}'.format(produto_servico.cofins_valor or 0) From 62916a79e26aa1422ad1fd249fb057008a184443 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 14:07:02 +0200 Subject: [PATCH 5/8] print() is a function in Python 3 --- run_tests.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/run_tests.py b/run_tests.py index 072fe01..0b76d5f 100644 --- a/run_tests.py +++ b/run_tests.py @@ -23,8 +23,7 @@ if __name__ == '__main__': # Run the tests for fname in test_files: - print 'Running "%s"...'%(os.path.splitext(os.path.split(fname)[-1])[0]) + print('Running "%s"...'%(os.path.splitext(os.path.split(fname)[-1])[0])) doctest.testfile(fname) - print 'Finished!' - + print('Finished!') From 8f999fdba81b28bec9a341a50b673c4848a598fa Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 14:08:35 +0200 Subject: [PATCH 6/8] print() is a function in Python 3 --- run_fake_soap_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run_fake_soap_server.py b/run_fake_soap_server.py index 8a1b90d..ec76806 100644 --- a/run_fake_soap_server.py +++ b/run_fake_soap_server.py @@ -2,6 +2,7 @@ """Este script deve ser executado com Python 2.6+ e OpenSSL""" +from __future__ import print_function import os, datetime CUR_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -39,7 +40,7 @@ class HandlerStatusServico(tornado.web.RequestHandler): tag = extrair_tag(raiz.getroot().getchildren()[0].getchildren()[0]) # Chama o método respectivo para a tag - print 'Metodo:', tag + print('Metodo:', tag) getattr(self, tag)(raiz) def nfeStatusServicoNF2(self, raiz): @@ -92,4 +93,3 @@ if __name__ == '__main__': http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_options) http_server.listen(porta) tornado.ioloop.IOLoop.instance().start() - From f309fb3c65ab24bd4df8403d8b7831d87fc08c3b Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 14:19:41 +0200 Subject: [PATCH 7/8] pip install -r requirements.txt -r requirements-nfse.txt --- .github/workflows/lint_python.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 54c4be3..6300dcb 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -6,13 +6,13 @@ jobs: steps: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 - - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade safety + - run: pip install bandit black flake8 isort mypy pytest pyupgrade safety - run: bandit --recursive --skip B101 . || true # B101 is assert statements - run: black --check . || true - - run: codespell || true # --ignore-words-list="" --skip="" - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - run: isort --check-only --profile black . || true - - run: pip install -r requirements.txt || true + - run: pip install -r requirements.txt -r requirements-nfse.txt + - run: python ./test.py || true - run: mypy --ignore-missing-imports . || true - run: pytest . || true - run: pytest --doctest-modules . || true From bd816f569a41c35c3501e4dc350ade368ec2450a Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Fri, 14 May 2021 14:25:45 +0200 Subject: [PATCH 8/8] pip install sphinx_rtd_theme tornado --- .github/workflows/lint_python.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index 6300dcb..ff5fc4f 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -11,7 +11,7 @@ jobs: - run: black --check . || true - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - run: isort --check-only --profile black . || true - - run: pip install -r requirements.txt -r requirements-nfse.txt + - run: pip install sphinx_rtd_theme tornado -r requirements.txt -r requirements-nfse.txt - run: python ./test.py || true - run: mypy --ignore-missing-imports . || true - run: pytest . || true