hanslub42 / rlwrap

A readline wrapper
GNU General Public License v2.0
2.53k stars 149 forks source link

Python filter can't be loaded #161

Closed ams-cen closed 1 year ago

ams-cen commented 2 years ago

Hi,

We are using the EPEL 8 rlwrap package (0.45.2), and I don't have the infrastructure to try if this happens with a self-compiled version. Still I think rlwrapfilter.py should be prepared for this.

Using the python version of the provided example censor_passwords script (as well as my own filter written in python) produces the following error (the example perl filters work fine):

rlwrap -icf $CENV_HOME/sqlplus.clc -z censor_passwords.py sqlplus
Traceback (most recent call last):
  File "/usr/share/rlwrap/filters/censor_passwords.py", line 21, in <module>
    import rlwrapfilter
  File "/usr/share/rlwrap/filters/rlwrapfilter.py", line 74, in <module>
    rlwrap_version = float(os.environ.get('RLWRAP_VERSION', "0.41"))
ValueError: could not convert string to float: '0.45.2'
rlwrap: error: error writing to filter: Broken pipe
rlwrap: warning: filter died
warnings can be silenced by the --no-warnings (-n) option

A quick but dirty fix could be rlwrap_version = float(os.environ.get('RLWRAP_VERSION', "0.41")[:4]) but only until version 0.99 :)

Attila

michel-slm commented 1 year ago

Fedora bug: https://bugzilla.redhat.com/show_bug.cgi?id=2091749

The fix should be quite straightforward, we should probably use packaging.version.parse instead of float. I'll try and put up a PR tomorrow.

ams-cen commented 1 year ago

Hi Michel,

I saw that there is already a package for RHEL with the fix, thank you very much :)

Best regards, Attila

ams-cen commented 1 year ago

Hi @michel-slm,

Unfortunately packaging is not part of the Python Standard Library. This change introduces a new dependency:

Traceback (most recent call last):
  File "/home/oracle/cenv/rlwrap_filters.py", line 13, in <module>
    import rlwrapfilter
  File "/usr/share/rlwrap/filters/rlwrapfilter.py", line 51, in <module>
    from packaging import version
ModuleNotFoundError: No module named 'packaging'
rlwrap: error: error writing to filter: Broken pipe
hanslub42 commented 1 year ago

See 804e76e9b81edec4c9f2953197019ae9a85ab395 Version strings like 12.5.43b-5 will now be converted to 12.5435. This should be granular enough for now - I'd rather not pull in a dependency oustide the standard library.

The perl filter does a string comparison, which will be problematic as soon as we reach version 10