GitHub Action to test Python code
Output: https://github.com/cclauss/nfelib/actions
Travis CI seems to be no longer active...
Hello @cclauss. I'm very much OK to move to Github actions. As for linting the Python generated code, I prefer to stay away from it for now. Indeed it will introduce artificial diff with the code generated next time if the generator has some changes. And spotting real changes easily over formatting is really what matters here (changes usually happen because of schemas updates or because of changes in generateDS).
Also while one can read/debug/hack the nfelib generated code, this is usually not some code you will spend time into. It's more of a black box that is tested to get the job done. Instead as for us who work with the Odoo ERP, we have an equivalent NFe Odoo abstract model: https://github.com/akretion/l10n-brazil/blob/12.0-l10n_br_nfe_spec-update/l10n_br_nfe_spec/models/v4_00/leiauteNFe.py This is the nice NFe code we eventually read when we need. Then we automatically convert this abstract model back and forth to nfelib and use nfelib pretty much as a black box unless we suspect a bug.
It is generated with this generateDS plugin https://github.com/akretion/generateds-odoo Similar plugins can target other frameworks/ERPs...
I'll comment more about code formatting in a few weeks. Meanwhile if you do a PR focusing on moving to testing with Github Actions I'm OK to merge it. What do you think?
Are there particular directories that contain generated code because we could exclude them from analysis.
So in fact most of the lib is generated code... We could almost generate it on the fly even, but having it in a Github repo is a safe way to track evolutions (due to new schema versions or changes in the generator).
So the nfelibdirectory is all generated code. And instead src and tests is hand written code. src is a collection of snall overrides where we need them and as allowed by GenerateDS. We could format/analysis src and tests, but IMHO the benefice is very little for so little code.
OK... I have slimmed this down to just bandit (security), the most essential flake8 tests (below), and pytest. If these tests break, we should know about it.
https://flake8.pycqa.org/en/latest/user/error-codes.html
On the flake8 test selection, this PR does not focus on "style violations" (the majority of flake8 error codes that psf/black can autocorrect). Instead, these tests focus on runtime safety and correctness:
- E9 tests are about Python syntax errors usually raised because flake8 can not build an Abstract Syntax Tree (AST). Often these issues are a sign of unused code or code that has not been ported to Python 3. These would be compile-time errors in a compiled language but in a dynamic language like Python, they result in the script halting/crashing on the user.
- F63 tests are usually about the confusion between identity and equality in Python. Use ==/!= to compare str, bytes, and int literals is the classic case. These are areas where a == b is True but a is b is False (or vice versa). Python >= 3.8 will raise SyntaxWarnings on these instances.
- F7 tests logic errors and syntax errors in type hints
- F82 tests are almost always undefined names which are usually a sign of a typo, missing imports, or code that has not been ported to Python 3. These also would be compile-time errors in a compiled language but in Python, a NameError is raised which will halt/crash the script on the user.
$ pytest .
tests/nfe/test_nfelib.py ............ [100%]
Hello @cclauss if you are still interested in nfelib, the new xsdata based branch we want to switch to is this one https://github.com/akretion/nfelib/tree/master-xsdata-originalCase/nfelib We believe this new branch generated with xsdata is a lot cleaner and more sustainable to maintain and extend.
And here is its xsdata model generator counter counterpart https://github.com/akretion/xsdata-odoo (the replacement for akretion/generateds-odoo) We are still adjusting a few things before making the switch in Odoo https://github.com/OCA/l10n-brazil/pull/1979 and when we do it in Odoo (hopefully within 30 days) we will switch the default branch of nfelib too.