├── .gitignore ├── .travis.yml ├── AUTHORS.rst ├── CONTRIBUTING.rst ├── HISTORY.rst ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.rst ├── applied-patches └── patch1.patch ├── docs ├── Makefile ├── authors.rst ├── conf.py ├── contributing.rst ├── history.rst ├── index.rst ├── installation.rst ├── make.bat ├── readme.rst └── usage.rst ├── examples ├── basic_code.dot ├── basic_code.pdf ├── basic_code.png ├── basic_code.txt ├── nested_if.dot ├── nested_if.pdf ├── nested_if.png └── nested_if.txt ├── flowgen ├── __init__.py ├── __main__.py ├── core.py ├── graph.py ├── language.py └── options.py ├── requirements_dev.txt ├── setup.cfg ├── setup.py ├── tests ├── __init__.py ├── graphs │ ├── basic_code.dot │ ├── basic_code.txt │ ├── nested_if.dot │ └── nested_if.txt ├── test_graph.py └── test_language.py └── tox.ini /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | 91 | #2to3 files 92 | *.bak 93 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Config file for automatic testing at travis-ci.org 2 | # This file will be regenerated if you run travis_pypi_setup.py 3 | 4 | language: python 5 | python: 3.5 6 | 7 | env: 8 | - TOXENV=py35 9 | - TOXENV=py34 10 | - TOXENV=py33 11 | - TOXENV=py27 12 | - TOXENV=pypy 13 | 14 | # command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors 15 | install: pip install -U tox 16 | 17 | # command to run tests, e.g. python setup.py test 18 | script: tox -e ${TOXENV} 19 | 20 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | Credits 3 | ======= 4 | 5 | Development Lead 6 | ---------------- 7 | 8 | * Adam Dobrawy 9 | 10 | Contributors 11 | ------------ 12 | 13 | None yet. Why not be the first? 14 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: shell 2 | 3 | ============ 4 | Contributing 5 | ============ 6 | 7 | Contributions are welcome, and they are greatly appreciated! Every 8 | little bit helps, and credit will always be given. 9 | 10 | You can contribute in many ways: 11 | 12 | Types of Contributions 13 | ---------------------- 14 | 15 | Report Bugs 16 | ~~~~~~~~~~~ 17 | 18 | Report bugs at https://github.com/ad-m/flowgen/issues. 19 | 20 | If you are reporting a bug, please include: 21 | 22 | * Your operating system name and version. 23 | * Any details about your local setup that might be helpful in troubleshooting. 24 | * Detailed steps to reproduce the bug. 25 | 26 | Fix Bugs 27 | ~~~~~~~~ 28 | 29 | Look through the GitHub issues for bugs. Anything tagged with "bug" 30 | and "help wanted" is open to whoever wants to implement it. 31 | 32 | Implement Features 33 | ~~~~~~~~~~~~~~~~~~ 34 | 35 | Look through the GitHub issues for features. Anything tagged with "enhancement" 36 | and "help wanted" is open to whoever wants to implement it. 37 | 38 | Write Documentation 39 | ~~~~~~~~~~~~~~~~~~~ 40 | 41 | FlowGen could always use more documentation, whether as part of the 42 | official FlowGen docs, in docstrings, or even on the web in blog posts, 43 | articles, and such. 44 | 45 | Submit Feedback 46 | ~~~~~~~~~~~~~~~ 47 | 48 | The best way to send feedback is to file an issue at https://github.com/ad-m/flowgen/issues. 49 | 50 | If you are proposing a feature: 51 | 52 | * Explain in detail how it would work. 53 | * Keep the scope as narrow as possible, to make it easier to implement. 54 | * Remember that this is a volunteer-driven project, and that contributions 55 | are welcome :) 56 | 57 | Get Started! 58 | ------------ 59 | 60 | Ready to contribute? Here's how to set up `flowgen` for local development. 61 | 62 | 1. Fork the `flowgen` repo on GitHub. 63 | 2. Clone your fork locally:: 64 | 65 | $ git clone git@github.com:your_name_here/flowgen.git 66 | 67 | 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: 68 | 69 | $ mkvirtualenv flowgen 70 | $ cd flowgen/ 71 | $ python setup.py develop 72 | 73 | 4. Create a branch for local development:: 74 | 75 | $ git checkout -b name-of-your-bugfix-or-feature 76 | 77 | Now you can make your changes locally. 78 | 79 | 5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: 80 | 81 | $ flake8 flowgen tests 82 | $ python setup.py test or py.test 83 | $ tox 84 | 85 | To get flake8 and tox, just pip install them into your virtualenv. 86 | 87 | 6. Commit your changes and push your branch to GitHub:: 88 | 89 | $ git add . 90 | $ git commit -m "Your detailed description of your changes." 91 | $ git push origin name-of-your-bugfix-or-feature 92 | 93 | 7. Submit a pull request through the GitHub website. 94 | 95 | Pull Request Guidelines 96 | ----------------------- 97 | 98 | Before you submit a pull request, check that it meets these guidelines: 99 | 100 | 1. The pull request should include tests. 101 | 2. If the pull request adds functionality, the docs should be updated. Put 102 | your new functionality into a function with a docstring, and add the 103 | feature to the list in README.rst. 104 | 3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5, and for PyPy. Check 105 | https://travis-ci.org/ad-m/flowgen/pull_requests 106 | and make sure that the tests pass for all supported Python versions. 107 | 108 | Tips 109 | ---- 110 | 111 | To run a subset of tests:: 112 | 113 | 114 | $ python -m unittest tests.test_flowgen 115 | -------------------------------------------------------------------------------- /HISTORY.rst: -------------------------------------------------------------------------------- 1 | ======= 2 | History 3 | ======= 4 | 5 | 0.1.0 (2017-01-09) 6 | ------------------ 7 | 8 | * First release on PyPI. 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | MIT License 3 | 4 | Copyright (c) 2017, Adam Dobrawy 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 9 | 10 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 11 | 12 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | 2 | include AUTHORS.rst 3 | 4 | include CONTRIBUTING.rst 5 | include HISTORY.rst 6 | include LICENSE 7 | include README.rst 8 | 9 | recursive-include tests * 10 | recursive-exclude * __pycache__ 11 | recursive-exclude * *.py[co] 12 | 13 | recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean clean-test clean-pyc clean-build docs help 2 | .DEFAULT_GOAL := help 3 | define BROWSER_PYSCRIPT 4 | import os, webbrowser, sys 5 | try: 6 | from urllib import pathname2url 7 | except: 8 | from urllib.request import pathname2url 9 | 10 | webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) 11 | endef 12 | export BROWSER_PYSCRIPT 13 | 14 | define PRINT_HELP_PYSCRIPT 15 | import re, sys 16 | 17 | for line in sys.stdin: 18 | match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) 19 | if match: 20 | target, help = match.groups() 21 | print("%-20s %s" % (target, help)) 22 | endef 23 | export PRINT_HELP_PYSCRIPT 24 | BROWSER := python -c "$$BROWSER_PYSCRIPT" 25 | 26 | help: 27 | @python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) 28 | 29 | clean: clean-build clean-pyc clean-test ## remove all build, test, coverage and Python artifacts 30 | 31 | 32 | clean-build: ## remove build artifacts 33 | rm -fr build/ 34 | rm -fr dist/ 35 | rm -fr .eggs/ 36 | find . -name '*.egg-info' -exec rm -fr {} + 37 | find . -name '*.egg' -exec rm -f {} + 38 | 39 | clean-pyc: ## remove Python file artifacts 40 | find . -name '*.pyc' -exec rm -f {} + 41 | find . -name '*.pyo' -exec rm -f {} + 42 | find . -name '*~' -exec rm -f {} + 43 | find . -name '__pycache__' -exec rm -fr {} + 44 | 45 | clean-test: ## remove test and coverage artifacts 46 | rm -fr .tox/ 47 | rm -f .coverage 48 | rm -fr htmlcov/ 49 | 50 | lint: ## check style with flake8 51 | flake8 flowgen tests 52 | 53 | test: ## run tests quickly with the default Python 54 | 55 | python setup.py test 56 | 57 | test-all: ## run tests on every Python version with tox 58 | tox 59 | 60 | coverage: ## check code coverage quickly with the default Python 61 | 62 | coverage run --source flowgen setup.py test 63 | 64 | coverage report -m 65 | coverage html 66 | $(BROWSER) htmlcov/index.html 67 | 68 | docs: ## generate Sphinx HTML documentation, including API docs 69 | rm -f docs/flowgen.rst 70 | rm -f docs/modules.rst 71 | sphinx-apidoc -o docs/ flowgen 72 | $(MAKE) -C docs clean 73 | $(MAKE) -C docs html 74 | $(BROWSER) docs/_build/html/index.html 75 | 76 | servedocs: docs ## compile the docs watching for changes 77 | watchmedo shell-command -p '*.rst' -c '$(MAKE) -C docs html' -R -D . 78 | 79 | release: clean ## package and upload a release 80 | python setup.py sdist upload 81 | python setup.py bdist_wheel upload 82 | 83 | dist: clean ## builds source and wheel package 84 | python setup.py sdist 85 | python setup.py bdist_wheel 86 | ls -l dist 87 | 88 | install: clean ## install the package to the active Python's site-packages 89 | python setup.py install 90 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | =============================== 2 | FlowGen 3 | =============================== 4 | 5 | 6 | .. image:: https://img.shields.io/pypi/v/flowgen.svg 7 | :target: https://pypi.python.org/pypi/flowgen 8 | 9 | .. image:: https://img.shields.io/travis/ad-m/flowgen.svg 10 | :target: https://travis-ci.org/ad-m/flowgen 11 | 12 | .. image:: https://readthedocs.org/projects/flowgen/badge/?version=latest 13 | :target: https://flowgen.readthedocs.io/en/latest/?badge=latest 14 | :alt: Documentation Status 15 | 16 | .. image:: https://pyup.io/repos/github/ad-m/flowgen/shield.svg 17 | :target: https://pyup.io/repos/github/ad-m/flowgen/ 18 | :alt: Updates 19 | 20 | 21 | code to flowchart converter. 22 | 23 | 24 | * Free software: MIT license 25 | * Documentation: https://flowgen.readthedocs.io. 26 | 27 | 28 | Features 29 | -------- 30 | 31 | * draw flowchart from pseudocode 32 | 33 | Example 34 | -------- 35 | 36 | It's simple to draw diagram based on simple pseudocode like:: 37 | 38 | Hello Smith; 39 | Ask Smith about coffee; 40 | if(Smith want coffee){ 41 | Make coffee; 42 | // Warning, it might be hot! 43 | } 44 | // Be nice 45 | Let's party!; 46 | Good night Smith!; 47 | 48 | It was rendered as: 49 | 50 | .. image:: https://raw.githubusercontent.com/ad-m/flowgen/master/examples/basic_code.png 51 | :alt: Rendered diagram 52 | 53 | 54 | 55 | Credits 56 | --------- 57 | 58 | This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template. 59 | 60 | .. _Cookiecutter: https://github.com/audreyr/cookiecutter 61 | .. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage 62 | 63 | -------------------------------------------------------------------------------- /applied-patches/patch1.patch: -------------------------------------------------------------------------------- 1 | diff --git a/flowgen/graph.py b/flowgen/graph.py 2 | index 0cbfbaf..0bd9eae 100644 3 | --- a/flowgen/graph.py 4 | +++ b/flowgen/graph.py 5 | @@ -90,7 +90,7 @@ class Graph(object): 6 | head_name = head if isinstance(head, str) else str(head) 7 | self.dot.edge(tail_name=tail_name, 8 | head_name=head_name, 9 | - **self.style.get_for_edge(name, tail, head), 10 | + *self.style.get_for_edge(name, tail, head), 11 | **kwargs) 12 | 13 | def traverse_edges(self, node, parent=None): 14 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # User-friendly check for sphinx-build 11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) 12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) 13 | endif 14 | 15 | # Internal variables. 16 | PAPEROPT_a4 = -D latex_paper_size=a4 17 | PAPEROPT_letter = -D latex_paper_size=letter 18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 19 | # the i18n builder cannot share the environment and doctrees with the others 20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 21 | 22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext 23 | 24 | help: 25 | @echo "Please use \`make ' where is one of" 26 | @echo " html to make standalone HTML files" 27 | @echo " dirhtml to make HTML files named index.html in directories" 28 | @echo " singlehtml to make a single large HTML file" 29 | @echo " pickle to make pickle files" 30 | @echo " json to make JSON files" 31 | @echo " htmlhelp to make HTML files and a HTML help project" 32 | @echo " qthelp to make HTML files and a qthelp project" 33 | @echo " devhelp to make HTML files and a Devhelp project" 34 | @echo " epub to make an epub" 35 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 36 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 37 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" 38 | @echo " text to make text files" 39 | @echo " man to make manual pages" 40 | @echo " texinfo to make Texinfo files" 41 | @echo " info to make Texinfo files and run them through makeinfo" 42 | @echo " gettext to make PO message catalogs" 43 | @echo " changes to make an overview of all changed/added/deprecated items" 44 | @echo " xml to make Docutils-native XML files" 45 | @echo " pseudoxml to make pseudoxml-XML files for display purposes" 46 | @echo " linkcheck to check all external links for integrity" 47 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 48 | 49 | clean: 50 | rm -rf $(BUILDDIR)/* 51 | 52 | html: 53 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 54 | @echo 55 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 56 | 57 | dirhtml: 58 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 59 | @echo 60 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 61 | 62 | singlehtml: 63 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 64 | @echo 65 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 66 | 67 | pickle: 68 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 69 | @echo 70 | @echo "Build finished; now you can process the pickle files." 71 | 72 | json: 73 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 74 | @echo 75 | @echo "Build finished; now you can process the JSON files." 76 | 77 | htmlhelp: 78 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 79 | @echo 80 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 81 | ".hhp project file in $(BUILDDIR)/htmlhelp." 82 | 83 | qthelp: 84 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 85 | @echo 86 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 87 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 88 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/flowgen.qhcp" 89 | @echo "To view the help file:" 90 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/flowgen.qhc" 91 | 92 | devhelp: 93 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 94 | @echo 95 | @echo "Build finished." 96 | @echo "To view the help file:" 97 | @echo "# mkdir -p $$HOME/.local/share/devhelp/flowgen" 98 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/flowgen" 99 | @echo "# devhelp" 100 | 101 | epub: 102 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 103 | @echo 104 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 105 | 106 | latex: 107 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 108 | @echo 109 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 110 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 111 | "(use \`make latexpdf' here to do that automatically)." 112 | 113 | latexpdf: 114 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 115 | @echo "Running LaTeX files through pdflatex..." 116 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 117 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 118 | 119 | latexpdfja: 120 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 121 | @echo "Running LaTeX files through platex and dvipdfmx..." 122 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja 123 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 124 | 125 | text: 126 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 127 | @echo 128 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 129 | 130 | man: 131 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 132 | @echo 133 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 134 | 135 | texinfo: 136 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 137 | @echo 138 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 139 | @echo "Run \`make' in that directory to run these through makeinfo" \ 140 | "(use \`make info' here to do that automatically)." 141 | 142 | info: 143 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 144 | @echo "Running Texinfo files through makeinfo..." 145 | make -C $(BUILDDIR)/texinfo info 146 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 147 | 148 | gettext: 149 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 150 | @echo 151 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 152 | 153 | changes: 154 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 155 | @echo 156 | @echo "The overview file is in $(BUILDDIR)/changes." 157 | 158 | linkcheck: 159 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 160 | @echo 161 | @echo "Link check complete; look for any errors in the above output " \ 162 | "or in $(BUILDDIR)/linkcheck/output.txt." 163 | 164 | doctest: 165 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 166 | @echo "Testing of doctests in the sources finished, look at the " \ 167 | "results in $(BUILDDIR)/doctest/output.txt." 168 | 169 | xml: 170 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml 171 | @echo 172 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml." 173 | 174 | pseudoxml: 175 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml 176 | @echo 177 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." 178 | -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # flowgen documentation build configuration file, created by 5 | # sphinx-quickstart on Tue Jul 9 22:26:36 2013. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | import sys 17 | import os 18 | 19 | # If extensions (or modules to document with autodoc) are in another 20 | # directory, add these directories to sys.path here. If the directory is 21 | # relative to the documentation root, use os.path.abspath to make it 22 | # absolute, like shown here. 23 | #sys.path.insert(0, os.path.abspath('.')) 24 | 25 | # Get the project root dir, which is the parent dir of this 26 | cwd = os.getcwd() 27 | project_root = os.path.dirname(cwd) 28 | 29 | # Insert the project root dir as the first element in the PYTHONPATH. 30 | # This lets us ensure that the source package is imported, and that its 31 | # version is used. 32 | sys.path.insert(0, project_root) 33 | 34 | import flowgen 35 | 36 | # -- General configuration --------------------------------------------- 37 | 38 | # If your documentation needs a minimal Sphinx version, state it here. 39 | #needs_sphinx = '1.0' 40 | 41 | # Add any Sphinx extension module names here, as strings. They can be 42 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. 43 | extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] 44 | 45 | # Add any paths that contain templates here, relative to this directory. 46 | templates_path = ['_templates'] 47 | 48 | # The suffix of source filenames. 49 | source_suffix = '.rst' 50 | 51 | # The encoding of source files. 52 | #source_encoding = 'utf-8-sig' 53 | 54 | # The master toctree document. 55 | master_doc = 'index' 56 | 57 | # General information about the project. 58 | project = u'FlowGen' 59 | copyright = u"2017, Adam Dobrawy" 60 | 61 | # The version info for the project you're documenting, acts as replacement 62 | # for |version| and |release|, also used in various other places throughout 63 | # the built documents. 64 | # 65 | # The short X.Y version. 66 | version = flowgen.__version__ 67 | # The full version, including alpha/beta/rc tags. 68 | release = flowgen.__version__ 69 | 70 | # The language for content autogenerated by Sphinx. Refer to documentation 71 | # for a list of supported languages. 72 | #language = None 73 | 74 | # There are two options for replacing |today|: either, you set today to 75 | # some non-false value, then it is used: 76 | #today = '' 77 | # Else, today_fmt is used as the format for a strftime call. 78 | #today_fmt = '%B %d, %Y' 79 | 80 | # List of patterns, relative to source directory, that match files and 81 | # directories to ignore when looking for source files. 82 | exclude_patterns = ['_build'] 83 | 84 | # The reST default role (used for this markup: `text`) to use for all 85 | # documents. 86 | #default_role = None 87 | 88 | # If true, '()' will be appended to :func: etc. cross-reference text. 89 | #add_function_parentheses = True 90 | 91 | # If true, the current module name will be prepended to all description 92 | # unit titles (such as .. function::). 93 | #add_module_names = True 94 | 95 | # If true, sectionauthor and moduleauthor directives will be shown in the 96 | # output. They are ignored by default. 97 | #show_authors = False 98 | 99 | # The name of the Pygments (syntax highlighting) style to use. 100 | pygments_style = 'sphinx' 101 | 102 | # A list of ignored prefixes for module index sorting. 103 | #modindex_common_prefix = [] 104 | 105 | # If true, keep warnings as "system message" paragraphs in the built 106 | # documents. 107 | #keep_warnings = False 108 | 109 | 110 | # -- Options for HTML output ------------------------------------------- 111 | 112 | # The theme to use for HTML and HTML Help pages. See the documentation for 113 | # a list of builtin themes. 114 | html_theme = 'default' 115 | 116 | # Theme options are theme-specific and customize the look and feel of a 117 | # theme further. For a list of options available for each theme, see the 118 | # documentation. 119 | #html_theme_options = {} 120 | 121 | # Add any paths that contain custom themes here, relative to this directory. 122 | #html_theme_path = [] 123 | 124 | # The name for this set of Sphinx documents. If None, it defaults to 125 | # " v documentation". 126 | #html_title = None 127 | 128 | # A shorter title for the navigation bar. Default is the same as 129 | # html_title. 130 | #html_short_title = None 131 | 132 | # The name of an image file (relative to this directory) to place at the 133 | # top of the sidebar. 134 | #html_logo = None 135 | 136 | # The name of an image file (within the static path) to use as favicon 137 | # of the docs. This file should be a Windows icon file (.ico) being 138 | # 16x16 or 32x32 pixels large. 139 | #html_favicon = None 140 | 141 | # Add any paths that contain custom static files (such as style sheets) 142 | # here, relative to this directory. They are copied after the builtin 143 | # static files, so a file named "default.css" will overwrite the builtin 144 | # "default.css". 145 | html_static_path = ['_static'] 146 | 147 | # If not '', a 'Last updated on:' timestamp is inserted at every page 148 | # bottom, using the given strftime format. 149 | #html_last_updated_fmt = '%b %d, %Y' 150 | 151 | # If true, SmartyPants will be used to convert quotes and dashes to 152 | # typographically correct entities. 153 | #html_use_smartypants = True 154 | 155 | # Custom sidebar templates, maps document names to template names. 156 | #html_sidebars = {} 157 | 158 | # Additional templates that should be rendered to pages, maps page names 159 | # to template names. 160 | #html_additional_pages = {} 161 | 162 | # If false, no module index is generated. 163 | #html_domain_indices = True 164 | 165 | # If false, no index is generated. 166 | #html_use_index = True 167 | 168 | # If true, the index is split into individual pages for each letter. 169 | #html_split_index = False 170 | 171 | # If true, links to the reST sources are added to the pages. 172 | #html_show_sourcelink = True 173 | 174 | # If true, "Created using Sphinx" is shown in the HTML footer. 175 | # Default is True. 176 | #html_show_sphinx = True 177 | 178 | # If true, "(C) Copyright ..." is shown in the HTML footer. 179 | # Default is True. 180 | #html_show_copyright = True 181 | 182 | # If true, an OpenSearch description file will be output, and all pages 183 | # will contain a tag referring to it. The value of this option 184 | # must be the base URL from which the finished HTML is served. 185 | #html_use_opensearch = '' 186 | 187 | # This is the file name suffix for HTML files (e.g. ".xhtml"). 188 | #html_file_suffix = None 189 | 190 | # Output file base name for HTML help builder. 191 | htmlhelp_basename = 'flowgendoc' 192 | 193 | 194 | # -- Options for LaTeX output ------------------------------------------ 195 | 196 | latex_elements = { 197 | # The paper size ('letterpaper' or 'a4paper'). 198 | #'papersize': 'letterpaper', 199 | 200 | # The font size ('10pt', '11pt' or '12pt'). 201 | #'pointsize': '10pt', 202 | 203 | # Additional stuff for the LaTeX preamble. 204 | #'preamble': '', 205 | } 206 | 207 | # Grouping the document tree into LaTeX files. List of tuples 208 | # (source start file, target name, title, author, documentclass 209 | # [howto/manual]). 210 | latex_documents = [ 211 | ('index', 'flowgen.tex', 212 | u'FlowGen Documentation', 213 | u'Adam Dobrawy', 'manual'), 214 | ] 215 | 216 | # The name of an image file (relative to this directory) to place at 217 | # the top of the title page. 218 | #latex_logo = None 219 | 220 | # For "manual" documents, if this is true, then toplevel headings 221 | # are parts, not chapters. 222 | #latex_use_parts = False 223 | 224 | # If true, show page references after internal links. 225 | #latex_show_pagerefs = False 226 | 227 | # If true, show URL addresses after external links. 228 | #latex_show_urls = False 229 | 230 | # Documents to append as an appendix to all manuals. 231 | #latex_appendices = [] 232 | 233 | # If false, no module index is generated. 234 | #latex_domain_indices = True 235 | 236 | 237 | # -- Options for manual page output ------------------------------------ 238 | 239 | # One entry per manual page. List of tuples 240 | # (source start file, name, description, authors, manual section). 241 | man_pages = [ 242 | ('index', 'flowgen', 243 | u'FlowGen Documentation', 244 | [u'Adam Dobrawy'], 1) 245 | ] 246 | 247 | # If true, show URL addresses after external links. 248 | #man_show_urls = False 249 | 250 | 251 | # -- Options for Texinfo output ---------------------------------------- 252 | 253 | # Grouping the document tree into Texinfo files. List of tuples 254 | # (source start file, target name, title, author, 255 | # dir menu entry, description, category) 256 | texinfo_documents = [ 257 | ('index', 'flowgen', 258 | u'FlowGen Documentation', 259 | u'Adam Dobrawy', 260 | 'flowgen', 261 | 'One line description of project.', 262 | 'Miscellaneous'), 263 | ] 264 | 265 | # Documents to append as an appendix to all manuals. 266 | #texinfo_appendices = [] 267 | 268 | # If false, no module index is generated. 269 | #texinfo_domain_indices = True 270 | 271 | # How to display URL addresses: 'footnote', 'no', or 'inline'. 272 | #texinfo_show_urls = 'footnote' 273 | 274 | # If true, do not generate a @detailmenu in the "Top" node's menu. 275 | #texinfo_no_detailmenu = False 276 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/history.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../HISTORY.rst 2 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | Welcome to FlowGen's documentation! 2 | ====================================== 3 | 4 | Contents: 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | readme 10 | installation 11 | usage 12 | contributing 13 | authorshistory 14 | 15 | Indices and tables 16 | ================== 17 | 18 | * :ref:`genindex` 19 | * :ref:`modindex` 20 | * :ref:`search` 21 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | .. highlight:: shell 2 | 3 | ============ 4 | Installation 5 | ============ 6 | 7 | 8 | Stable release 9 | -------------- 10 | 11 | To install FlowGen, run this command in your terminal: 12 | 13 | .. code-block:: console 14 | 15 | $ pip install flowgen 16 | 17 | This is the preferred method to install FlowGen, as it will always install the most recent stable release. 18 | 19 | If you don't have `pip`_ installed, this `Python installation guide`_ can guide 20 | you through the process. 21 | 22 | .. _pip: https://pip.pypa.io 23 | .. _Python installation guide: http://docs.python-guide.org/en/latest/starting/installation/ 24 | 25 | 26 | From sources 27 | ------------ 28 | 29 | The sources for FlowGen can be downloaded from the `Github repo`_. 30 | 31 | You can either clone the public repository: 32 | 33 | .. code-block:: console 34 | 35 | $ git clone git://github.com/ad-m/flowgen 36 | 37 | Or download the `tarball`_: 38 | 39 | .. code-block:: console 40 | 41 | $ curl -OL https://github.com/ad-m/flowgen/tarball/master 42 | 43 | Once you have a copy of the source, you can install it with: 44 | 45 | .. code-block:: console 46 | 47 | $ python setup.py install 48 | 49 | 50 | .. _Github repo: https://github.com/ad-m/flowgen 51 | .. _tarball: https://github.com/ad-m/flowgen/tarball/master 52 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. xml to make Docutils-native XML files 37 | echo. pseudoxml to make pseudoxml-XML files for display purposes 38 | echo. linkcheck to check all external links for integrity 39 | echo. doctest to run all doctests embedded in the documentation if enabled 40 | goto end 41 | ) 42 | 43 | if "%1" == "clean" ( 44 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 45 | del /q /s %BUILDDIR%\* 46 | goto end 47 | ) 48 | 49 | 50 | %SPHINXBUILD% 2> nul 51 | if errorlevel 9009 ( 52 | echo. 53 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 54 | echo.installed, then set the SPHINXBUILD environment variable to point 55 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 56 | echo.may add the Sphinx directory to PATH. 57 | echo. 58 | echo.If you don't have Sphinx installed, grab it from 59 | echo.http://sphinx-doc.org/ 60 | exit /b 1 61 | ) 62 | 63 | if "%1" == "html" ( 64 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 68 | goto end 69 | ) 70 | 71 | if "%1" == "dirhtml" ( 72 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 76 | goto end 77 | ) 78 | 79 | if "%1" == "singlehtml" ( 80 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 84 | goto end 85 | ) 86 | 87 | if "%1" == "pickle" ( 88 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can process the pickle files. 92 | goto end 93 | ) 94 | 95 | if "%1" == "json" ( 96 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 97 | if errorlevel 1 exit /b 1 98 | echo. 99 | echo.Build finished; now you can process the JSON files. 100 | goto end 101 | ) 102 | 103 | if "%1" == "htmlhelp" ( 104 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 105 | if errorlevel 1 exit /b 1 106 | echo. 107 | echo.Build finished; now you can run HTML Help Workshop with the ^ 108 | .hhp project file in %BUILDDIR%/htmlhelp. 109 | goto end 110 | ) 111 | 112 | if "%1" == "qthelp" ( 113 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 114 | if errorlevel 1 exit /b 1 115 | echo. 116 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 117 | .qhcp project file in %BUILDDIR%/qthelp, like this: 118 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\flowgen.qhcp 119 | echo.To view the help file: 120 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\flowgen.ghc 121 | goto end 122 | ) 123 | 124 | if "%1" == "devhelp" ( 125 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished. 129 | goto end 130 | ) 131 | 132 | if "%1" == "epub" ( 133 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 137 | goto end 138 | ) 139 | 140 | if "%1" == "latex" ( 141 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 145 | goto end 146 | ) 147 | 148 | if "%1" == "latexpdf" ( 149 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 150 | cd %BUILDDIR%/latex 151 | make all-pdf 152 | cd %BUILDDIR%/.. 153 | echo. 154 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 155 | goto end 156 | ) 157 | 158 | if "%1" == "latexpdfja" ( 159 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 160 | cd %BUILDDIR%/latex 161 | make all-pdf-ja 162 | cd %BUILDDIR%/.. 163 | echo. 164 | echo.Build finished; the PDF files are in %BUILDDIR%/latex. 165 | goto end 166 | ) 167 | 168 | if "%1" == "text" ( 169 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 170 | if errorlevel 1 exit /b 1 171 | echo. 172 | echo.Build finished. The text files are in %BUILDDIR%/text. 173 | goto end 174 | ) 175 | 176 | if "%1" == "man" ( 177 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 178 | if errorlevel 1 exit /b 1 179 | echo. 180 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 181 | goto end 182 | ) 183 | 184 | if "%1" == "texinfo" ( 185 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 186 | if errorlevel 1 exit /b 1 187 | echo. 188 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 189 | goto end 190 | ) 191 | 192 | if "%1" == "gettext" ( 193 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 194 | if errorlevel 1 exit /b 1 195 | echo. 196 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 197 | goto end 198 | ) 199 | 200 | if "%1" == "changes" ( 201 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 202 | if errorlevel 1 exit /b 1 203 | echo. 204 | echo.The overview file is in %BUILDDIR%/changes. 205 | goto end 206 | ) 207 | 208 | if "%1" == "linkcheck" ( 209 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 210 | if errorlevel 1 exit /b 1 211 | echo. 212 | echo.Link check complete; look for any errors in the above output ^ 213 | or in %BUILDDIR%/linkcheck/output.txt. 214 | goto end 215 | ) 216 | 217 | if "%1" == "doctest" ( 218 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 219 | if errorlevel 1 exit /b 1 220 | echo. 221 | echo.Testing of doctests in the sources finished, look at the ^ 222 | results in %BUILDDIR%/doctest/output.txt. 223 | goto end 224 | ) 225 | 226 | if "%1" == "xml" ( 227 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml 228 | if errorlevel 1 exit /b 1 229 | echo. 230 | echo.Build finished. The XML files are in %BUILDDIR%/xml. 231 | goto end 232 | ) 233 | 234 | if "%1" == "pseudoxml" ( 235 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml 236 | if errorlevel 1 exit /b 1 237 | echo. 238 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml. 239 | goto end 240 | ) 241 | 242 | :end 243 | -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ===== 2 | Usage 3 | ===== 4 | 5 | To use FlowGen in a project:: 6 | 7 | import flowgen 8 | -------------------------------------------------------------------------------- /examples/basic_code.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | start [label=START shape=oval] 3 | end [label=END shape=oval] 4 | start -> "Hello Smith" 5 | "Hello Smith" [label="Hello Smith" shape=box] 6 | "Hello Smith" -> "Ask Smith about coffee" 7 | "Ask Smith about coffee" [label="Ask Smith about coffee" shape=box] 8 | "Ask Smith about coffee" -> "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" 9 | "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" [label="Smith want coffee" shape=diamond] 10 | "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" -> "Let's party!" [label=False color=red] 11 | "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" -> "Make coffee" [label=True color=green] 12 | "Make coffee" [label="Make coffee" shape=box] 13 | "Make coffee" -> "Let's party!" 14 | "Warning, it might be hot!" [label="Warning, it might be hot!" fillcolor=gray shape=box style=filled] 15 | "Warning, it might be hot!" -> "Make coffee" [style=dashed] 16 | "Be nice" [label="Be nice" fillcolor=gray shape=box style=filled] 17 | "Be nice" -> "Make coffee" [style=dashed] 18 | "Let's party!" [label="Let's party!" shape=box] 19 | "Let's party!" -> "Good night Smith!" 20 | "Good night Smith!" [label="Good night Smith!" shape=box] 21 | "Good night Smith!" -> end 22 | } -------------------------------------------------------------------------------- /examples/basic_code.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zaryob/flowgen/39250f743bb8508bd005fc5bc8e41e470aa1efd7/examples/basic_code.pdf -------------------------------------------------------------------------------- /examples/basic_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zaryob/flowgen/39250f743bb8508bd005fc5bc8e41e470aa1efd7/examples/basic_code.png -------------------------------------------------------------------------------- /examples/basic_code.txt: -------------------------------------------------------------------------------- 1 | Hello Smith; 2 | Ask Smith about coffee; 3 | if(Smith want coffee){ 4 | Make coffee; 5 | // Warning, it might be hot! 6 | } 7 | // Be nice 8 | Let's party!; 9 | Good night Smith!; 10 | -------------------------------------------------------------------------------- /examples/nested_if.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | start [label=START shape=oval] 3 | end [label=END shape=oval] 4 | start -> 1 5 | 1 [label=1 shape=box] 6 | 1 -> 2 7 | 2 [label=2 shape=box] 8 | 2 -> "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" 9 | "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" [label=3 shape=diamond] 10 | "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" -> 9 [label=False color=red] 11 | "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" -> 4 [label=True color=green] 12 | 4 [label=4 shape=box] 13 | 4 -> 5 14 | 5 [label=5 shape=box] 15 | 5 -> "Condition(['7', '8'], name=ConditionType('if'))" 16 | "Condition(['7', '8'], name=ConditionType('if'))" [label=6 shape=diamond] 17 | "Condition(['7', '8'], name=ConditionType('if'))" -> 9 [label=False color=red] 18 | "Condition(['7', '8'], name=ConditionType('if'))" -> 7 [label=True color=green] 19 | 7 [label=7 shape=box] 20 | 7 -> 9 21 | 8 [label=8 fillcolor=gray shape=box style=filled] 22 | 8 -> 7 [style=dashed] 23 | 9 [label=9 shape=box] 24 | 9 -> 11 25 | 10 [label=10 fillcolor=gray shape=box style=filled] 26 | 10 -> 9 [style=dashed] 27 | 11 [label=11 shape=box] 28 | 11 -> 12 29 | 12 [label=12 shape=box] 30 | 12 -> end 31 | } -------------------------------------------------------------------------------- /examples/nested_if.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zaryob/flowgen/39250f743bb8508bd005fc5bc8e41e470aa1efd7/examples/nested_if.pdf -------------------------------------------------------------------------------- /examples/nested_if.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Zaryob/flowgen/39250f743bb8508bd005fc5bc8e41e470aa1efd7/examples/nested_if.png -------------------------------------------------------------------------------- /examples/nested_if.txt: -------------------------------------------------------------------------------- 1 | 1; 2 | 2; 3 | if(3){ 4 | 4; 5 | 5; 6 | if(6){ 7 | 7; 8 | // 8 9 | } 10 | } 11 | 9; 12 | // 10 13 | 11; 14 | 12; 15 | -------------------------------------------------------------------------------- /flowgen/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import sys 3 | 4 | from flowgen.core import FlowGen 5 | 6 | __author__ = """Adam Dobrawy""" 7 | __email__ = 'naczelnik@jawnosc.tk' 8 | __version__ = '0.1.0' 9 | 10 | 11 | def main(): 12 | FlowGen(sys.argv[1:]).run() 13 | -------------------------------------------------------------------------------- /flowgen/__main__.py: -------------------------------------------------------------------------------- 1 | from flowgen import main 2 | 3 | if __name__ == '__main__': 4 | main() 5 | -------------------------------------------------------------------------------- /flowgen/core.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import print_function 3 | from flowgen.graph import Graph 4 | from flowgen.language import Code 5 | from flowgen.options import parser 6 | from pypeg2 import parse 7 | from pypeg2.xmlast import thing2xml 8 | 9 | 10 | class FlowGen(object): 11 | 12 | def __init__(self, args): 13 | self.args = parser.parse_args(args) 14 | 15 | def any_output(self): 16 | return any([self.args.dump_source, self.args.dump_xml]) 17 | 18 | def safe_print(self, *args, **kwargs): 19 | if not self.any_output(): 20 | print(*args, **kwargs) 21 | 22 | def run(self): 23 | data_input = self.args.infile.read() 24 | tree = parse(data_input, Code) 25 | if self.args.dump_xml: 26 | print(thing2xml(tree, pretty=True).decode()) 27 | 28 | graph = Graph(tree) 29 | 30 | graph.render() 31 | 32 | if self.args.dump_source: 33 | print(graph.get_source()) 34 | if self.args.preview: 35 | graph.dot.view() 36 | if self.args.outfile: 37 | graph.save(self.args.outfile.name) 38 | self.safe_print("Saved graph to %s successfull" % (self.args.outfile.name)) 39 | -------------------------------------------------------------------------------- /flowgen/graph.py: -------------------------------------------------------------------------------- 1 | from os.path import splitext 2 | 3 | from flowgen.language import Code, Comment, Condition, Instruction 4 | from graphviz import Digraph 5 | 6 | 7 | def is_iterable(node): 8 | return isinstance(node, (Condition, Code)) 9 | 10 | 11 | def contains(needle, haystack): 12 | if needle == haystack: 13 | return True 14 | if is_iterable(haystack): 15 | return any(contains(needle, x) for x in haystack) 16 | return False 17 | 18 | 19 | class GraphStyle(object): 20 | 21 | # Terminators 22 | def start_node(self, node): 23 | return dict(shape="oval") 24 | 25 | def start_edge(self, tail, head): 26 | return dict() 27 | 28 | def end_node(self, node): 29 | return dict(shape="oval") 30 | 31 | # Instruction 32 | def instruction_node(self, node): 33 | return dict(label=str(node), shape="box") 34 | 35 | def instruction_edge(self, tail, head): 36 | return dict() 37 | 38 | # Comment 39 | def comment_node(self, node): 40 | return dict(label=str(node), shape="box", 41 | style="filled", 42 | fillcolor="gray") 43 | 44 | def comment_edge(self, tail, head): 45 | return dict(style="dashed") 46 | 47 | # Condition 48 | def condition_node(self, node): 49 | return dict(label=node.condition, shape="diamond") 50 | 51 | def condition_true_edge(self, tail, head): 52 | return dict(label="True", color="green") 53 | 54 | def condition_false_edge(self, tail, head): 55 | return dict(label="False", color="red") 56 | 57 | def get_for_edge(self, name, tail, head): 58 | return getattr(self, "%s_edge" % (name))(tail, head) 59 | 60 | def get_for_node(self, name, node=None): 61 | return getattr(self, "%s_node" % (name))(node) 62 | 63 | 64 | class Graph(object): 65 | 66 | def __init__(self, tree, style=None): 67 | self.rendered = False 68 | self.tree = tree 69 | self.style = GraphStyle() if style is None else style 70 | 71 | def render(self): 72 | self.dot = Digraph() 73 | self.dot.node('start', "START", **self.style.get_for_node('start')) 74 | self.dot.node('end', "END", **self.style.get_for_node('end')) 75 | 76 | self.nodes = [] 77 | self.traverse_list(self.tree) 78 | self.add_edge('start', self.nodes[0], 'start') 79 | self.traverse_edges(self.tree) 80 | 81 | def traverse_list(self, node, parent=None): 82 | if not isinstance(node, Code): 83 | self.nodes.append(node) 84 | if is_iterable(node): 85 | for el in node: 86 | self.traverse_list(el, node) 87 | 88 | def add_edge(self, tail, head, name, **kwargs): 89 | tail_name = tail if isinstance(tail, str) else str(tail) 90 | head_name = head if isinstance(head, str) else str(head) 91 | self.dot.edge(tail_name=tail_name, 92 | head_name=head_name, 93 | *self.style.get_for_edge(name, tail, head), 94 | **kwargs) 95 | 96 | def traverse_edges(self, node, parent=None): 97 | if isinstance(node, Code): 98 | for el in node: 99 | self.traverse_edges(el, node) 100 | elif isinstance(node, Instruction): 101 | self.dot.node(str(node), **self.style.get_for_node('instruction', node)) 102 | 103 | n = self.find_next(node, (Instruction, Condition)) 104 | self.add_edge(node, n, 'instruction') 105 | elif isinstance(node, Comment): 106 | self.dot.node(str(node), **self.style.get_for_node('comment', node)) 107 | 108 | prev = self.find_prev(node, (Instruction, Condition)) 109 | self.add_edge(node, prev, 'comment') 110 | elif isinstance(node, Condition): 111 | self.dot.node(str(node), **self.style.get_for_node('condition', node)) 112 | 113 | n = self.find_next(node, (Instruction, Condition), exclude_child=True) 114 | self.add_edge(node, n, 'condition_false') 115 | 116 | self.add_edge(node, node[0], 'condition_true') 117 | 118 | for el in node: 119 | self.traverse_edges(el, node) 120 | 121 | def find_prev(self, item, types, exclude_child=False): 122 | index = self.nodes.index(item) 123 | items = enumerate(self.nodes) 124 | if exclude_child: 125 | items = filter(lambda v: contains(v[1], item), items) 126 | items = filter(lambda v: v[0] < index, items) 127 | items = filter(lambda v: isinstance(v[1], types), items) 128 | items = list(map(lambda v: v[1], items)) 129 | if not items: 130 | return 'start' 131 | return items[-1] 132 | 133 | def find_next(self, item, types=None, exclude_child=False): 134 | index = self.nodes.index(item) 135 | items = enumerate(self.nodes) 136 | if exclude_child: 137 | items = filter(lambda v: not contains(v[1], item), items) 138 | items = filter(lambda v: v[0] > index, items) 139 | items = filter(lambda v: isinstance(v[1], types), items) 140 | items = list(map(lambda v: v[1], items)) 141 | if not items: 142 | return 'end' 143 | return items[0] 144 | 145 | def get_source(self): 146 | return self.dot.source 147 | 148 | def view(self): 149 | return self.dot.view() 150 | 151 | def save(self, path): 152 | filename, ext = splitext(path) 153 | self.dot.format = ext.lstrip('.') 154 | self.dot.render(filename) 155 | -------------------------------------------------------------------------------- /flowgen/language.py: -------------------------------------------------------------------------------- 1 | from __future__ import unicode_literals, print_function 2 | import re 3 | 4 | from pypeg2 import * 5 | 6 | super_word = re.compile('([\w0-9 +\?!&\']+)') 7 | 8 | 9 | class MultiLineComment(str): 10 | grammar = comment_c 11 | 12 | 13 | class EndLineComment(str): 14 | grammar = "//", restline, endl 15 | 16 | 17 | class Comment(str): 18 | grammar = [EndLineComment, MultiLineComment] 19 | 20 | 21 | class Instruction(str): 22 | grammar = super_word, some([";", "\n"]) 23 | 24 | 25 | class ConditionType(Keyword): 26 | grammar = Enum(K("if"), K("while")) 27 | 28 | 29 | class Condition(List): 30 | pass 31 | 32 | 33 | block = "{", maybe_some([Instruction, Comment, Condition]), "}", maybe_some(';') 34 | Condition.grammar = attr("name", ConditionType), '(', attr("condition", super_word), ")",\ 35 | [block, Instruction] 36 | 37 | 38 | class Code(List): 39 | grammar = maybe_some([Instruction, Condition, Comment]) 40 | -------------------------------------------------------------------------------- /flowgen/options.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import sys 3 | 4 | parser = argparse.ArgumentParser() 5 | parser.add_argument('infile', nargs='?', type=argparse.FileType('r'), 6 | default=sys.stdin) 7 | parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=None) 8 | parser.add_argument('--dump-xml', action='store_true', 9 | help='Dump the result of parsing file as XML') 10 | parser.add_argument('--dump-source', action='store_true', 11 | help='Dump the DOT source code') 12 | parser.add_argument('--preview', action='store_true', 13 | help='Open graph preview') 14 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | pip==8.1.2 2 | bumpversion==0.5.3 3 | wheel==0.29.0 4 | watchdog==0.8.3 5 | flake8==2.6.0 6 | tox==2.3.1 7 | coverage==4.1 8 | Sphinx==1.4.8 9 | 10 | 11 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 0.1.0 3 | commit = True 4 | tag = True 5 | 6 | [bumpversion:file:setup.py] 7 | search = version='{current_version}' 8 | replace = version='{new_version}' 9 | 10 | [bumpversion:file:flowgen/__init__.py] 11 | search = __version__ = '{current_version}' 12 | replace = __version__ = '{new_version}' 13 | 14 | [bdist_wheel] 15 | universal = 1 16 | 17 | [flake8] 18 | exclude = docs 19 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | 4 | from setuptools import setup 5 | 6 | with open('README.rst') as readme_file: 7 | readme = readme_file.read() 8 | 9 | with open('HISTORY.rst') as history_file: 10 | history = history_file.read() 11 | 12 | requirements = [ 13 | 'pypeg2', 14 | 'graphviz' 15 | ] 16 | 17 | test_requirements = [ 18 | # TODO: put package test requirements here 19 | ] 20 | 21 | setup( 22 | name='flowgen', 23 | version='0.1.0', 24 | description="code to flowchart converter.", 25 | long_description=readme + '\n\n' + history, 26 | author="Adam Dobrawy", 27 | author_email='naczelnik@jawnosc.tk', 28 | url='https://github.com/ad-m/flowgen', 29 | packages=[ 30 | 'flowgen', 31 | ], 32 | package_dir={'flowgen': 33 | 'flowgen'}, 34 | include_package_data=True, 35 | install_requires=requirements, 36 | license="MIT license", 37 | zip_safe=False, 38 | keywords='flowgen', 39 | classifiers=[ 40 | 'Development Status :: 2 - Pre-Alpha', 41 | 'Intended Audience :: Developers', 42 | 'License :: OSI Approved :: MIT License', 43 | 'Natural Language :: English', 44 | "Programming Language :: Python :: 2", 45 | 'Programming Language :: Python :: 2.6', 46 | 'Programming Language :: Python :: 2.7', 47 | 'Programming Language :: Python :: 3', 48 | 'Programming Language :: Python :: 3.3', 49 | 'Programming Language :: Python :: 3.4', 50 | 'Programming Language :: Python :: 3.5', 51 | ], 52 | test_suite='tests', 53 | tests_require=test_requirements 54 | ) 55 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /tests/graphs/basic_code.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | start [label=START shape=oval] 3 | end [label=END shape=oval] 4 | start -> "Hello Smith" 5 | "Hello Smith" [label="Hello Smith" shape=box] 6 | "Hello Smith" -> "Ask Smith about coffee" 7 | "Ask Smith about coffee" [label="Ask Smith about coffee" shape=box] 8 | "Ask Smith about coffee" -> "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" 9 | "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" [label="Smith want coffee" shape=diamond] 10 | "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" -> "Let's party!" [label=False color=red] 11 | "Condition(['Make coffee', 'Warning, it might be hot!'], name=ConditionType('if'))" -> "Make coffee" [label=True color=green] 12 | "Make coffee" [label="Make coffee" shape=box] 13 | "Make coffee" -> "Let's party!" 14 | "Warning, it might be hot!" [label="Warning, it might be hot!" fillcolor=gray shape=box style=filled] 15 | "Warning, it might be hot!" -> "Make coffee" [style=dashed] 16 | "Be nice" [label="Be nice" fillcolor=gray shape=box style=filled] 17 | "Be nice" -> "Make coffee" [style=dashed] 18 | "Let's party!" [label="Let's party!" shape=box] 19 | "Let's party!" -> "Good night Smith!" 20 | "Good night Smith!" [label="Good night Smith!" shape=box] 21 | "Good night Smith!" -> end 22 | } -------------------------------------------------------------------------------- /tests/graphs/basic_code.txt: -------------------------------------------------------------------------------- 1 | Hello Smith; 2 | Ask Smith about coffee; 3 | if(Smith want coffee){ 4 | Make coffee; 5 | // Warning, it might be hot! 6 | } 7 | // Be nice 8 | Let's party!; 9 | Good night Smith!; 10 | -------------------------------------------------------------------------------- /tests/graphs/nested_if.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | start [label=START shape=oval] 3 | end [label=END shape=oval] 4 | start -> 1 5 | 1 [label=1 shape=box] 6 | 1 -> 2 7 | 2 [label=2 shape=box] 8 | 2 -> "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" 9 | "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" [label=3 shape=diamond] 10 | "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" -> 9 [label=False color=red] 11 | "Condition(['4', '5', Condition(['7', '8'], name=ConditionType('if'))], name=ConditionType('if'))" -> 4 [label=True color=green] 12 | 4 [label=4 shape=box] 13 | 4 -> 5 14 | 5 [label=5 shape=box] 15 | 5 -> "Condition(['7', '8'], name=ConditionType('if'))" 16 | "Condition(['7', '8'], name=ConditionType('if'))" [label=6 shape=diamond] 17 | "Condition(['7', '8'], name=ConditionType('if'))" -> 9 [label=False color=red] 18 | "Condition(['7', '8'], name=ConditionType('if'))" -> 7 [label=True color=green] 19 | 7 [label=7 shape=box] 20 | 7 -> 9 21 | 8 [label=8 fillcolor=gray shape=box style=filled] 22 | 8 -> 7 [style=dashed] 23 | 9 [label=9 shape=box] 24 | 9 -> 11 25 | 10 [label=10 fillcolor=gray shape=box style=filled] 26 | 10 -> 9 [style=dashed] 27 | 11 [label=11 shape=box] 28 | 11 -> 12 29 | 12 [label=12 shape=box] 30 | 12 -> end 31 | } -------------------------------------------------------------------------------- /tests/graphs/nested_if.txt: -------------------------------------------------------------------------------- 1 | 1; 2 | 2; 3 | if(3){ 4 | 4; 5 | 5; 6 | if(6){ 7 | 7; 8 | // 8 9 | } 10 | } 11 | 9; 12 | // 10 13 | 11; 14 | 12; 15 | -------------------------------------------------------------------------------- /tests/test_graph.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, unicode_literals 2 | 3 | import string 4 | import unittest 5 | from os.path import dirname, join 6 | 7 | from flowgen.graph import Graph, GraphStyle 8 | from flowgen.language import Code 9 | from pypeg2 import parse 10 | 11 | 12 | class MockNode(object): 13 | condition = 'x' 14 | 15 | 16 | class StyleMixin(object): 17 | node_type = ['instruction', 'comment', 'condition', 'start', 'end'] 18 | edge_type = ['start', 'instruction', 'comment', 'condition_true', 'condition_false'] 19 | style = None 20 | 21 | def get_style(self): 22 | if self.style is None: 23 | raise RuntimeError( 24 | '{0} is missing a style to test. Define {0}.style ' 25 | 'or override {0}.get_style().'.format(self.__class__.__name__)) 26 | return self.style 27 | 28 | def test_return_dict_for_nodes(self): 29 | 30 | style = self.get_style() 31 | for name in self.node_type: 32 | res = style.get_for_node(name, MockNode()) 33 | self.assertIsInstance(res, dict, msg="Style for edge {0} is wrong".format(name)) 34 | 35 | def test_return_dict_for_edges(self): 36 | 37 | style = self.get_style() 38 | for name in self.edge_type: 39 | res = style.get_for_edge(name, MockNode(), MockNode()) 40 | self.assertIsInstance(res, dict, msg="Style for edge {0} is wrong".format(name)) 41 | 42 | 43 | class GraphStyleTestCase(StyleMixin, unittest.TestCase): 44 | style = GraphStyle() 45 | 46 | 47 | class GraphTestCase(unittest.TestCase): 48 | graphs = ['basic_code', 'nested_if'] 49 | 50 | def _get_test_dir(self): 51 | return dirname(__file__) 52 | 53 | def get_file_content(self, filename): 54 | path = join(self._get_test_dir(), 'graphs', filename) 55 | 56 | with open(path, 'r') as fp: 57 | return fp.read() 58 | 59 | def test_basic_graph_from_fixtures(self): 60 | for name in self.graphs: 61 | data_test = self.get_file_content('%s.txt' % (name)) 62 | tree = parse(data_test, Code) 63 | 64 | graph = Graph(tree) 65 | graph.render() 66 | 67 | graph_test = self.get_file_content('%s.dot' % (name)) 68 | source = graph.get_source() 69 | self.assertEqual(graph_test, source) 70 | 71 | maxDiff = None 72 | -------------------------------------------------------------------------------- /tests/test_language.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from __future__ import print_function, unicode_literals 4 | 5 | import os 6 | import unittest 7 | from glob import glob 8 | 9 | from flowgen import language 10 | from pypeg2 import parse, some 11 | 12 | 13 | class PEGMixin(unittest.TestCase): 14 | 15 | def assertPEG(self, obj, cls, value=None): 16 | self.assertIsInstance(obj, cls) 17 | self.assertEqual(obj, value) 18 | 19 | def assertConditionEqual(self, obj, name, condition): 20 | self.assertIsInstance(obj, language.Condition) 21 | self.assertEqual(obj.name, name) 22 | self.assertEqual(obj.condition, condition) 23 | 24 | 25 | class InstructionTestCase(PEGMixin, unittest.TestCase): 26 | 27 | def _test_instructions(self, case, result): 28 | tree = parse(case, language.Instruction) 29 | self.assertPEG(tree, language.Instruction, result) 30 | 31 | def test_instructions_parse(self): 32 | self._test_instructions('Welcome to code2flow;', 'Welcome to code2flow') 33 | self._test_instructions('Some text!;', 'Some text!') 34 | 35 | 36 | class ConditionTestCase(PEGMixin, unittest.TestCase): 37 | 38 | def test_basic_while(self): 39 | tree = parse("""while (my_condition) { 40 | instruction; 41 | }""", language.Condition) 42 | self.assertConditionEqual(tree, 'while', "my_condition") 43 | 44 | self.assertPEG(tree[0], language.Instruction, "instruction") 45 | 46 | def test_basic_if(self): 47 | tree = parse("""if (example && aa) { 48 | instruction; 49 | }""", language.Condition) 50 | 51 | self.assertConditionEqual(tree, 'if', "example && aa") 52 | 53 | self.assertPEG(tree[0], language.Instruction, "instruction") 54 | 55 | def test_single_line_condition(self): 56 | tree = parse("if (cond) instruction;", language.Condition) 57 | 58 | self.assertConditionEqual(tree, 'if', "cond") 59 | 60 | self.assertPEG(tree[0], language.Instruction, "instruction") 61 | 62 | def test_condition_with_multiline_comment(self): 63 | tree = parse("""if (my_condition) { 64 | code; 65 | /* XXX */ 66 | }""", language.Condition) 67 | 68 | self.assertConditionEqual(tree, 'if', "my_condition") 69 | 70 | self.assertPEG(tree[0], language.Instruction, "code") 71 | self.assertPEG(tree[1], language.Comment, "/* XXX */") 72 | 73 | def test_condition_with_multiline_comment_in_multi_lines(self): 74 | tree = parse("""if (my_condition) { 75 | code; 76 | /* XXX 77 | xxx 78 | */ 79 | }""", language.Condition) 80 | 81 | self.assertConditionEqual(tree, 'if', "my_condition") 82 | 83 | self.assertPEG(tree[0], language.Instruction, "code") 84 | self.assertPEG(tree[1], language.Comment, """/* XXX 85 | xxx 86 | */""") 87 | 88 | def test_nested_condition(self): 89 | tree = parse("""if(my_condition) { 90 | while(nested) { 91 | code; 92 | } 93 | }""", language.Condition) 94 | 95 | self.assertConditionEqual(tree, 'if', "my_condition") 96 | 97 | self.assertConditionEqual(tree[0], 'while', "nested") 98 | 99 | self.assertEqual(tree[0][0], "code") 100 | 101 | 102 | class CommentUnitTestCase(PEGMixin, unittest.TestCase): 103 | 104 | def test_plain_multiline_comment(self): 105 | tree = parse("""/* foo 106 | bar */ 107 | """, language.Comment) 108 | 109 | self.assertPEG(tree, language.Comment, """/* foo 110 | bar */""") 111 | 112 | def test_plain_end_line_comment(self): 113 | tree = parse("""// foo""", language.Comment) 114 | self.assertPEG(tree, language.Comment, "foo") 115 | 116 | 117 | class CodeUnitTestCase(PEGMixin, unittest.TestCase): 118 | heading = """Welcome to code2flow; 119 | """ 120 | condition = """if(In doubt?) { 121 | Press Help; 122 | while(!Ready?) 123 | Read help; 124 | } 125 | """ 126 | comment = """//the preview updates 127 | //as you write""" 128 | footer = "Improve your workflow!;""" 129 | 130 | def test_heading(self): 131 | parse(self.heading, some(language.Instruction)) 132 | parse(self.heading, language.Code) 133 | 134 | def test_condition(self): 135 | parse(self.condition, some(language.Condition)) 136 | parse(self.condition, language.Code) 137 | 138 | def test_comment(self): 139 | parse(self.comment, some(language.Comment)) 140 | parse(self.comment, language.Code) 141 | 142 | def test_footer(self): 143 | parse(self.footer, some(language.Instruction)) 144 | parse(self.footer, language.Code) 145 | 146 | def test_concat(self): 147 | parse(self.heading + self.condition + self.comment + self.footer, language.Code) 148 | 149 | def test_ignore_condition_in_comment(self): 150 | tree = parse("""// foo if(cond) instruction; 151 | // bar""", language.Code) 152 | self.assertPEG(tree[0], language.Comment, "foo if(cond) instruction;") 153 | self.assertPEG(tree[1], language.Comment, "bar") 154 | 155 | def test_condition_with_end_line_comment(self): 156 | tree = parse("""if (my_condition) { 157 | code; 158 | };// simple comment""", language.Code) 159 | 160 | self.assertConditionEqual(tree[0], 'if', "my_condition") 161 | 162 | self.assertPEG(tree[0][0], language.Instruction, 'code') 163 | 164 | self.assertPEG(tree[1], language.Comment, 'simple comment') 165 | 166 | def test_condition_with_multiple_end_line_comments(self): 167 | tree = parse("""if (my_condition) { 168 | code; 169 | }; // simple comment 170 | // second comment 171 | """, language.Code) 172 | 173 | self.assertConditionEqual(tree[0], 'if', 'my_condition') 174 | 175 | self.assertPEG(tree[1], language.Comment, 'simple comment') 176 | 177 | self.assertPEG(tree[2], language.Comment, 'second comment') 178 | 179 | def test_empty_string(self): 180 | parse("", language.Code) 181 | 182 | def _get_root_dir(self): 183 | return os.path.join(os.path.dirname(__file__), '..') 184 | 185 | def test_parse_examples(self): 186 | path = os.path.join(self._get_root_dir(), 'examples', '*.txt') 187 | files = glob(path) 188 | for file in files: 189 | with open(file, 'r') as fp: 190 | parse(fp.read(), language.Code) 191 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27, py33, py34, py35, flake8 3 | 4 | [testenv:flake8] 5 | basepython=python 6 | deps=flake8 7 | commands=flake8 flowgen 8 | 9 | [testenv] 10 | setenv = 11 | PYTHONPATH = {toxinidir}:{toxinidir}/flowgen 12 | 13 | commands = python setup.py test 14 | 15 | ; If you want to make tox run the tests with the same versions, create a 16 | ; requirements.txt with the pinned versions and uncomment the following lines: 17 | ; deps = 18 | ; -r{toxinidir}/requirements.txt 19 | --------------------------------------------------------------------------------