Skip to content

Commit

Permalink
Merge pull request #110 from akretion/format
Browse files Browse the repository at this point in the history
Format + clean tests + pyproject
  • Loading branch information
rvalyi committed Jun 29, 2024
2 parents 8ee2c2a + c852cfb commit 0021342
Show file tree
Hide file tree
Showing 14 changed files with 307 additions and 148 deletions.
2 changes: 0 additions & 2 deletions .coveragerc

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
release:
types: [released]

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/nfelib
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: 3.9
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
16 changes: 10 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
- {name: Python 3.11, python: '3.11', os: ubuntu}
- {name: Python 3.12, python: '3.12', os: ubuntu}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Install libxml2
Expand All @@ -33,9 +33,13 @@ jobs:
sudo apt-get install libxml2-dev libxslt-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools tox
python -m pip install --upgrade pip setuptools pytest pytest-xdist xmlschema pytest-cov
python -m pip install .[test]
- name: Test
run: |
tox -e py -v --color=yes
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
pytest --cov=./nfelib --cov-report=xml --cov-branch --doctest-glob="docs/*.md"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ docs/_build/

# Backup files
*~
*.swp
*.swp
70 changes: 27 additions & 43 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,54 +1,38 @@
exclude: |
(?x)
setup.cfg|
^tests|
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.10.1
hooks:
- id: pyupgrade
args: [--py37-plus]
- repo: https://github.com/asottile/reorder_python_imports
rev: v2.4.0
hooks:
- id: reorder-python-imports
- repo: https://github.com/ambv/black
rev: 22.3.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.0
hooks:
- id: flake8
additional_dependencies: [
flake8-bugbear,
flake8-annotations,
flake8-comprehensions,
]
args: ["--suppress-none-returning"]
^README\.md$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: debug-statements
- repo: git@github.com:humitos/mirrors-docformatter.git
rev: v1.0
hooks:
- id: docformatter
args: ["--in-place", "--pre-summary-newline"]
- repo: https://github.com/crate-ci/typos
rev: v1.22.9
hooks:
- id: typos
exclude: ^tests/|.xsd$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff
args: [ --fix, --show-fixes]
- id: ruff-format
exclude: ^nfelib/[^/]+\.py$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
rev: v1.10.1
hooks:
- id: mypy
additional_dependencies: [tokenize-rt]
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.17.0
hooks:
- id: setup-cfg-fmt
args: ["--max-py-version=3.9"]
- repo: https://github.com/PyCQA/doc8
rev: 0.9.0a1
hooks:
- id: doc8
files: ^(nfelib/)
args: [ "--check-untyped-defs", "--ignore-missing-imports" ]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
additional_dependencies:
- prettier@3.2.5
types_or: [markdown]
args: [--prose-wrap=always, --print-width=88]
exclude: ^nfelib/[^/]+\.xml$
4 changes: 2 additions & 2 deletions .xsdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
<Substitution type="package" search="http://schemas.xmlsoap.org/wsdl/soap/" replace="soap"/>
<Substitution type="package" search="http://schemas.xmlsoap.org/wsdl/soap12/" replace="soap12"/>
<Substitution type="package" search="http://schemas.xmlsoap.org/soap/envelope/" replace="soapenv"/>

