The diagrams were interesting so I tried wrapping them with flask

What is diagrams

It is software that can draw an architecture diagram with python.

https://diagrams.mingrammer.com

A few days ago, my motivation was that I wanted to do something like the following about my eyes.

<img src='http://localhost:8080/?
with Diagram("Grouped Workers", show=False, direction="TB"):
    ELB("lb") >> [EC2("worker1"),
                  EC2("worker2"),
                  EC2("worker3"),
                  EC2("worker4"),
                  EC2("worker5")] >> RDS("events")

For the time being, I will finally make it

I wrestled for about 10 hours and created it. The complete source code is the following repository.

https://github.com/tamuto/diagrams-server

Compile Python code

First and foremost, the question is how to compile the Python source code passed in the URL? is. It's okay to get it from query_string, but you have to format it and then compile it. I used yapf as a library.

PROBLEM TO BE SOLVED: To have no line feed code in query_string in the first place.

I was planning to have them describe it, including the import statement, as it is posted in examples. However, the query_string is attached like ``` ... import EC2from ...` ````, and even if it is formatted, it cannot be separated (obviously).

Change arguments using AST

Here, we were able to implement the expected behavior. It is rewritten using NodeTransformer, compiled and executed by exec. I got an error saying that there was no lineno on the way, but I solved it safely with `ast.fix_missing_location`. (I think I did ...)

Forcibly requesting an icon ...

If you output with svg, an icon request will be generated separately. I forcibly processed it with Flask's route. (Because it is running in docker, it should be allowed !?)

Other issues

I tried my best to make it, but I think there are various problems.

Normally, it should be written as an issue ...

For some reason, I rushed to release it with a time trial feeling. After this, I would like to sit down and respond.

Recommended Posts

The diagrams were interesting so I tried wrapping them with flask
I tried linebot with flask (anaconda) + heroku
I tried playing with the image with Pillow
I tried "smoothing" the image with Python + OpenCV
I tried "differentiating" the image with Python + OpenCV
I tried to save the data with discord
I tried Flask with Remote-Containers of VS Code
I tried "binarizing" the image with Python + OpenCV
I tried playing with the calculator on tkinter
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to solve the problem with Python Vol.1
Work memo that I tried i18n with Flask app
I tried hitting the API with echonest's python client
I wanted to run the motor with Raspberry Pi, so I tried using Waveshare's Motor Driver Board
I tried to find the entropy of the image with python
I tried "gamma correction" of the image with Python + OpenCV
I tried to simulate how the infection spreads with Python
I tried to analyze the whole novel "Weathering with You" ☔️
I tried using the Python library from Ruby with PyCall
I tried to find the average of the sequence with TensorFlow
I tried to notify the train delay information with LINE Notify
I tried replacing the Windows 10 HDD with a smaller SSD
I tried using the DS18B20 temperature sensor with Raspberry Pi
I tried saving the DRF API request history with django-request
I tried to divide the file into folders with Python
I tried fp-growth with python
I tried scraping with Python
I tried Learning-to-Rank with Elasticsearch!
I tried clustering with PyCaret
I tried the changefinder library!
I tried gRPC with Python
I tried scraping with python
I tried to expand the database so that it can be used with PES analysis software
I don't really understand the difference between modules, packages and libraries, so I tried to organize them.
PySpark learning record ② Kaggle I tried the Titanic competition with PySpark binding
I tried scraping the ranking of Qiita Advent Calendar with Python
[AWS / Tello] I tried operating the drone with my voice Part2
I tried to describe the traffic in real time with WebSocket
I tried to solve the ant book beginner's edition with python
I tried to automate the watering of the planter with Raspberry Pi
I tried cross-validation based on the grid search results with scikit-learn
I tried to process the image in "sketch style" with OpenCV
I tried sending an email from the Sakura server with flask-mail
[AWS / Tello] I tried operating the drone with my voice Part1
I tried to process the image in "pencil style" with OpenCV
I tried to expand the size of the logical volume with LVM
I tried running the DNN part of OpenPose with Chainer CPU
I tried to improve the efficiency of daily work with Python
I tried Diagram as Code (Diagrams) which can manage the configuration diagram code
I tried running the TensorFlow tutorial with comments (_TensorFlow_2_0_Introduction for beginners)
I tried the TensorFlow tutorial 1st
I tried the Naro novel API 2
I tried trimming efficiently with OpenCV
I tried summarizing sentences with summpy
I tried machine learning with liblinear
I tried web scraping with python.
Run the app with Flask + Heroku
I tried moving food with SinGAN
I tried the TensorFlow tutorial 2nd
I tried implementing DeepPose with PyTorch