zipcodetw icon indicating copy to clipboard operation
zipcodetw copied to clipboard

Remove unicodecsv from dependency for Python 3+

Open rschiang opened this issue 3 years ago • 2 comments

Currently, new installations in a clean virtualenv on Python 3.9.7 would result in the following error:

    File "/private/var/folders/…/zipcodetw/builder.py", line 23, in build
      dir_.load_chp_csv(csv_f)
    File "/private/var/folders/…/zipcodetw/util.py", line 317, in method_wrapper
      retval = method(self, *args, **kargs)
    File "/private/var/folders/…/zipcodetw/util.py", line 340, in load_chp_csv
      for row in csv.reader(lines_iter):
    File "/Users/…/zipcode_test/venv/lib/python3.9/site-packages/unicodecsv/py3.py", line 55, in __next__
      return self.reader.__next__()
    File "/Users/…/zipcode_test/venv/lib/python3.9/site-packages/unicodecsv/py3.py", line 51, in <genexpr>
      f = (bs.decode(encoding, errors=errors) for bs in f)
  AttributeError: 'str' object has no attribute 'decode'
  ----------------------------------------

Running pip remove unicodecsv && python -m zipcodetw.builder fixed the issue.

It appears that unicodecsv has been abandoned as in jdunck/python-unicodecsv#92, and thus no further maintenance are done for the package.

We could either:

  • drop the support for Python 2.7,
  • use the suggested csv backport from Python 3, or
  • specify unicodecsv as our dependency only when Python version < 3 as shown in PEP 0508.

The last one should be the easiest mitigation. Please let me know if a PR is preferred over issues.

rschiang avatar Sep 01 '21 19:09 rschiang

Python 2.7 has been end-of-life for nearly 2 years and many projects are no longer supporting it.

If you don't have an urgent need, I suggest dropping it too, it should make things much easier to maintain.

hugovk avatar Sep 05 '21 20:09 hugovk

@rschiang Thanks a lot. I have no preference among the suggested solutions and a PR is welcome.

moskytw avatar Sep 09 '21 14:09 moskytw