<!-- xmldsig : -->
<Substitution type="field" search="^@any_element$" replace="any_element"/>
<Substitution type="field" search="^@other_element$" replace="other_element"/>
<Substitution type="field" search="^@any_attributes$" replace="any_attributes"/>
<Substitution type="field" search="^@any_attributes$" replace="any_attributes"/>
<Substitution type="field" search="^Signature$" replace="signature"/>
<Substitution type="field" search="^SignatureMethod$" replace="signatureMethod"/>
<Substitution type="field" search="^SignatureValue$" replace="signatureValue"/>
Expand Down
133 changes: 133 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
[build-system]
requires = ["setuptools>=61.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools.packages.find]
include = ["nfelib*"]

[project]
name = "nfelib"
description = "nfelib: electronic invoicing library for Brazil"
authors = [{name = "Raphaël Valyi", email = "raphael.valyi@akretion.com.br"}]
license = {text = "MIT"}
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
keywords = ["e-invoicing", "ERP", "Odoo", "NFe", "CTe", "MDFe", "BPe", "NFSe"]
requires-python = ">=3.8"
dependencies = [
"xsdata",
]
dynamic = ["version"]

[project.readme]
file = "README.md"
content-type = "text/markdown"

[project.urls]
Homepage = "https://github.com/akretion/nfelib"
Source = "https://github.com/akretion/nfelib"
Documentation = "https://nfelib.readthedocs.io/"
Changelog = "https://nfelib.readthedocs.io/en/latest/changelog/"

[project.optional-dependencies]
sign = [
"erpbrasil.assinatura",
]
pdf = [
"brazilfiscalreport",
]
test = [
"pre-commit",
"pytest",
"pytest-benchmark",
"pytest-cov",
"xmldiff",
"requests",
"beautifulsoup4",
"erpbrasil.assinatura",
"brazilfiscalreport",
]

[tool.setuptools]
include-package-data = true
license-files = ["MIT-LICENSE"]

[tool.setuptools.dynamic]
version = {attr = "nfelib.__version__"}

[tool.ruff]
target-version = "py38"

[tool.ruff.lint]
select = [
# pycodestyle
"E",
# Pyflakes
"F",
# pyupgrade
"UP",
# flake8-bugbear
"B",
# flake8-simplify
"SIM",
# flake8-annotations
"ANN",
# flake8-comprehensions
"C4",
# isort
"I",
# pydocstyle
"D",
# flake-raise
"RSE",
# flake-return
"RET",
# Ruff rules
"RUF",
]

ignore = [
"ANN101",
"ANN102",
"ANN201",
"ANN202",
"ANN204",
"ANN206",
"ANN401",
"E203",
"B028",
"B904",
"D100",
"D104",
"D107",
"RUF009",
"RUF012",
]

[tool.ruff.lint.per-file-ignores]
"**/{tests}/*" = ["ANN001", "ANN002", "ANN003", "E501", "B018", "D"]
"**/utils/testing.py" = ["D"]
"docs/*" = ["D"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.format]
line-ending = "lf"

[tool.pytest.ini_options]
addopts = "--color=yes"
doctest_optionflags = "NORMALIZE_WHITESPACE"
3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

39 changes: 20 additions & 19 deletions tests/cte/test_cte.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@

import os
from xmldiff import main
from unittest import TestCase

from xsdata.formats.dataclass.serializers.config import SerializerConfig
from xsdata.formats.dataclass.parsers import XmlParser
from xsdata.formats.dataclass.serializers import XmlSerializer
from pathlib import Path

from nfelib.cte.bindings import v4_0
from nfelib.cte.bindings import v4_0 # noqa: F401


def test_in_out_cte():
path = os.path.join("nfelib", "cte", "samples", "v4_0")
for filename in os.listdir(path):
input_file = os.path.join(path, filename)
parser = XmlParser()
obj = parser.from_path(Path(input_file))
serializer = XmlSerializer(config=SerializerConfig(pretty_print=True))
xml = serializer.render(
obj=obj,
ns_map={None: "http://www.portalfiscal.inf.br/cte"}
)
class CTeTests(TestCase):
def test_in_out_cte(self):
path = os.path.join("nfelib", "cte", "samples", "v4_0")
for filename in os.listdir(path):
input_file = os.path.join(path, filename)
parser = XmlParser()
obj = parser.from_path(Path(input_file))
serializer = XmlSerializer(config=SerializerConfig(pretty_print=True))
xml = serializer.render(
obj=obj, ns_map={None: "http://www.portalfiscal.inf.br/cte"}
)

output_file = "tests/output_cte.xml"
with open(output_file, "w") as f:
f.write(xml)
output_file = "tests/output_cte.xml"
with open(output_file, "w") as f:
f.write(xml)

diff = main.diff_files(input_file, output_file)
assert len(diff) == 0
if len(diff) != 0:
break
diff = main.diff_files(input_file, output_file)
self.assertEqual(len(diff), 0)
if len(diff) != 0:
break
Loading

0 comments on commit 0021342

Please sign in to comment.