├── .dockerignore ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── app.py ├── front ├── .gitignore ├── README.md ├── package.json ├── public │ ├── favicon.png │ └── index.html └── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── index.css │ ├── index.js │ ├── logo.svg │ └── snippets.js ├── parse.py └── requirements.txt /.dockerignore: -------------------------------------------------------------------------------- 1 | front/node_modules 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | **/node_modules 3 | VENV 4 | npm-debug.log 5 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:2.7-alpine 2 | 3 | WORKDIR /opt/pyast 4 | ADD . /opt/pyast 5 | 6 | RUN apk update && \ 7 | apk add g++ make && \ 8 | apk add nodejs && \ 9 | pip install -r requirements.txt && \ 10 | cd /opt/pyast/front && \ 11 | npm set progress=false && \ 12 | npm install && \ 13 | npm run build 14 | 15 | EXPOSE 4361 16 | 17 | CMD ["gunicorn", "app:app", "-w" "4", "-b", "'0.0.0.0:4361'"] 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python-ast-explorer - a simple AST visualizer 2 | 3 | The illustrous code behind [python-ast-explorer.com](https://python-ast-explorer.com), you can touch it. 4 | 5 | ## Making sense of it 6 | 7 | See the `Dockerfile` for steps to get it up and running. It's basically a pretty bare `react-create-app` artifact that talks to a hacked up Flask app via repeated, desperate calls to `/api/_parse`. 8 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask import request 3 | from flask import jsonify 4 | from flask import send_file 5 | 6 | from parse import make_ast 7 | 8 | app = Flask(__name__, static_folder='front/build/static') 9 | 10 | @app.route('/') 11 | def index(): 12 | return send_file('front/build/index.html') 13 | 14 | @app.route('/favicon.ico') 15 | def favicon_ico(): 16 | return send_file('front/build/favicon.png') 17 | 18 | @app.route('/api/_parse', methods=['POST']) 19 | def api_parse(): 20 | body = request.get_data() 21 | try: 22 | return jsonify({ 'ast': make_ast(body) }) 23 | except Exception as e: 24 | return jsonify({ 'ast': { 'error': 'yes', 'why_error?': 'it doesn\'t compile, yo' }}) 25 | 26 | @app.after_request 27 | def after_request(response): 28 | response.headers.add('Access-Control-Allow-Origin', '*') 29 | response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') 30 | response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE') 31 | return response 32 | 33 | if __name__ == "__main__": 34 | app.debug = True 35 | app.run('0.0.0.0', 4361) 36 | -------------------------------------------------------------------------------- /front/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | node_modules 5 | 6 | # testing 7 | coverage 8 | 9 | # production 10 | build 11 | 12 | # misc 13 | .DS_Store 14 | .env 15 | npm-debug.log 16 | -------------------------------------------------------------------------------- /front/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). 2 | 3 | Below you will find some information on how to perform common tasks. 4 | You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md). 5 | 6 | ## Table of Contents 7 | 8 | - [Updating to New Releases](#updating-to-new-releases) 9 | - [Sending Feedback](#sending-feedback) 10 | - [Folder Structure](#folder-structure) 11 | - [Available Scripts](#available-scripts) 12 | - [npm start](#npm-start) 13 | - [npm test](#npm-test) 14 | - [npm run build](#npm-run-build) 15 | - [npm run eject](#npm-run-eject) 16 | - [Displaying Lint Output in the Editor](#displaying-lint-output-in-the-editor) 17 | - [Installing a Dependency](#installing-a-dependency) 18 | - [Importing a Component](#importing-a-component) 19 | - [Adding a Stylesheet](#adding-a-stylesheet) 20 | - [Post-Processing CSS](#post-processing-css) 21 | - [Adding Images and Fonts](#adding-images-and-fonts) 22 | - [Using the `public` Folder](#using-the-public-folder) 23 | - [Adding Bootstrap](#adding-bootstrap) 24 | - [Adding Flow](#adding-flow) 25 | - [Adding Custom Environment Variables](#adding-custom-environment-variables) 26 | - [Can I Use Decorators?](#can-i-use-decorators) 27 | - [Integrating with a Node Backend](#integrating-with-a-node-backend) 28 | - [Proxying API Requests in Development](#proxying-api-requests-in-development) 29 | - [Using HTTPS in Development](#using-https-in-development) 30 | - [Generating Dynamic `` Tags on the Server](#generating-dynamic-meta-tags-on-the-server) 31 | - [Running Tests](#running-tests) 32 | - [Filename Conventions](#filename-conventions) 33 | - [Command Line Interface](#command-line-interface) 34 | - [Version Control Integration](#version-control-integration) 35 | - [Writing Tests](#writing-tests) 36 | - [Testing Components](#testing-components) 37 | - [Using Third Party Assertion Libraries](#using-third-party-assertion-libraries) 38 | - [Initializing Test Environment](#initializing-test-environment) 39 | - [Focusing and Excluding Tests](#focusing-and-excluding-tests) 40 | - [Coverage Reporting](#coverage-reporting) 41 | - [Continuous Integration](#continuous-integration) 42 | - [Disabling jsdom](#disabling-jsdom) 43 | - [Experimental Snapshot Testing](#experimental-snapshot-testing) 44 | - [Deployment](#deployment) 45 | - [Building for Relative Paths](#building-for-relative-paths) 46 | - [GitHub Pages](#github-pages) 47 | - [Heroku](#heroku) 48 | - [Modulus](#modulus) 49 | - [Now](#now) 50 | - [Surge](#surge) 51 | - [Something Missing?](#something-missing) 52 | 53 | ## Updating to New Releases 54 | 55 | Create React App is divided into two packages: 56 | 57 | * `create-react-app` is a global command-line utility that you use to create new projects. 58 | * `react-scripts` is a development dependency in the generated projects (including this one). 59 | 60 | You almost never need to update `create-react-app` itself: it’s delegates all the setup to `react-scripts`. 61 | 62 | When you run `create-react-app`, it always creates the project with the latest version of `react-scripts` so you’ll get all the new features and improvements in newly created apps automatically. 63 | 64 | To update an existing project to a new version of `react-scripts`, [open the changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md), find the version you’re currently on (check `package.json` in this folder if you’re not sure), and apply the migration instructions for the newer versions. 65 | 66 | In most cases bumping the `react-scripts` version in `package.json` and running `npm install` in this folder should be enough, but it’s good to consult the [changelog](https://github.com/facebookincubator/create-react-app/blob/master/CHANGELOG.md) for potential breaking changes. 67 | 68 | We commit to keeping the breaking changes minimal so you can upgrade `react-scripts` painlessly. 69 | 70 | ## Sending Feedback 71 | 72 | We are always open to [your feedback](https://github.com/facebookincubator/create-react-app/issues). 73 | 74 | ## Folder Structure 75 | 76 | After creation, your project should look like this: 77 | 78 | ``` 79 | my-app/ 80 | README.md 81 | node_modules/ 82 | package.json 83 | public/ 84 | index.html 85 | favicon.ico 86 | src/ 87 | App.css 88 | App.js 89 | App.test.js 90 | index.css 91 | index.js 92 | logo.svg 93 | ``` 94 | 95 | For the project to build, **these files must exist with exact filenames**: 96 | 97 | * `public/index.html` is the page template; 98 | * `src/index.js` is the JavaScript entry point. 99 | 100 | You can delete or rename the other files. 101 | 102 | You may create subdirectories inside `src`. For faster rebuilds, only files inside `src` are processed by Webpack. 103 | You need to **put any JS and CSS files inside `src`**, or Webpack won’t see them. 104 | 105 | Only files inside `public` can be used from `public/index.html`. 106 | Read instructions below for using assets from JavaScript and HTML. 107 | 108 | You can, however, create more top-level directories. 109 | They will not be included in the production build so you can use them for things like documentation. 110 | 111 | ## Available Scripts 112 | 113 | In the project directory, you can run: 114 | 115 | ### `npm start` 116 | 117 | Runs the app in the development mode.
118 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 119 | 120 | The page will reload if you make edits.
121 | You will also see any lint errors in the console. 122 | 123 | ### `npm test` 124 | 125 | Launches the test runner in the interactive watch mode. 126 | See the section about [running tests](#running-tests) for more information. 127 | 128 | ### `npm run build` 129 | 130 | Builds the app for production to the `build` folder.
131 | It correctly bundles React in production mode and optimizes the build for the best performance. 132 | 133 | The build is minified and the filenames include the hashes.
134 | Your app is ready to be deployed! 135 | 136 | ### `npm run eject` 137 | 138 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 139 | 140 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 141 | 142 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 143 | 144 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 145 | 146 | ## Displaying Lint Output in the Editor 147 | 148 | >Note: this feature is available with `react-scripts@0.2.0` and higher. 149 | 150 | Some editors, including Sublime Text, Atom, and Visual Studio Code, provide plugins for ESLint. 151 | 152 | They are not required for linting. You should see the linter output right in your terminal as well as the browser console. However, if you prefer the lint results to appear right in your editor, there are some extra steps you can do. 153 | 154 | You would need to install an ESLint plugin for your editor first. 155 | 156 | >**A note for Atom `linter-eslint` users** 157 | 158 | >If you are using the Atom `linter-eslint` plugin, make sure that **Use global ESLint installation** option is checked: 159 | 160 | > 161 | 162 | Then add this block to the `package.json` file of your project: 163 | 164 | ```js 165 | { 166 | // ... 167 | "eslintConfig": { 168 | "extends": "react-app" 169 | } 170 | } 171 | ``` 172 | 173 | Finally, you will need to install some packages *globally*: 174 | 175 | ```sh 176 | npm install -g eslint-config-react-app@0.2.1 eslint@3.5.0 babel-eslint@6.1.2 eslint-plugin-react@6.3.0 eslint-plugin-import@1.12.0 eslint-plugin-jsx-a11y@2.2.2 eslint-plugin-flowtype@2.18.1 177 | ``` 178 | 179 | We recognize that this is suboptimal, but it is currently required due to the way we hide the ESLint dependency. The ESLint team is already [working on a solution to this](https://github.com/eslint/eslint/issues/3458) so this may become unnecessary in a couple of months. 180 | 181 | ## Installing a Dependency 182 | 183 | The generated project includes React and ReactDOM as dependencies. It also includes a set of scripts used by Create React App as a development dependency. You may install other dependencies (for example, React Router) with `npm`: 184 | 185 | ``` 186 | npm install --save 187 | ``` 188 | 189 | ## Importing a Component 190 | 191 | This project setup supports ES6 modules thanks to Babel. 192 | While you can still use `require()` and `module.exports`, we encourage you to use [`import` and `export`](http://exploringjs.com/es6/ch_modules.html) instead. 193 | 194 | For example: 195 | 196 | ### `Button.js` 197 | 198 | ```js 199 | import React, { Component } from 'react'; 200 | 201 | class Button extends Component { 202 | render() { 203 | // ... 204 | } 205 | } 206 | 207 | export default Button; // Don’t forget to use export default! 208 | ``` 209 | 210 | ### `DangerButton.js` 211 | 212 | 213 | ```js 214 | import React, { Component } from 'react'; 215 | import Button from './Button'; // Import a component from another file 216 | 217 | class DangerButton extends Component { 218 | render() { 219 | return