{"id":15107620,"url":"https://github.com/juliendelplanque/python3generator","last_synced_at":"2025-07-04T18:41:42.040Z","repository":{"id":53536670,"uuid":"78302136","full_name":"juliendelplanque/Python3Generator","owner":"juliendelplanque","description":"A toolkit to generate Python 3 source code from Pharo.","archived":false,"fork":false,"pushed_at":"2024-02-15T12:41:27.000Z","size":152,"stargazers_count":26,"open_issues_count":2,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-30T17:11:17.507Z","etag":null,"topics":["ast","code-generation","generator","pharo","python3"],"latest_commit_sha":null,"homepage":null,"language":"Smalltalk","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/juliendelplanque.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-07T20:31:50.000Z","updated_at":"2023-03-08T19:41:57.000Z","dependencies_parsed_at":"2024-08-03T17:13:05.845Z","dependency_job_id":null,"html_url":"https://github.com/juliendelplanque/Python3Generator","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendelplanque%2FPython3Generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendelplanque%2FPython3Generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendelplanque%2FPython3Generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendelplanque%2FPython3Generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliendelplanque","download_url":"https://codeload.github.com/juliendelplanque/Python3Generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237769067,"owners_count":19363250,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","code-generation","generator","pharo","python3"],"created_at":"2024-09-25T21:40:29.169Z","updated_at":"2025-02-08T06:30:42.019Z","avatar_url":"https://github.com/juliendelplanque.png","language":"Smalltalk","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python3Generator\n[![Build Status](https://travis-ci.org/juliendelplanque/Python3Generator.svg?branch=master)](https://travis-ci.org/juliendelplanque/Python3Generator)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/juliendelplanque/Python3Generator/master/LICENSE)\n[![Pharo version](https://img.shields.io/badge/Pharo-6.1-%23aac9ff.svg)](https://pharo.org/download)\n[![Pharo version](https://img.shields.io/badge/Pharo-7.0-%23aac9ff.svg)](https://pharo.org/download)\n[![Pharo version](https://img.shields.io/badge/Pharo-8.0-%23aac9ff.svg)](https://pharo.org/download)\n\nA toolkit to generate Python 3 source code from Pharo.\n\n- [Python3Generator](#python3generator)\n  * [Install](#install)\n  * [Version management](#version-management)\n  * [Examples](#examples)\n- [Python3Generator users](#python3generator-users)\n- [Acknowledgement](#acknowledgement)\n\n## Install\nTo be able to execute the Python code generated directly from Pharo, you need to have Python 3 installed on your computer.\n\n```\nMetacello new\n    baseline: 'Python3Generator';\n    repository: 'github://juliendelplanque/Python3Generator/src';\n    load\n```\n\nIf 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'`.\n\n## Version management \n\nThis 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`. \n\n- **X** define the major version number\n- **Y** define the minor version number \n- **Z** define the patch version number\n\nWhen 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. \n\nThus, it should be safe to depend on a fixed major version and moving minor version of this project.\n\n## Examples\n### Getting os information in `/tmp/os.json` file\n```\ninstr := P3GInstructionsList new.\n\njson := 'json' asP3GIdentifier.\nfile := 'file' asP3GIdentifier.\nos := 'os' asP3GIdentifier.\n\ninstr addAll: {\n    json import.\n    os import.\n    file \u003c- ('open' asP3GIdentifier callWith: #('/tmp/osp3g.json' 'w')).\n    (file=\u003e#write) callWith: { (json=\u003e#dumps) callWith: {{\n                                                'os' -\u003e (os=\u003e#name).\n                                                'uname' -\u003e (os=\u003e#uname) call } asDictionary} }.\n    ((file=\u003e#close) call)\n}.\n\ninstr execute.\n```\n\n### Open a Qt window using PyQt4\n```\n\"instructions will hold the instructions of the program we are going to build.\"\ninstructions := P3GInstructionsList new.\n\n\"Import sys and PyQt.\"\nsys := 'sys' asP3GIdentifier.\n\npyqt := 'PyQt4' asP3GIdentifier =\u003e 'QtGui'.\ninstructions\n    add: sys import;\n    add: pyqt import.\n\n\"Instantiate Qt App.\"\napp := 'app' asP3GIdentifier.\ninstructions\n    add: app \u003c- ((pyqt =\u003e 'QApplication') callWith: #(())).\n\n\"Create a simple window with a progress bar.\"\nw  := 'w' asP3GIdentifier.\ninstructions\n    add: w \u003c- (pyqt =\u003e 'QMainWindow') call;\n    add: (((w =\u003e 'statusBar') call =\u003e 'showMessage') callWith: #('Ready'));\n    add: ((w =\u003e 'setGeometry') callWith: #(300 300 250 150));\n    add: (( w =\u003e 'setWindowTitle') callWith: #(Statusbar));\n    add: (w =\u003e 'show') call;\n    add: ((sys =\u003e 'exit') callWith: { (app =\u003e 'exec_') call }).\n\n\"Execute the program built (you can inspect instructions to see the source code).\"\ninstructions execute.\n```\n\n### Plot an histogram with MatplotLib\n\u003e Remark: To really use MatplotLib from Pharo, I created the [MatplotLibBridge](https://github.com/juliendelplanque/MatplotLibBridge) project which provides an higher lever interface.\n\n```\nnumpy := 'numpy' asP3GIdentifier.\nmlab := 'matplotlib' asP3GIdentifier=\u003e#mlab.\npyplot := 'matplotlib' asP3GIdentifier=\u003e#pyplot.\n\ninstr := P3GInstructionsList new.\n\ninstr addAll: {\n    \"Import modules.\"\n    numpy import.\n    mlab import.\n    pyplot import.\n\n    \"Set seed for random.\"\n    (numpy=\u003e#random=\u003e#seed) callWith: #(0).\n\n    \"Example data\"\n    #mu asP3GIdentifier \u003c- 100.\n    #sigma asP3GIdentifier \u003c- 15.\n    #x asP3GIdentifier \u003c- (#mu asP3GIdentifier + (#sigma asP3GIdentifier * ((numpy=\u003e#random=\u003e#randn) callWith: #(437)))).\n\n    #num_bin asP3GIdentifier \u003c- 50.\n\n    #res asP3GIdentifier \u003c- (pyplot=\u003e#subplots) call.\n    #fig asP3GIdentifier \u003c- (#res asP3GIdentifier at: 0).\n    #ax asP3GIdentifier \u003c- (#res asP3GIdentifier at: 1).\n\n    \"Plot histogram of data.\"\n    #res asP3GIdentifier \u003c- ((#ax asP3GIdentifier=\u003e#hist) callWith: {#x asP3GIdentifier.#num_bin asP3GIdentifier} with: {'normed' -\u003e 1 } asDictionary).\n    #bins asP3GIdentifier \u003c- (#res asP3GIdentifier at: 1).\n\n    \"Add a 'best fit line'\"\n    #y asP3GIdentifier \u003c- ((mlab=\u003e#normpdf) callWith: {#bins asP3GIdentifier . #mu asP3GIdentifier . #sigma asP3GIdentifier}).\n    (#ax asP3GIdentifier=\u003e#plot) callWith: { #bins asP3GIdentifier . #y asP3GIdentifier . '--' }.\n\n    (pyplot=\u003e#show) call\n }.\n\ninstr execute\n```\n\n# Python3Generator users\n- [MatplotLibBridge](https://github.com/juliendelplanque/MatplotLibBridge)\n- [PythonBridge](https://objectprofile.github.io/PythonBridge) ([github repository](https://github.com/ObjectProfile/PythonBridge))\n\n\u003e You are using Python3Generator and want your project listed here? Open a pull request.\n\n# Acknowledgement\n- Thanks to [Alejandro Infante](https://github.com/alejandroinfante) for his contribution to this project (based on his work on [Python3Bridge](https://github.com/ObjectProfile/PythonBridge) that you should check by the way, it is a nice complement to P3G).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliendelplanque%2Fpython3generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliendelplanque%2Fpython3generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliendelplanque%2Fpython3generator/lists"}