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

Python2/3 compatibile (compile and runtime) code #32

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

marcin1j
Copy link

This makes both ownet and swig (bindings, examples, unit tests) modules Python2/Python3 compatible. Ownet library requires six module (https://pypi.org/project/six/, it's a runtime dependency).

Note that this PR conflicts with python part of #26.

change exception syntax (for raise and except)
@miccoli miccoli self-assigned this Jan 27, 2019
@miccoli
Copy link
Contributor

miccoli commented Jan 28, 2019

THX for the PR: please give me a week or so for the review.

Although it is not strictly python3 compatibility, I would suggest to update also the ownet setup.py to use setuptools and to include the appropriate install_requires = ['six>= X.Y.Z']

@marcin1j
Copy link
Author

You're right. I'll do that.

@miccoli miccoli requested review from miccoli and removed request for miccoli February 3, 2019 14:24
Copy link
Contributor

@miccoli miccoli left a comment

Choose a reason for hiding this comment

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

At a first glance the changes to the python sources are OK.

However the setup.py files should be modernised and made python3 compatible.

  • module/ownet/python/setup.py and module/swig/python/setup.py.in: use setuptools instead of legacy distutils
  • module/ownet/python/setup.py: add relevant install_requires = ['six>= X.Y.Z']
  • module/swig/python/setup.py.in: when I try to build under python3 I have this error:
$ make -C module/swig/python 
Making all in ow
make[1]: Nothing to be done for `all'.
/usr/local/bin/swig -python -o ow_wrap.c ../ow.i
CFLAGS="-I/usr/local/Cellar/libusb/1.0.22/include/libusb-1.0 " /Users/miccoli/.pyenv/versions/owfs/bin/python setup.py build
Traceback (most recent call last):
  File "setup.py", line 93, in <module>
    my_extra_link_args = my_extra_link_args + string.split('../../owlib/src/c/.libs/libow.so', ' ')
AttributeError: module 'string' has no attribute 'split'
make[1]: *** [OW.py] Error 1
make: *** [all-recursive] Error 1

@marcin1j
Copy link
Author

marcin1j commented Oct 4, 2020

@miccoli Apparently I've lost track of this PR. Sorry for that.

Personally, after a short period of time I gave up using synchronous ownet module and wrote something with equivalent but asynchronous API, which better suits my needs.

I am still willing to make owfs python3-compatibile. If I'm not mistaken almost two years have passed and it still lacks python3 support. For that reason it's been recently masked and is scheduled to be completely removed from Gentoo's repo!

I can rewrite and test whatever is necessary on top of your changes #26 to make it compile and work correctly on either python3 or python2 and python3.
There's only question if we still needs python2 compatibility at all since it's been unmaintained for nine months now.

@miccoli
Copy link
Contributor

miccoli commented Oct 5, 2020

@marcin1j we usually discourage people from using the "official" owfs python bindings in new projects, since this code is unmaintained and has some serious limitations. The only reason for keeping it alive, is to ease the transition from legacy python2 code to python3, although a rewrite, targeting one of the various python3 libraries available on PyPi, would be in most cases a better choice.

This said I would say that it is better to keep python2 compatibility, which will stay around for a while for running legacy code.

As you can see I pushed a few commits to your repo, addressing some of my concerns. I think that now only some testing is needed to see if all works as expected.

Final touches, like a more clean configure.ac and makefile structure can be postponed.

This makes Python ownet module portable. Requires "six" module version
1.12.0 or newer.

Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
This makes swig Python code compatible with both Python 2 and Python 3.
Required to build package with Python bindings enabled.

Additionally, simplify "except ... as" syntax.
There's no reference to exception object in "except ... as" body so this
clause can be reduced to pure "exception" clause.

Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
@marcin1j marcin1j force-pushed the pr/20190103-python3-compatibility branch from 3ac4eb7 to 686f88a Compare October 5, 2020 16:49
@marcin1j
Copy link
Author

marcin1j commented Oct 5, 2020

I rebased this PR on top of #26. SWIG wrapper now compiles fine on both py2/3.

Note that you need 70027f5 (either cherry-pick 70027f5 or merge this PR with master branch). For testing purposes I rebased my PR on top of c68deb1 but can't do that on github since #26 is still based on 8750e5a.

Since this is the third attempt to upgrade python codebase (#24 addressed print syntax is swig module, #26 addressed raise/except syntax and this one aimed to address both syntax and runtime behavior), it makes sense to combine as much as possible. PR #24 is already merged but #26 is not so feel free to reorganize (cherry-pick or merge) my commits with #26 so that it forms a single branch.

@miccoli
Copy link
Contributor

miccoli commented Oct 11, 2020

@marcin1j tanks for your efforts. I'm a little busy now, but I will for sure merge this and all related PRs.

@miccoli miccoli added this to the v3.2p5 milestone Oct 11, 2020
buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this pull request Feb 9, 2022
The python support only works with python2, so drop it.

Notice that there is a PR adding python3 support, but it is not yet merged:

owfs/owfs#32

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Proposals for improving owfs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants