Live data from Hacker News

Grumpy: Go running Python

opensource.googleblog.com

211–220 of 463 posts

Re: Grumpy: Go running Python

#211
post #48

- Amusingly, it runs Python 2.7, even though this project started long after Python 3.x came out. - It's a hard-code compiler, not an interpreter written in Go. That implies some restrictions, but the documentation doesn't say much about what they are. PyPy jumps through hoops to make all of Python's self modification at run-time features work, complicating PyPy enormously. Nobody uses that stuff in production code,…

What does "hard-code compiler" mean?

Transpilers with no runtime.

Re: Grumpy: Go running Python

#212

Does anyone know if there is an easy way to get involved in open source projects like this? The readme mentions adding PRs, but as someone that doesn't have much experience working with open source projects like this, I don't even know where to begin. It sounds like an incredible learning opportunity though.

The first stop is usually a CONTRIBUTING.md Here's theirs https://github.com/google/grumpy/blob/master/CONTRIBUTING.md

There's not a ton there. The next place I'd go is open issues: https://github.com/google/grumpy/issues

It looks like at the moment they're mostly random bug reports from people who have tried Grumpy since this announcement, rather than ones filed by people working on Grumpy since before it was made public. So that's a bit trickier.

The last place I'd look is then, the README: https://github.com/google/grumpy not a ton there about ways they wish to have people contribute.

At this point, what I'd do personally is open an issue asking how you can get involved; possibly by improving this documentation on how to get involved!

Anyway, that's what I'd do. Hope that helps!

Re: Grumpy: Go running Python

#213

I tried a simple `http.Get()` example, but the resultant `Response` object appears to not allow access to any of the struct fields as attributes. How does one access a Go object's fields from Python? For example, I want to `io.Copy(os.Stdout, rsp.Body)`.

Unfortunately the native interface is still pretty immature so I can't guarantee things will work as they should. In this case, I think the problem is that you have a *Response object which is not itself a struct. I've rewritten this part of the code a couple times and I think this functionality was lost. I've filed: https://github.com/google/grumpy/issues/13

Re: Grumpy: Go running Python

#214

Earlier quoted context omitted.

> Amusingly, it runs Python 2.7, even though this project started long after Python 3.x came out. Basically, we needed to support a large existing Python 2.7 codebase. See discussion here: https://github.com/google/grumpy/issues/1 > It's a hard-code compiler, not an interpreter written in Go. That implies some restrictions, but the documentation doesn't say much about what they are. PyPy jumps through hoops to make a…

Is there not a single namedtuple in the entire Google codebase? That's strange :o

(1) A grep can identify all the occurrences; a sed might even fix them. (translated to Google internal tools obviously)

(2) Apparently setting a __dict__ key works; they could be implemented like that.

Re: Grumpy: Go running Python

#215
post #5

This seems like an odd engineering choice. Presumably the effort to create a python->go translator would be non-trivial. Why not just start rewriting components into Go, and migrating them out of Python, leaving python as essentially the presentation layer at most?

Creating a new Python runtime in Go is obviously non-trivial, but so is rewriting the heart of YouTube in Go. Heck, YouTube may be a bigger codebase than Python for all I know. And there's a lot more side benefit in a better multithreading Python runtime for Google for other Python code Google has (or hosts), whereas the benefits of a YouTube rewrite are more narrowly limited to YouTube.

Just because the site is popular doesn't mean the codebase is big. It's a simple site. I could probably write YouTube in Go in an afternoon and I don't even know Go.

Re: Grumpy: Go running Python

#216

I tried a simple `http.Get()` example, but the resultant `Response` object appears to not allow access to any of the struct fields as attributes. How does one access a Go object's fields from Python? For example, I want to `io.Copy(os.Stdout, rsp.Body)`.

Unfortunately the native interface is still pretty immature so I can't guarantee things will work as they should. In this case, I think the problem is that you have a *Response object which is not itself a struct. I've rewritten this part of the code a couple times and I think this functionality was lost. I've filed: https://github.com/google/grumpy/issues/13

Whoops, just noticed you (or somebody) had already filed it: https://github.com/google/grumpy/issues/12

Re: Grumpy: Go running Python

#217

Earlier quoted context omitted.

Unfortunately the native interface is still pretty immature so I can't guarantee things will work as they should. In this case, I think the problem is that you have a *Response object which is not itself a struct. I've rewritten this part of the code a couple times and I think this functionality was lost. I've filed: https://github.com/google/grumpy/issues/13

Whoops, just noticed you (or somebody) had already filed it: https://github.com/google/grumpy/issues/12

Yeah, that was me. I should have updated my post here accordingly. Apologies for the inconvenience!

Re: Grumpy: Go running Python

#218

Earlier quoted context omitted.

Whoops, just noticed you (or somebody) had already filed it: https://github.com/google/grumpy/issues/12

Yeah, that was me. I should have updated my post here accordingly. Apologies for the inconvenience!

It's all good. Thanks for filing the issue. I'll get that fixed.

Re: Grumpy: Go running Python

#219
post #181

Earlier quoted context omitted.

I think that that's rather dismissive of a language that runs huge web, scientific, and general purpose applications daily.

It might be, but that it is usually a consequence of not knowing any better or making use of existing libraries. Just like people learned 8-bit BASIC and went on to do business applications and games on it. I went Z80 ASM instead. Personally I would only use Python for shell scripting and advise for using Julia instead. Of course, others see it differently.

Julia? Look, I enjoy playing with Julia, but have you actually used it? Because most of the people I meet who turn up their nose at Python and say nice things about Julia haven't ever used Julia. It's got great potential but has some major gaps and warts, and is just plain dog shit slow for certain things compared to SciPy, which, you may not be aware, is basically C and Fortran code wrapped in Python API.

Re: Grumpy: Go running Python

#220

Earlier quoted context omitted.

Attrs ( https://attrs.readthedocs.io/ ) replaced namedtuple for us (and many others). It's slightly more verbose but allows all class goodness such as methods, attribute validation, etc.

Doesn't work for everything, but you can subclass a namedtuple: from collections import namedtuple class Foo(namedtuple("Foo", "a b c")): @property def sum(self): return self.a + self.b + self.c f = Foo(1,2,3) print f.sum

That doesn't look super awesome to me. I.e. classes or attrs both seem better.
Post reply on HN