Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: update dependencies, testing, packaging, and linting/formatting #685

Merged

Conversation

lindsay-stevens
Copy link
Contributor

Overall this PR modernises pyxform and lints a swathe of code. Most of the commits are progressive application of linter rules, which hopefully makes it clearer what is being done and why - refer to pyproject.toml to see what rules were enabled in that commit.

Changes summary:

  • update prod and dev/test dependencies to latest versions for Python 3.8
  • update testing runner from nose 1.3.7 (2015) to built-in unittest, which can do everything required by pyxform. This also revealed some testing issues which are fixed:
    • ResourceWarnings due to input XLS/X files not being closed properly. Presumably nose was suppressing warnings so these were not visible until switching to unittest.
    • BadChoicesSheetHeaders test expected warnings that either don't exist or apply anymore. This test was not being run by nose for some unknown reason.
    • AttributeColumnsTest test expected output was not updated for secondary instances, and the fix to missing itext media. This test was not being run by nose for some unknown reason.
  • update packaging to use flit since setuptools is no longer recommended for python. Another option is hatch but it looked like it might be a bit overkill and/or introduce OS dependency requirements just for package building.
  • update linting to use ruff, which has linter/formatter rules that encompass all the existing tools (black, flake8, isort) and many more. An initial batch of extra linting rule sets are enabled and applied.
  • remove unused and unmaintained sphinx based docs stub folder - not published anywhere and broken anyway

Why is this the best possible solution? Were any other approaches considered?

These changes support upgrading pyxform supported Python versions, since the tools replaced in this PR are either out of date already or will not be supported in future.

A lot of code in pyxform is/was crufty due to it's origins in Python 2, and as a natural result of having dozens of committers over many years. The increased linting moves the code towards a more coherent style that is more consistent with modern Python code. This should make contributions easier in future.

What are the regression risks?

The update of AttributeColumnsTest seems to have revealed a bug introduced by #380 for custom attributes and repeats (will backref this ticket). Nobody seems to have complained about this though so perhaps it's a low priority to fix.

The release publishing GitHub action may not be 100% right since I'm not sure there's a nice way to test that.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

The code should be functionally equivalent for users. Where applicable, the README file has been updated.

Before submitting this PR, please make sure you have:

  • included test cases for core behavior and edge cases in tests
  • run nosetests unittest and verified all tests pass
  • run black pyxform tests ruff check pyxform tests & ruff format pyxform tests to lint and format code
  • verified that any code or assets from external sources are properly credited in comments

Copy link
Contributor

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice, thank you! I've put a couple of small notes inline and happy for you to merge after you've considered them.

pyxform/builder.py Outdated Show resolved Hide resolved
pyxform/constants.py Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
- config: old [setup.cfg, setup.py], new [pyproject.toml]
- format/lint: old [black, flake8, isort], new [ruff]
- build/publish: old [build, twine], new [flit]
- updated github actions and readme accordingly
- source changes according to new default formatter and linter rules
- nobody has changed these files since 2011, and they're very incomplete
- the docs generated aren't published anywhere
- the readme instructions don't work with python 3.8
  - sphinx 1.0.7 not compatible with python 3+
  - newer sphinx versions have an OS dependency on OpenSSL 1.1.1+
- updated readme to refer to useful resources and current docs state
- mostly error handling, unused variables
- mostly mutable classvars, unnecessary noqa comments, list unpacking
- unnecessary calls to list() or dict(), redundant comprehensions
- unnecessary placeholders, unnecessary range starts (0), dict.values()
- re-order ruff calls since `check` doesn't auto-format
- collapsible else-ifs, collapsible multiple comparisons
- use of assert, use of ElementTree, unchecked URL scheme
- use type-able NamedTuple, raise accurate errors, log exception TBs
- UP009 utf8-encoding-declaration unnecessary for python 3
- UP031 printf-string-formatting replace percent-formats with f-strings
- nose 1.3.7 is very old and not using any advanced test features that
  would require a 3rd party test library like nose2 or pytest
- default pattern is test_* for runner to pick up TestCases
- remove redundant mode/encoding args
- simplify unittest import in test_bugs.py
- xls2json_backends.py: both XLS and XLSX open and read the respective
  files, do processing, then close the file. But if an error occurs
  during processing then the file is left open. A ResourceWarning
  is raised when python cleans up the file handle. The ResourceWarning
  is visible during tests because test libraries remove the normal
  suppression of warnings during test runs. So normally a user probably
  wouldn't see it. The fix is to make sure the workbook object and file
  are cleaned up and closed with a contextmanager + try-except block.
- test_bugs.py: fixed test that had been broken for a while. It was not
  being executed by nose test runner for some reason. After converting
  tests to unittest, it ran and failed. After doing some git archaeology
  it seems that the 3rd warning that was expected was one about Google
  Sheets not supporting certain file names, but while that warning was
  later removed, the test was not updated. The 2nd is commented on.
- fixed strange string concatentation on the same line e.g. "a" "b".
- nose tests were not running this test for a while. The changes are:
  - secondary instances / itemsets replacing inline choices.
  - for media itext with no translation, the value/form not output
  - probable bug: custom attributes not applied to repeat template
    (they appear in first repeat but not the jr:template).
- bump actions version numbers
- update syntax for install, build, test
- either missing before, or mistakenly removed in commit f491ea8
lindsay-stevens added a commit to lindsay-stevens/pyxform that referenced this pull request Feb 8, 2024
@lindsay-stevens
Copy link
Contributor Author

@lognaturel thanks for the review! I'll wait for #694 to be decided before merging.

@lognaturel
Copy link
Contributor

Let's go ahead and merge! I think we're going to let #694 simmer for a bit. We can always release off a special release branch if needed.

@lindsay-stevens lindsay-stevens merged commit a7027ea into XLSForm:master Feb 14, 2024
10 checks passed
@lindsay-stevens lindsay-stevens deleted the pyxform-dev-deps-update branch February 14, 2024 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants