kaitai-io / kaitai_struct_webide

Online editor / visualizer for Kaitai Struct .ksy files
https://ide.kaitai.io
GNU General Public License v3.0
275 stars 62 forks source link

Adjust python code to work with python3 #53

Open sem-geologist opened 6 years ago

sem-geologist commented 6 years ago

I wanted to install webide on the android tablet using termux (I have tested webide remote version and find it quite useful, it looked to me to be less complicated to install with termux than cmd line version, as termux have no jde available). However I run into problem with installation and launching python scripts, which are written for python2, and only python3 comes with termux. Python3 is becoming a standard version in the many linux distributions and many software is dropping python 2 support.

So I can offer my time to modify python code and add PR, the main question is how? These are to considerations:

  1. drop python 2 support, and convert python code to comply with python3 using e.g. py2to3.
  2. if python2 support is wished to stay present, the python codebase could be modified to use six so that it would work with both python2 and python3.

PS. I am really impressed with capabilities of kaitai_struct (even if used only as the tool to RE binary format) it is manyfold better tool compared with other hex editors. I have some highly dynamic binary formats in my RE experience (some scientific electron microscopy formats, including virtual file system) and using Hexinator or wxHexEditor were really painful on dynamic data structs. Lately I am RE another binary format and find that using traditional hexeditors I am not able to manage whole complexity, and started to translate my knowledge about format into ksy. I wish kaitai_struct were available for me two years ago, I would had not lost so much time. I am still not sure about compiled code, as excessive class construction and hierarchical instance access is costly in python. Soon I will have something to compare.

GreyCat commented 6 years ago

There is no "remote" and "local" versions of Web IDE. It runs completely on client-side, there is no server-side component. Python is used in Web IDE mostly to automate routine building tasks. Migrating that to Python 3 is possible, but not the highest priority, I guess — and, even if you do, building that on an Android would be probably still a pretty high hurdle to jump over (i.e. it requires TypeScript, which in turn requires working npm and some JavaScript engine like nodejs to run that, etc, etc).

On the other hand, the only thing needed to run is a simple static files web server. If you have any Python, just run

python -m SimpleHTTPServer 5123

And then you can access Web IDE on http://127.0.0.1:5123/

PS. I am really impressed with capabilities of kaitai_struct

Thanks for your high marks :)

some scientific electron microscopy formats

BTW, you could probably cooperate with @KOLANICH, he was also working on some microscopy/spectroscopy formats — i.e. https://github.com/kaitai-io/kaitai_struct_formats/tree/master/scientific/spectroscopy and https://github.com/kaitai-io/kaitai_struct/issues/134

I am still not sure about compiled code, as excessive class construction and hierarchical instance access is costly in python.

Well, Python is relatively slow (well, probably the slowest of all, to be frank), so you might want to consider some alternatives. C++ would be probably many times faster.

KOLANICH commented 6 years ago

1 I vote for dropping python 2 support, since python 3 works on even on very ancient systems with Windows XP, i686 without sse2 (pentium 3, I really have worked on such systems in 2017, and yes, it works fine (lubuntu is capable running python 3.7)), so everyone should upgrade immediately (unless a very special case of having old c++ modules incompatible with new python) to the latest version of python supported having support of his environment.

2

python is relatively slow

I guess pypy3 may help (though I haven't used it). But it is quite useless since it doesn't have scipy.

koczkatamas commented 6 years ago

OSX comes with only Python 2 and based on this Reddit thread most of the Linux distros have Python 2 installed.

As @GreyCat mentioned serve.py is only required for development. The WebIDE works without any server-side code as long as its files are served by any webserver (file:// does not work).

I will look into making this script Python 2 & 3 compatible, but I won't handle this task with high priority.

iROOT commented 6 years ago

I managed to port. It was be easy. Run $FileDir$/2to3 -w $FilePathRelativeToProjectRoot$ (External Tool in IDEA) and python -bb vendor_build.py. Small fixes with bytes and that's all. https://github.com/iroot/kaitai_struct_webide/commit/58ccb36fe15438e01725662dbe2ec2dec8b896b5 I did not use six, so therefore backward compatibility is probably broken.

jaxxor44 commented 5 years ago

currently there is a problem with the shebang line of vendor_build.py Further problems with packages when using an env2.7 Does not seem to be friendly to my setup for now, ill keep an eye on this until full py3 support is implemented.