Basic functionality of string_to_code
is to generate
a piece of messy code printing a given string.
For example
def f_1():
print('H', end='')
print('e', end='')
def f_2():
print('l', end='')
print('l', end='')
def f_5():
print(',', end='')
print(' ', end='')
def f_4():
print('o', end='')
f_5()
print('W', end='')
def f_6():
print('o', end='')
print('r', end='')
print('l', end='')
def f_3():
f_4()
f_6()
def f_7():
print('d', end='')
print('!', end='')
def f_0():
f_1()
f_2()
f_3()
f_7()
f_0()
is a python
program generated with
string_to_code.to_python3
displaying Hello, World!
.
This package is available at PyPI. It can be installed using the command
pip install string-to-code
In order to generate a code in your_favourite_language
just call the function
string_to_code.to_your_favourite_language.proc
with the string which you want to display.
examples
show some basic usage.
The project is setup using poetry. In order to create a develompent enviroment, after cloning this repository, run the command:
poetry install --with dev
Have a look at Running tests locally section.
If you just want to see the examples in action, it is enough to clone this repository and run the command:
poetry install
Afterwards you can execute the commands like:
poetry run python3 examples/example_to_cpp.py
If you think that string_to_code
is missing some
language, feel free to add it - it is simple.
If you want to add support of let's say turbo_snake
,
there are few things which you need to do:
-
create
to_turbo_snake.py
instring_to_code
. This module should define two functionproc
andproc_printer_program
. Theproc
function returns aturbo_snake
program displaying the input string. Theproc_printer_program
returns aturbo_snake
representation of the givencore.PrinterProgram
object.Have a look at the existing modules.
-
create
setup_turbo_snake.py
intests
. This file is used for tests. It should contain a functionget_test_data()
returning aLanguage
object having fields like:tool_names
: a list of program names (compilers, interpreters, linters etc.) used for executing and analysing the generated code,string_to_code
being the functionstring_to_code.to_turbo_snake.proc
,printer_program_to_code
being the functionstring_to_code.to_turbo_snake.proc_printer_program
,run_code
: the function, which executes the generated code and returns the standard output,id
: the id of the language, most likelyturbo_snake
,source_code_file_extension
: in case ofturbo_snake
something likets
.
-
create
setup_for_turbo_snake.sh
orsetup_no_sudo_for_turbo_snake.sh
insystem_setup_scripts
. These scripts are used by the workflows to install programs needed to execute corresponding tests - cf. stepInstall language dependencies
inpython_test.yml
andgenerate_and_upload_coverage_data.yml
, and.gitpod.dockerfile
. -
create and populate the
turbo_snake
directory intests/example_data
. These files should contain theturbo_snake
sourcecode of some basic programs. Please have a look at the already existing examples.
tests
use pytest
.
If you do not want to run the tests for all of the languages
(because it takes too long
or you do not want to install all of the required tools)
you can skip some of them by using the --skip
option.
For example, in order to skip
bash
, C++
and
Lisp
run the command
poetry run pytest --skip=bash --skip=cpp --skip=lisp
You can also specify the languages which you want to test by using
--select
option.
For example to run tests for C++
and
COBOL
exclusively execute
poetry run pytest --select=cpp --select=cobol
Without installing any language dependencies from
system_setup_scripts
you should be able
to successfully execute the command
poetry run pytest --select=python3
This project is setup to be used with gitpod.