Comments (6)
I've started to standardize a structure for Python projects under Grumpy. The basis for this is:
- Python files that are to be compiled under Grumpy should be staged in
GOPATH/src/__python__
- A rudimentary tool called genmake can then traverse this path to generate a makefile for building Go packages
- grumpc will now search
GOPATH/src/__python__
dirs for Python modules to import as Go packages in the generated source code
In principle, this means that you can pretty easily copy sources from a Python project and build and use the Go packages. Assuming you have a GOPATH set up and grumpy tools on the PATH, something like this could work:
git clone https://github.com/PyMySQL/PyMySQL
cp -R PyMySQL/pymysql $GOPATH/src/__python__
genmake $GOPATH > Makefile
make
echo 'import pymysql; print pymysql.VERSION' | grumprun
(Note: PyMySQL is still not supported, so this doesn't actually compile yet.)
Long term I'd like to wrap these steps into something simpler, along the lines of:
grumpy get https://github.com/PyMySQL/PyMySQL
But there are a bunch of steps to get there:
- Integrate the existing toolchain into a
grumpy
binary that supports a bunch of subcommands, much like thego
binary. - Implement
grumpy genmake
that wraps the current genmake tool. - Support
grumpy fetch
that will grab Python files and import them intoGOPATH/src/__python__
. To start, it can just support directories and recurisvely copy .py files over. - Wrap up
grumpy fetch
,grumpy genmake
and themake
step into a convenientgrumpy get
subcommand. - Support for projects that use setuptools including finding sources within a project directory, determining dependencies, etc.
I'd also fold some of the other tools into the grumpy binary as subcommands including grumprun, grumpc and pydeps.
from grumpy.
That's a very cool idea. I have two questions.
-
What should Grumpy assume is in the PyMySQL dir? Should we assume subdirs with init.py are root packages and traverse them for all the .py files? That would seem to work for PyMySQL which has
pymysql/__init__.py
. Would it work for most libraries? -
Currently the Python
import pymysql
would look for the Go package grumpy/lib/pymysql. Thus your output directory $GOPATH/src/github.com/PyMySQL/PyMySQL won't work as you've described it without some changes. Does it make more sense to merge all the Go packages into one dir like grumpy/lib? Or should grumpc have some configuration so that when generating the .go files to mapimport pymysql
to the Go package path github.com/PyMySQL/PyMySQL?
Another option would be to assume that the packages of interest are in the PYTHONPATH and then support the following:
grumpy/tools/grumpc --read pymysql
It could find the pymysql package by looking through the PYTHONPATH and then dump that into $GOPATH/src/grumpy/lib/pymysql. Maybe use $GOPATH/src/__py__
as the root dir by convention instead of grumpy/lib.
Are there other approaches we should consider? Is there a way that we could adopt something more like go build
where it automatically pulls in dependencies?
from grumpy.
Perhaps find already installed Python packages, grab and compile those, then bundle them together for projects that use external libraries specified in a requirements.txt
? Then you could go build
CLI projects that use things like twisted, etc. and quickly compile them into a native binary through transpiled Go code?
As far as the init.py problem goes, it's probably best to stick to Python's way of module searching to make as many libraries as possible compatible
from grumpy.
Maybe you could implement and use setuptools find_packages.
In the case of pymysql and most other libraries with this approach you could use the setup.py file for exploring the library.
PYMSQL setup.py is something like:
from setuptools import setup, find_packages
setup(
...
packages=find_packages()
...
)
from grumpy.
That sounds awesome @trotterdylan!
from grumpy.
The standard way to install packages in the python world is the pip
tool, so I guess having a grumpy pip
subcommand, as close to a drop-in replacement of pip
would make more sense than a go-like construct like grumpy get
:
grumpy pip install foo
grumpy pip install foo[bar]
These should entirely implement the pip install
workflow:
- Python modules that are not meant to deploy binaries should just be recursively installed under the global
$GOPATH/src/__python__
- compile the binaries normally generated by pip's
setup.py
as program entrypoints and drop them into$GOPATH/bin
from grumpy.
Related Issues (20)
- expected 'IDENT', found 'INT' 7 HOT 2
- <unknown>:1:1-1:2: fatal: unexpected .: expected (, +, -, @, [, `, assert, break, class, complex, continue, def, del, exec, float, for, from, global, ident, if, import, int, lambda, newline, nonlocal, not, pass, print, raise, return, strbegin, try, while, with, yield, { or ~ ../third_party/stdlib/StringIO.py
- Implement __getattribuate__ HOT 2
- Build in windows
- js to golang ? HOT 2
- Should resolve ImportError on run time, not compile time HOT 1
- ZeroDivisionError
- conversion type not yet supported: c
- Asking HOT 2
- this is not working. because bool(AssertionError) is true
- Active fork of grumpy HOT 22
- How to import and call function(written in python and transferred into go by grumpc) in go? HOT 1
- Failed to import some python std libs(e.g. json) in python code and then called in go code
- question: is grumpy dead? HOT 1
- Rebuild tool for automated refactoring
- Fix simple typo: implementating -> implementing HOT 1
- Question : does grumpy supports only python2.7 codes? HOT 2
- Is this project abandoned? HOT 3
- make: *** No rule to make target 'run'. Stop. HOT 1
- Let's try it, python bindings cgo-less
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grumpy.