hedyorg / hedy

Hedy is a gradual programming language to teach children programming. Gradual languages use different language levels, where each level adds new concepts and syntactic complexity. At the end of the Hedy level sequence, kids master a subset of syntactically valid Python.
https://www.hedy.org
European Union Public License 1.2
1.32k stars 289 forks source link

[BUG] Level is 0 by default when running from command line #1341

Closed ibsenrune closed 2 years ago

ibsenrune commented 2 years ago

If you do a clean checkout and try to run a simple Hedy program from the command line, you get an error because the level hasn’t been set properly.

Steps to reproduce:

  1. Do a clean checkout
  2. Run
$ python3 -m venv .env
$ source .env/bin/activate
(.env)$ pip install -r requirements.txt
  1. Create a file, hello.hedy, with the following contents:
print Hello World!

Then run the program from the command line according to this description:

(.env)$ python3 runhedy.py hello.hedy
An error occurred: Invalid Argument Type
Error attributes:
command=print
invalid_type=string
allowed_types=[]
invalid_argument=
(.env)$

I expected the program to print Hello World!.

As far as I can tell, the error happens because the Hedy source file doesn’t declare a level. And indeed, if you explicitly provide a level, the program works:

(.env)$ python3 runhedy.py hello.hedy —level 1
Hello World!
(.env)$

According to the docs here, indicating a level is only necessary if you want to use a level besides level 1. Thus, I think the example provided above should have worked.

As far as I can tell, there are two options for fixing this:

  1. Change the documentation in CONTRIBUTING.md to say that you always need to indicate a level, or
  2. Fix the source code around here in runhedy.py so that level is set to 1 if it hasn’t been set by a command line flag or a declaration in the source file (AFAICT, it is left as 0 if not otherwise specified).

Despite never having written a single line of Python, I am happy to take a stab at fixing either the documentation or the Python code :-)

PS. Thank you for the chat “at” Build Stuff @Felienne

Felienne commented 2 years ago

Hi @ibsenrune!

It was nice chatting with you yesterday.

I think option 1 is way easier and the better way to go. Supporting Hedy from the command line is not really something we support very actively, and my suspicion is that you will run into a few more issues if you test it further, so sorry in advance :) Our intended audience of school teachers and kids is not so likely to use Hedy that way.