GithubHelp home page GithubHelp logo

py2rb's People

Contributors

naitoh avatar snood1205 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py2rb's Issues

sys.argv and sys.exit

It appears there is no translation of sys.argv and sys.exit. Without these it isnt possible to transpile CLI scripts that use args or have exit codes.

Test [FAIL]

Hi there, I was giving a try, but I was a bit unfortunate.

I use rbenv and pyenv

python --version
Python 3.6.10
ruby --version
ruby 2.5.4p155 (2019-03-13 revision 67245) [x86_64-darwin18]

I tried several different version of python and ruby but still failing

./run_tests.py 
Looking for "ruby", "py2rb/builtins/module.rb", "py2rb/builtins/require.rb" [3]:
..                                                               [OK]
tests/test_builtins.rb [1]: .                                    [OK]
tests/algorithms/sqrt.py [4]: .                                [FAIL]
tests/algorithms/triangulation.py [4]: .                       [FAIL]
tests/basic/assert.py [4]: .                                   [FAIL]
tests/basic/assign.py [4]: .                                   [FAIL]
tests/basic/assign_slice.py [4]: .                             [FAIL]
tests/basic/augassign.py [4]: .                                [FAIL]
tests/basic/augassign2.py [4]: .                               [FAIL]
tests/basic/binaryops.py [4]: .                                [FAIL]

Any help would be appreciated

Instructions

Hi,

could you please add more instructions how to use it?

Thanks

range with step doesnt stop before stop

for i in range(0, 10, 2):
    print(i)

should emit 2->8, stepped by two

The transpiler emits

for i in 0.step(10, 2)
    print(i)
  end

which emits 2->10, stepped by two

Bare except catching failure

The follow (bad) Python will catch the exception

try:
    raise Exception("foo")
except:
    print("Got it")

It is transpiled as

begin
  raise Exception, "foo"
rescue
  print("Got it")
end

That only catches the default Ruby exception StandardError.
To catch the exception in Ruby, it needs to catch the top level Ruby exception class.

begin
  raise Exception, "foo"
rescue Exception
  print("Got it")
end

๐ŸŽ‰

Hello.
Today I use py2rb for the first time to translate some Python scripts into Ruby.
I think this tool is very useful.
Keep up your great work ๐ŸŽ‰

Syntax error in maths

gap = max(1, floor(gap / 1.25))

is transpiled to

gap = (1, floor(gap / 1.25.to_f)).max

error:

syntax error, unexpected ',', expecting ')'

Bug when using py2rb

I just found your package and it seems to be a good one.

I installed it and tried to run it but I just found this error message on my terminal:

$ py2rb python.py
Traceback (most recent call last):
  File "/usr/local/bin/py2rb", line 7, in <module>
    from py2rb import main
  File "/usr/local/lib/python2.7/site-packages/py2rb/__init__.py", line 2919
    print('Try  : ' + py_path + ' -> ' + output + ' : ', end='')
                                                            ^
SyntaxError: invalid syntax

The contents of my python.py file:

result=0
a,b=0,2
for x in range(1500):
    a,b=b,a+(4*b)
    if a<4000000:
        result+=a
print(result)

Can you help me?

AnnAssign not supported

ast.AnnAssign proves typed assignments (a: int = 1).

It is slightly different structure from ast.Assign as there is only one target instead of an array of targets, and includes an annotation which could be ignored initially.

only two ok

output:

$ python -V
Python 3.10.4
$ pip -V
pip 22.1.2 from /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pip (python 3.10)
$ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [arm64-darwin21]
$ pip install pyyaml
Requirement already satisfied: pyyaml in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (6.0)
$ pip install numpy
Requirement already satisfied: numpy in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (1.23.0)
$ python run_tests.py 

