All Projects → juliendelplanque → Python3Generator

juliendelplanque / Python3Generator

Licence: MIT license
A toolkit to generate Python 3 source code from Pharo.

Programming Languages

smalltalk
420 projects
HTML
75241 projects

Projects that are alternatives of or similar to Python3Generator

toast
Plugin-driven CLI utility for code generation using Go source as IDL
Stars: ✭ 52 (+108%)
Mutual labels:  ast, code-generation
Ts Type Info
TypeScript AST and code generator [Deprecated]
Stars: ✭ 90 (+260%)
Mutual labels:  ast, code-generation
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+15788%)
Mutual labels:  ast, code-generation
Cgen
C/C++ source generation from an AST
Stars: ✭ 107 (+328%)
Mutual labels:  ast, code-generation
Spoon
Spoon is a metaprogramming library to analyze and transform Java source code (up to Java 15). 🥄 is made with ❤️, 🍻 and ✨. It parses source files to build a well-designed AST with powerful analysis and transformation API.
Stars: ✭ 1,078 (+4212%)
Mutual labels:  ast, code-generation
Ts Morph
TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Stars: ✭ 2,384 (+9436%)
Mutual labels:  ast, code-generation
ast-viewer
🕺TypeScript AST Viewer
Stars: ✭ 39 (+56%)
Mutual labels:  ast
openapi-client
Generate ES6 or Typescript service integration code from an OpenAPI 2 spec
Stars: ✭ 92 (+268%)
Mutual labels:  code-generation
fastobo-py
Faultless AST for Open Biomedical Ontologies in Python.
Stars: ✭ 21 (-16%)
Mutual labels:  ast
aptk
A toolkit project to enable you to build annotation processors more easily
Stars: ✭ 28 (+12%)
Mutual labels:  code-generation
ParNMPC
A Parallel Optimization Toolkit for Nonlinear Model Predictive Control (NMPC)
Stars: ✭ 173 (+592%)
Mutual labels:  code-generation
1c http
Подсистема 1С для работы с HTTP
Stars: ✭ 48 (+92%)
Mutual labels:  code-generation
django-code-generator
Generate code from your Django models for faster development
Stars: ✭ 35 (+40%)
Mutual labels:  code-generation
solregex
Regex compilation to Solidity
Stars: ✭ 37 (+48%)
Mutual labels:  code-generation
scope-analyzer
simple scope analysis for javascript ASTs
Stars: ✭ 20 (-20%)
Mutual labels:  ast
Willow
The Web Interaction Library that eases the burden of creating AJAX-based web applications
Stars: ✭ 41 (+64%)
Mutual labels:  pharo
awesome-pharo-ml
List of projects, books, booklets, papers, and applications related to machine learning, AI, data science in Pharo
Stars: ✭ 56 (+124%)
Mutual labels:  pharo
gdbus-codegen-glibmm
Code generator for C++ D-Bus stubs and proxies using Giomm/Glibmm
Stars: ✭ 21 (-16%)
Mutual labels:  code-generation
gogoAST
The simplest tool to parse/transform/generate code on ast
Stars: ✭ 29 (+16%)
Mutual labels:  ast
cog
Command-line utility that makes it easy to organize a project which uses code generation
Stars: ✭ 15 (-40%)
Mutual labels:  code-generation

Python3Generator

Build Status License Pharo version Pharo version Pharo version

A toolkit to generate Python 3 source code from Pharo.

Install

To be able to execute the Python code generated directly from Pharo, you need to have Python 3 installed on your computer.

Metacello new
    baseline: 'Python3Generator';
    repository: 'github://juliendelplanque/Python3Generator/src';
    load

If your python3 binary is located in a standard path in your file system, it should be fine, else you can manually set the path to python3 binary using for example: P3GInterpreter current pathToPython: '/usr/bin/python3'.

Version management

This project use semantic versionning to define the releases. This mean that each stable release of the project will get associate a version number of the form vX.Y.Z.

  • X define the major version number
  • Y define the minor version number
  • Z define the patch version number

