diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 0000000..ff5fc4f --- /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 flake8 isort mypy pytest pyupgrade safety + - run: bandit --recursive --skip B101 . || true # B101 is assert statements + - 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 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 + - run: pytest --doctest-modules . || true + - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true + - run: safety check diff --git a/pynfe/processamento/serializacao.py b/pynfe/processamento/serializacao.py index dfdd7ba..a04e802 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) 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): 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 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() - 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!')