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

Python 2 -> 3 changes. #1745

Closed
wants to merge 21 commits into from
Closed

Python 2 -> 3 changes. #1745

wants to merge 21 commits into from

Conversation

iljah
Copy link

@iljah iljah commented Mar 21, 2021

Didn't see much work being done lately for transition from python 2 to 3 and was wondering if something like this would be helpful. If yes I can submit request(s) that follow guidelines better...

@iljah
Copy link
Author

iljah commented Mar 21, 2021

@PeterSurda in case github doesn't ping you automatically.

@PeterSurda
Copy link
Member

Thanks, maybe we can use parts of it. As it is unfortunately I can't accept it as none of the test jobs succeed, it breaks compatibility with python 2.7 while still not working correctly with 3.7. You can run the tests yourself with run-tests-in-docker.sh if you want, and you can register with buildbot so that the tests are run on my servers, as described here: https://wiki.bitmessage.org/index.php/Contribute#Register_with_buildbot

@iljah
Copy link
Author

iljah commented Mar 22, 2021

breaks compatibility with python 2.7

This doesn't surprise me since I haven't been able to set up everything required by bitmessage under python 2 in latest fedora and cannot test compatibility of my changes. But if you're open to these contributions and no one else is working on this at the moment I can test python 2 stuff in a virtual machine so that things don't break.

@PeterSurda
Copy link
Member

@iljah well, there are developers working on python3 port, it just isn't always visible here as the work may not be ready for a PR until it's done correctly and I'm happy with it. I worry perhaps you're doing duplicate work.

If you want to continue development, as I said you can run the tests with the run-tests-in-docker.sh, it executes both python 2.7 and python 3.7 tests, no need to install a VM. I tested the script on Ubuntu 20.04 and Mac OS Big Sur, I'm confident it runs anywhere docker is available. Or, you can register with buildbot, and then upon pushing to your own repo, buildbot will queue the tests to be run by my workers, and you'll have the results online in about 5 minutes (this actually runs more tests, including windows builds, code quality, ...).

from network.invthread import InvThread
from network.receivequeuethread import ReceiveQueueThread
from network.downloadthread import DownloadThread
from network.uploadthread import UploadThread
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are binding the code to pathmagic harder instead of preparing its removal ):

network is a package, so you can write from .network import .. ant it will work both in python2.7 and python3 in installed and portable mode.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks it wasn't very clear to me what the best way to fix imports for python 3 would be. I'll give .network a try.

@PeterSurda
Copy link
Member

Also, there is WIP to get PyBitmessage flatpak builds working, #1618 . This may also alleviate pressure from a python3 port and serve as a workaround for new releases of linux distros.

@@ -75,7 +75,7 @@ def lock(self):
fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
self.lockPid = os.getpid()
except IOError:
print 'Another instance of this application is already running'
print('Another instance of this application is already running')
sys.exit(-1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

sys.exit('Another instance of this application is already running')?

Copy link
Author

Choose a reason for hiding this comment

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

Possible but in that case return value can't be specified. If nothing relies on particular return values then exit('') is probably better.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Only two values are significant here: 0 and any other. When you pass a string it's interpreted as program error, like any non-zero exit code.

Copy link
Author

Choose a reason for hiding this comment

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

I guess nothing relies on specific values of non-zero so exit('') is fine.

$ python -c 'exit(5)'; echo $?
5
$ python -c 'exit(6)'; echo $?
6
$ python -c 'exit("error")'; echo $?
error
1

@@ -0,0 +1 @@
from .storage import InventoryItem, InventoryStorage
Copy link
Collaborator

Choose a reason for hiding this comment

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

You are adding __init__ here and remove it from network, using dotted imports here, but rely on pathmagic in other places. So inconsistent.

Copy link
Author

Choose a reason for hiding this comment

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

I've (luckily? :)) never had to deal with this part of python so don't know what would be best/correct/portable fix. I'll try .stuff

@@ -40,12 +40,12 @@ def translateText(context, text, n=None):
try:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Didn't know this existed. Do you suggest starting my work from that or incorporating some changes into my fork?

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can see all the forks on the network page: https://github.com/Bitmessage/PyBitmessage/network I suggest you to keep trying if you wanna merge, but be prepared to long wait. Existing PR's and issues are also worth reading, for example #1712

@iljah iljah mentioned this pull request Mar 23, 2021
@iljah
Copy link
Author

iljah commented Mar 23, 2021

Created #1746 that includes fewer changes but still works using python 2.

@iljah iljah closed this Mar 23, 2021
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