When a release contains only bug fixes, the patch number increase. When the release contains new features backward compatibles, the minor version increase. When the release contains breaking changes, the major version increase.

Thus, it should be safe to depend on a fixed major version and moving minor version of this project.

Examples

Getting os information in /tmp/os.json file

instr := P3GInstructionsList new.

json := 'json' asP3GIdentifier.
file := 'file' asP3GIdentifier.
os := 'os' asP3GIdentifier.

instr addAll: {
    json import.
    os import.
    file <- ('open' asP3GIdentifier callWith: #('/tmp/osp3g.json' 'w')).
    (file=>#write) callWith: { (json=>#dumps) callWith: {{
                                                'os' -> (os=>#name).
                                                'uname' -> (os=>#uname) call } asDictionary} }.
    ((file=>#close) call)
}.

instr execute.

Open a Qt window using PyQt4

"instructions will hold the instructions of the program we are going to build."
instructions := P3GInstructionsList new.

"Import sys and PyQt."
sys := 'sys' asP3GIdentifier.

pyqt := 'PyQt4' asP3GIdentifier => 'QtGui'.
instructions
    add: sys import;
    add: pyqt import.

"Instantiate Qt App."
app := 'app' asP3GIdentifier.
instructions
    add: app <- ((pyqt => 'QApplication') callWith: #(())).

"Create a simple window with a progress bar."
w  := 'w' asP3GIdentifier.
instructions
    add: w <- (pyqt => 'QMainWindow') call;
    add: (((w => 'statusBar') call => 'showMessage') callWith: #('Ready'));
    add: ((w => 'setGeometry') callWith: #(300 300 250 150));
    add: (( w => 'setWindowTitle') callWith: #(Statusbar));
    add: (w => 'show') call;
    add: ((sys => 'exit') callWith: { (app => 'exec_') call }).

"Execute the program built (you can inspect instructions to see the source code)."
instructions execute.

Plot an histogram with MatplotLib

Remark: To really use MatplotLib from Pharo, I created the MatplotLibBridge project which provides an higher lever interface.

numpy := 'numpy' asP3GIdentifier.
mlab := 'matplotlib' asP3GIdentifier=>#mlab.
pyplot := 'matplotlib' asP3GIdentifier=>#pyplot.

instr := P3GInstructionsList new.

instr addAll: {
    "Import modules."
    numpy import.
    mlab import.
    pyplot import.

    "Set seed for random."
    (numpy=>#random=>#seed) callWith: #(0).

    "Example data"
    #mu asP3GIdentifier <- 100.
    #sigma asP3GIdentifier <- 15.
    #x asP3GIdentifier <- (#mu asP3GIdentifier + (#sigma asP3GIdentifier * ((numpy=>#random=>#randn) callWith: #(437)))).

    #num_bin asP3GIdentifier <- 50.

    #res asP3GIdentifier <- (pyplot=>#subplots) call.
    #fig asP3GIdentifier <- (#res asP3GIdentifier at: 0).
    #ax asP3GIdentifier <- (#res asP3GIdentifier at: 1).

    "Plot histogram of data."
    #res asP3GIdentifier <- ((#ax asP3GIdentifier=>#hist) callWith: {#x asP3GIdentifier.#num_bin asP3GIdentifier} with: {'normed' -> 1 } asDictionary).
    #bins asP3GIdentifier <- (#res asP3GIdentifier at: 1).

    "Add a 'best fit line'"
    #y asP3GIdentifier <- ((mlab=>#normpdf) callWith: {#bins asP3GIdentifier . #mu asP3GIdentifier . #sigma asP3GIdentifier}).
    (#ax asP3GIdentifier=>#plot) callWith: { #bins asP3GIdentifier . #y asP3GIdentifier . '--' }.

    (pyplot=>#show) call
 }.

instr execute

Python3Generator users

You are using Python3Generator and want your project listed here? Open a pull request.

Acknowledgement

  • Thanks to Alejandro Infante for his contribution to this project (based on his work on Python3Bridge that you should check by the way, it is a nice complement to P3G).
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].