Looking for "ruby", "py2rb/builtins/module.rb", "py2rb/builtins/require.rb" [3]:
..                                                               [OK]
tests/test_builtins.rb [1]: .                                    [OK]
tests/algorithms/sqrt.py [4]: .                                [FAIL]
tests/algorithms/triangulation.py [4]: .                       [FAIL]
tests/basic/assert.py [4]: .                                   [FAIL]
tests/basic/assign.py [4]: .                                   [FAIL]
tests/basic/assign_slice.py [4]: .                             [FAIL]
tests/basic/augassign.py [4]: .                                [FAIL]
tests/basic/augassign2.py [4]: .                               [FAIL]
tests/basic/binaryops.py [4]: .                                [FAIL]
tests/basic/break.py [4]: .                                    [FAIL]
tests/basic/class.py [4]: .                                    [FAIL]
tests/basic/class2.py [4]: .                                   [FAIL]
tests/basic/class3.py [4]: .                                   [FAIL]
tests/basic/class4.py [4]: .                                   [FAIL]
tests/basic/class5.py [4]: .                                   [FAIL]
tests/basic/class6.py [4]: .                                   [FAIL]
tests/basic/closure.py [4]: .                                  [FAIL]
tests/basic/closure_in_class.py [4]: .                         [FAIL]
tests/basic/continue.py [4]: .                                 [FAIL]
tests/basic/del_array.py [4]: .                                [FAIL]
tests/basic/del_attr.py [4]: .                                 [FAIL]
tests/basic/del_dict.py [4]: .                                 [FAIL]
tests/basic/del_slice.py [4]: .                                [FAIL]
tests/basic/dictcomp1.py [4]: .                                [FAIL]
tests/basic/dictcomp2.py [4]: .                                [FAIL]
tests/basic/dictionary.py [4]: .                               [FAIL]
tests/basic/dictionary2.py [4]: .                              [FAIL]
tests/basic/dictionary3.py [4]: .                              [FAIL]
tests/basic/docstring.py [4]: .                                [FAIL]
tests/basic/embedding.py [4]: .                                [FAIL]
tests/basic/fib.py [4]: .                                      [FAIL]
tests/basic/float2int.py [4]: .                                [FAIL]
tests/basic/for_in.py [4]: .                                   [FAIL]
tests/basic/for_range1.py [4]: .                               [FAIL]
tests/basic/for_range2.py [4]: .                               [FAIL]
tests/basic/for_step.py [4]: .                                 [FAIL]
tests/basic/getattr.py [4]: .                                  [FAIL]
tests/basic/globalvar.py [4]: .                                [FAIL]
tests/basic/hasattr1.py [4]: .                                 [FAIL]
tests/basic/helloworld.py [4]: .                               [FAIL]
tests/basic/ifelse.py [4]:                                     [FAIL]
tests/basic/ifs.py [4]: .                                      [FAIL]
tests/basic/ifs2.py [4]: .                                     [FAIL]
tests/basic/keys.py [4]: .                                     [FAIL]
tests/basic/kwargs.py [4]: .                                   [FAIL]
tests/basic/kwargs2.py [4]:                                    [FAIL]
tests/basic/kwargs3.py [4]: .                                  [FAIL]
tests/basic/lambda.py [4]: .                                   [FAIL]
tests/basic/lambda2.py [4]:                                    [FAIL]
tests/basic/lambda3.py [4]:                                    [FAIL]
tests/basic/lambda_map.py [4]: .                               [FAIL]
tests/basic/list.py [4]: .                                     [FAIL]
tests/basic/list2.py [4]: .                                    [FAIL]
tests/basic/list3.py [4]: .                                    [FAIL]
tests/basic/listcomp1.py [4]:                                  [FAIL]
tests/basic/literals.py [4]: .                                 [FAIL]
tests/basic/logicalops.py [4]: .                               [FAIL]
tests/basic/loops.py [4]: .                                    [FAIL]
tests/basic/multiassign.py [4]: .                              [FAIL]
tests/basic/none.py [4]: .                                     [FAIL]
tests/basic/numeric.py [4]: .                                  [FAIL]
tests/basic/oo.py [4]: .                                       [FAIL]
tests/basic/oo_attributes.py [4]: .                            [FAIL]
tests/basic/oo_inherit.py [4]: .                               [FAIL]
tests/basic/oo_inherit2.py [4]: .                              [FAIL]
tests/basic/oo_inherit3.py [4]: .                              [FAIL]
tests/basic/oo_inherit_simple.py [4]: .                        [FAIL]
tests/basic/oo_inherit_simple_super1.py [4]: .                 [FAIL]
tests/basic/oo_inherit_simple_super2.py [4]: .                 [FAIL]
tests/basic/oo_inherit_simple_super3.py [4]:                   [FAIL]
tests/basic/oo_static_inherit.py [4]: .                        [FAIL]
tests/basic/pass.py [4]: .                                     [FAIL]
tests/basic/print.py [4]: .                                    [FAIL]
tests/basic/raise.py [4]: .                                    [FAIL]
tests/basic/raise2.py [4]: .                                   [FAIL]
tests/basic/scope.py [4]: .                                    [FAIL]
tests/basic/set.py [4]: .                                      [FAIL]
tests/basic/str1.py [4]: .                                     [FAIL]
tests/basic/str_endswith.py [4]: .                             [FAIL]
tests/basic/sumcomp.py [4]: .                                  [FAIL]
tests/basic/super1.py [4]: .                                   [FAIL]
tests/basic/super2.py [4]: .                                   [FAIL]
tests/basic/trueorfalse.py [4]: .                              [FAIL]
tests/basic/try.py [4]: .                                      [FAIL]
tests/basic/tuple.py [4]: .                                    [FAIL]
tests/basic/tuple2.py [4]: .                                   [FAIL]
tests/basic/vargs.py [4]: .                                    [FAIL]
tests/basic/while.py [4]: .                                    [FAIL]
tests/basic/with.py [4]: .                                     [FAIL]
tests/collections/ordered_dict.py [4]: .                       [FAIL]
tests/decorator/function1.py [4]: .                            [FAIL]
tests/decorator/function2.py [4]: .                            [FAIL]
tests/decorator/function3.py [4]: .                            [FAIL]
tests/decorator/property.py [4]: .                             [FAIL]
tests/decorator/setter.py [4]: .                               [FAIL]
tests/deep-learning-from-scratch/and_gate.py [4]:              [FAIL]
tests/deep-learning-from-scratch/relu.py [4]:                  [FAIL]
tests/deep-learning-from-scratch/sigmoid.py [4]:               [FAIL]
tests/deep-learning-from-scratch/step_function.py [4]:         [FAIL]
tests/errors/py_collision.py [4]: .                            [FAIL]
tests/functions/and.py [4]: .                                  [FAIL]
tests/functions/append.py [4]: .                               [FAIL]
tests/functions/aug.py [4]: .                                  [FAIL]
tests/functions/bitand.py [4]: .                               [FAIL]
tests/functions/bitor.py [4]: .                                [FAIL]
tests/functions/bitxor.py [4]: .                               [FAIL]
tests/functions/divfloor.py [4]: .                             [FAIL]
tests/functions/float.py [4]: .                                [FAIL]
tests/functions/floatdiv.py [4]: .                             [FAIL]
tests/functions/gtge.py [4]: .                                 [FAIL]
tests/functions/in.py [4]: .                                   [FAIL]
tests/functions/int.py [4]: .                                  [FAIL]
tests/functions/isinstance.py [4]: .                           [FAIL]
tests/functions/len.py [4]: .                                  [FAIL]
tests/functions/lshift.py [4]: .                               [FAIL]
tests/functions/ltle.py [4]: .                                 [FAIL]
tests/functions/ne.py [4]: .                                   [FAIL]
tests/functions/or.py [4]: .                                   [FAIL]
tests/functions/pop.py [4]: .                                  [FAIL]
tests/functions/rshift.py [4]: .                               [FAIL]
tests/functions/sort.py [4]: .                                 [FAIL]
tests/functions/str.py [4]: .                                  [FAIL]
tests/functions/ubitcomp.py [4]: .                             [FAIL]
tests/functions/uminus.py [4]: .                               [FAIL]
tests/functions/uplus.py [4]: .                                [FAIL]
tests/lists/all.py [4]: .                                      [FAIL]
tests/lists/any.py [4]: .                                      [FAIL]
tests/lists/extend.py [4]: .                                   [FAIL]
tests/lists/filter.py [4]: .                                   [FAIL]
tests/lists/in.py [4]: .                                       [FAIL]
tests/lists/insert.py [4]: .                                   [FAIL]
tests/lists/map.py [4]: .                                      [FAIL]
tests/lists/max.py [4]: .                                      [FAIL]
tests/lists/min.py [4]: .                                      [FAIL]
tests/lists/reverse.py [4]: .                                  [FAIL]
tests/lists/subclass.py [4]: .                                 [FAIL]
tests/lists/subclass2.py [4]: .                                [FAIL]
tests/lists/subclass3.py [4]: .                                [FAIL]
tests/lists/sum.py [4]: .                                      [FAIL]
tests/lists/sum2.py [4]: .                                     [FAIL]
tests/lists/xrange.py [4]: .                                   [FAIL]
tests/lists/zip.py [4]: .                                      [FAIL]
tests/modules/classname.py [4]: .                              [FAIL]
tests/modules/from_import.py [4]: .                            [FAIL]
tests/modules/from_import_as_module.py [4]: .                  [FAIL]
tests/modules/import.py [4]: .                                 [FAIL]
tests/modules/import_alias.py [4]: .                           [FAIL]
tests/modules/import_as_module.py [4]: .                       [FAIL]
tests/modules/import_class.py [4]: .                           [FAIL]
tests/modules/import_global.py [4]: .                          [FAIL]
tests/modules/import_init.py [4]:                              [FAIL]
tests/modules/import_multi.py [4]: .                           [FAIL]
tests/numpy/abs.py [4]:                                        [FAIL]
tests/numpy/all.py [4]:                                        [FAIL]
tests/numpy/any.py [4]:                                        [FAIL]
tests/numpy/arange.py [4]:                                     [FAIL]
tests/numpy/array2string.py [4]:                               [FAIL]
tests/numpy/asarray.py [4]:                                    [FAIL]
tests/numpy/ellipsis.py [4]:                                   [FAIL]
tests/numpy/empty.py [4]:                                      [FAIL]
tests/numpy/ext_slice.py [4]:                                  [FAIL]
tests/numpy/full.py [4]:                                       [FAIL]
tests/numpy/insert.py [4]:                                     [FAIL]
tests/numpy/like.py [4]:                                       [FAIL]
tests/numpy/linspace.py [4]:                                   [FAIL]
tests/numpy/max_min.py [4]:                                    [FAIL]
tests/numpy/maximum_minimum.py [4]:                            [FAIL]
tests/numpy/ndarray.py [4]:                                    [FAIL]
tests/numpy/ndarray2.py [4]:                                   [FAIL]
tests/numpy/ndarray3.py [4]:                                   [FAIL]
tests/numpy/not_like.py [4]:                                   [FAIL]
tests/numpy/np_copy.py [4]:                                    [FAIL]
tests/numpy/product.py [4]:                                    [FAIL]
tests/numpy/random_rand.py [4]:                                [FAIL]
tests/numpy/random_randint.py [4]:                             [FAIL]
tests/numpy/random_random.py [4]:                              [FAIL]
tests/numpy/random_uniform.py [4]:                             [FAIL]
tests/numpy/special_values.py [4]:                             [FAIL]
tests/numpy/sqrt.py [4]:                                       [FAIL]
tests/numpy/sum.py [4]:                                        [FAIL]
tests/numpy/trigonometric_funcitons.py [4]:                    [FAIL]
tests/numpy/type.py [4]:                                       [FAIL]
tests/os/path_basename.py [4]: .                               [FAIL]
tests/os/path_dirname.py [4]: .                                [FAIL]
tests/os/path_join.py [4]: .                                   [FAIL]
tests/os/walk.py [4]: .                                        [FAIL]
tests/random/random_random.py [4]: .                           [FAIL]
tests/six/integer_types.py [4]: .                              [FAIL]
tests/six/iteritems.py [4]: .                                  [FAIL]
tests/six/itervalues.py [4]: .                                 [FAIL]
tests/six/moves.range.py [4]: .                                [FAIL]
tests/six/py23.py [4]: .                                       [FAIL]
tests/strings/count.py [4]: .                                  [FAIL]
tests/strings/find.py [4]: .                                   [FAIL]
tests/strings/join.py [4]: .                                   [FAIL]
tests/strings/lstrip0.py [4]: .                                [FAIL]
tests/strings/lstrip1.py [4]: .                                [FAIL]
tests/strings/replace.py [4]: .                                [FAIL]
tests/strings/rfind.py [4]: .                                  [FAIL]
tests/strings/rstrip0.py [4]: .                                [FAIL]
tests/strings/rstrip1.py [4]: .                                [FAIL]
tests/strings/split.py [4]: .                                  [FAIL]
tests/strings/splitlines.py [4]: .                             [FAIL]
tests/strings/string_format_combined_simple.py [4]: .          [FAIL]
tests/strings/string_format_d.py [4]: .                        [FAIL]
tests/strings/string_format_d_simple.py [4]: .                 [FAIL]
tests/strings/string_format_f_simple.py [4]: .                 [FAIL]
tests/strings/string_format_i.py [4]: .                        [FAIL]
tests/strings/string_format_s_simple.py [4]: .                 [FAIL]
tests/strings/string_format_u.py [4]: .                        [FAIL]
tests/strings/strings_in_strings.py [4]: .                     [FAIL]
tests/strings/strip.py [4]: .                                  [FAIL]
tests/strings/strip1.py [4]: .                                 [FAIL]
tests/strings/ulcase.py [4]: .                                 [FAIL]
tests/strings/zipstring.py [4]: .                              [FAIL]
tests/unittest/assertAlmostEqual.py [4]: .                     [FAIL]
tests/unittest/assertEqual.py [4]: .                           [FAIL]
tests/unittest/assertIn.py [4]: .                              [FAIL]
tests/unittest/assertIs.py [4]: .                              [FAIL]
tests/unittest/assertIsInstance.py [4]: .                      [FAIL]
tests/unittest/assertRaises.py [4]: .                          [FAIL]
tests/unittest/assertTrue.py [4]: .                            [FAIL]
tests/unittest/class.py [4]: .                                 [FAIL]
Ran 224 tests in 14.336s

FAILED (failures=222)

Support for Python 3.8

Hi, thanks for this great project!

When trying to translate a simple script with Python 3.8, the constants are missing.

print(1 + 2)

outputs

Warning : syntax not supported (<_ast.Constant object at 0x10c4da040>)
Warning : syntax not supported (<_ast.Constant object at 0x10c4da2e0>)
print( + )

It looks like there were changes in ast for Python 3.8. From the docs:

Changed in version 3.8: Class ast.Constant is now used for all constants.

Deprecated since version 3.8: Old classes ast.Num, ast.Str, ast.Bytes, ast.NameConstant and ast.Ellipsis are still available, > but they will be removed in future Python releases. In the meanwhile, instantiating them will return an instance of a different > class.

There's also an unrelated warning about YAML.

/usr/local/lib/python3.8/site-packages/py2rb/__init__.py:29: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  module_map.update(yaml.load(f))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.