grumpyhome / grumpy

Grumpy is a Python to Go source code transcompiler and runtime.
Apache License 2.0
420 stars 18 forks source link

Need a tutorial for running and transpiling youtube-dl #133

Open joeky888 opened 5 years ago

joeky888 commented 5 years ago

Would you document a tutorial for running and transpiling a complete project like youtube-dl.

The dependencies of youtube-dl are only Python and Python-setuptools.

$ cd youtube-dl
$ grumpc youtube_dl/__main__.py
package __main__
import (
        πg "grumpy"
        // _ "__python__/sys"
        // _ "__python__/os"
        // _ "__python__/os/path"
)
var Code *πg.Code
func init() {
...
$ What to do next?

It would be amazing if there is a tutorial for compiling youtube-dl to a static binary.

alanjds commented 5 years ago

I really should rewrite the outdated readme, but mainly is to install on the virtualenv and then

$ grumpy run youtube_dl/__main__.py

You can see internals using the -v debug flag, if you want:

$ grumpy -v debug run youtube_dl/__main__.py

When it got worked, can keep the binary with the flag --go-action build of run

$ grumpy run --go-action build youtube_dl/__main__.py

Btw, thanks for asking.

Let me know if it worked or not, ok?

joeky888 commented 5 years ago

grumpy run youtube_dl/main.py

I stuck on the first step.

$ git clone --depth 1 https://github.com/rg3/youtube-dl /tmp/youtube-dl
$ cd /tmp/youtube-dl
$ # Remove from __future__ import division
$ find . -type f -exec sed -i -e 's/,\s*division//g' {} \;
$ find . -type f -exec sed -i -e 's/division\s*,//g' {} \;
$ python2 youtube_dl/__main__.py # Looks good.
Usage: __main__.py [OPTIONS] URL [URL...]

__main__.py: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.

$ grumpy run youtube_dl/__main__.py # Not good.
../tmpIYBaGy__pycache__/gopath/src/__python__/main.go:60:2: no Go files in /usr/lib/python2.7/ctypes/macholib/__pycache__/dyld.grumpy-022.pyc/gopath/src/__python__/ctypes/macholib
../tmpIYBaGy__pycache__/gopath/src/__python__/main.go:69:2: no Go files in /usr/lib/python2.7/distutils/__pycache__/errors.grumpy-022.pyc/gopath/src/__python__/distutils
../tmpIYBaGy__pycache__/gopath/src/__python__/main.go:186:2: no Go files in /usr/lib/python2.7/xml/parsers/__pycache__/expat.grumpy-022.pyc/gopath/src/__python__/xml
../tmpIYBaGy__pycache__/gopath/src/__python__/main.go:187:2: no Go files in /usr/lib/python2.7/xml/etree/__pycache__/ElementTree.grumpy-022.pyc/gopath/src/__python__/xml/etree
../tmpIYBaGy__pycache__/gopath/src/__python__/main.go:190:2: no Go files in /usr/lib/python2.7/xml/parsers/__pycache__/expat.grumpy-022.pyc/gopath/src/__python__/xml/parsers
alanjds commented 5 years ago

Yeah. Grumpy does not support C-based modules right now (and probable never be). It runs pure-python only code. The ctypes module your code needs is C-based.

The alternatives are to reimplement the interfaces in pure-python or Go-based modules.

Just to say, I would imagine that Cython-based WOULD be possible to be supported, if it does not interfaces with the CPython C-API, but nobody started this effort.

alanjds commented 5 years ago

For example, my own pet task on this project right now is to reimplement _codecs module in pure-python, as the CPython version is C-based, thus unusable on Grumpy.

The expected outcome is to be able to run zipfile module, that needs _codecs.

joeky888 commented 5 years ago

Thanks, I guess this is why annie comes out :)