http://www.picpedia.org/highway-signs/c/conversion.html

From custom Wordpress to Flask and Python in a blink of an eye

Nicolas Rodriguez
7 min readNov 30, 2018

--

A few months ago I had a talk with a client about an ongoing effort on his part to ditch Wordpress (and PHP) and establish a Python-only shop. His employees are all Python programmers and most of the shop’s backbone is coded in PHP.

Their PHP code is a relatively ancient custom patched Wordpress instance… and a real mess I got to admit. He consult me about the best way to rewrite the PHP code with the little PHP resources available he had. I started describing a fairly painless way to migrate the code to Python (probably taking a performance hit which is easily fixable throwing more resources at the problem) and iteratively making its way to a more idiomatic Python code, using an custom made automated transpiler (also known as source-to-source compiler).

I know it is a lot to take in, and most people working in development (always talking from my perspective) are closed-minded about such an endeavour. The first reaction from their team was the classic “that cannot be done!” (or “it is the same effort as rewriting the whole code”).

I proceed to describe them the idea in more detail. In essence:

  1. Convert the PHP code to some form of abstract syntax tree (AST)
  2. Parse the AST nodes and spit out Python code

--

--

Nicolas Rodriguez

IT Security Consultant. Programmer. Analyst. Network Administrator. 30 years working with computers.