RedHat-Israel / ROSE

ROSE project car race game
GNU General Public License v2.0
34 stars 125 forks source link

Cleanup python2 six and imp libraries #478

Closed yaacov closed 1 year ago

yaacov commented 1 year ago

Ref: https://github.com/RedHat-Israel/ROSE/pull/476/files#r1306497974

Follow up for score logic cleanup, separate PR #476 to python2 cleanup and score logic cleanup.

yaacov commented 1 year ago

@nirs @sleviim hi, can you review / refer to a reviewer ?

sleviim commented 1 year ago

Just before merging, want to verify - @yaacov have you tried running the code with those changes and it went well? :)

yaacov commented 1 year ago

Just before merging, want to verify - @yaacov have you tried running the code with those changes and it went well? :)

Yes :-)

EDIT: ~( note that the .pyc examples will not work on python3 )~ ( note that the .pyc examples may not work on python other then python 3.9 )

screenshot-localhost_8880-2023 08 27-11_01_03

sleviim commented 1 year ago

hmmm interesting is there a way to run drivers codes without exposing the code (as we used the pyc for it)?

yaacov commented 1 year ago

hmmm interesting is there a way to run drivers codes without exposing the code (as we used the pyc for it)?

sorry for the confusion, in general, .pyc files are specific to the version of Python with which they were compiled, due to the potential changes in bytecode between versions. This is the reason why the magic number exists in the .pyc header; it helps prevent the accidental execution of a bytecode file with a different interpreter version than what it was compiled for.

to make the current.pyc files work you need to run them using the same version of python they where created with:

hexdump -n 2 -e '1/2 "%04x"' score.pyc 
0d42
# 0d42 is magic for python 3.9

using any other version of python may or may not run the .pyc files currectly.

is there a way to run drivers codes without exposing the code (as we used the pyc for it)?

a. yes, recompile them using the currently used python (you will need the sources for that) b. using pipenv, venv or Dockerfile (if we move to containers) to pin down the python version

yaacov commented 1 year ago

for completeness, link to python magic numbers: https://github.com/google/pytype/blob/main/pytype/pyc/magic.py

yaacov commented 1 year ago

side note: if we replace the RPC model with classic HTTP client-server model, we can write clients in any language, including compiled ones (e.g. rust / go ... ) and then we will not have the python decompile .pyc => .py problem