Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚚 Don't rewrite emoji in YAML files #5273

Merged
merged 12 commits into from
Mar 18, 2024
11 changes: 1 addition & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,4 @@ repos:
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
# INSTRUCTIONS: after enabling this, run `pre-commit run --all` to clean up all content files
- repo: local
hooks:
- id: content_yaml_autoformat
name: content yaml autoformatting
entry: tools/rewrite-content-yaml.py
files: 'content/.*\.ya?ml'
language: python
additional_dependencies: ['PyYAML==6.0.1', 'ruamel.yaml==0.17.4']
- id: flake8
4 changes: 2 additions & 2 deletions content/adventures/ar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ adventures:
### Exercise 2
Go back to the previous level and copy your story code. Make the code work in this level by adding quotation marks in the right spots.
Mind: The variables in your own story should be outside of the quotation marks. Just like the second line of the example code. In that line the variable name is placed outside of the quotation marks.
example_code: "```\nالاسم {is} حسن \n{print} _الاسم الأول للشخصية الرئيسية في القصة هو_ الاسم\n{print} الاسم _ذاهبٌ الآن للسير في الغابة_\n{print} الاسم _خائفٌ قليلًا_\nالحيوانات {is} \U0001F994, \U0001F43F, \U0001F989, \U0001F987\n{print} _لقد سمع صوت_ الحيوانات {at} {random}\n{print} الاسم _خائفٌ أن تكون هذه الغابة مسكونة_\n```\n"
example_code: "```\nالاسم {is} حسن \n{print} _الاسم الأول للشخصية الرئيسية في القصة هو_ الاسم\n{print} الاسم _ذاهبٌ الآن للسير في الغابة_\n{print} الاسم _خائفٌ قليلًا_\nالحيوانات {is} 🦔, 🐿, 🦉, 🦇\n{print} _لقد سمع صوت_ الحيوانات {at} {random}\n{print} الاسم _خائفٌ أن تكون هذه الغابة مسكونة_\n```\n"
5:
story_text: |
في هذا المستوى تستطيع برمجة نهايات مختلفة، والتي ستجعل قصتك اكثر متعة
Expand Down Expand Up @@ -3188,7 +3188,7 @@ adventures:
في المستوى ١ ستتمكن من صنع مطعم افتراضي وتأخذ طلبات الطعام الخاصة بضيوفك.
story_text_2: |
هل يمكنك التفكير في عدة سطور اخرى تضيفها لتطور كود مطعمك؟ على سبيل المثال، هل يمكنك استخدام `{ask}` لسؤال الضيوف ماذا يفضلون كشراب بجانب وجبتهم، وبعد ذلك اخبارهم بسعر طلبهم، و ان تتمنى لهم وجبة هنيئة؟
example_code_2: "```{print} \U0001F35F اهلاً بكم في مطعم هيدي \n{ask} ماذا تود ان تطلب؟\n{echo} اذاً، طلبك هو \n{print} شكرًا لطلبكم من مطعمنا!\n{print} طلبك في طريقه إليك!\n ```\n"
example_code_2: "```{print} 🍟 اهلاً بكم في مطعم هيدي \n{ask} ماذا تود ان تطلب؟\n{echo} اذاً، طلبك هو \n{print} شكرًا لطلبكم من مطعمنا!\n{print} طلبك في طريقه إليك!\n ```\n"
2:
story_text: |
في المستوى 2 ستتمكن من تطوير مطعمك باستخدام المتغيرات، في المستوى الأول، كانت هيدي تستطيع فقط أن تردد طلبك باستخدام الأمر `{echo} ` وكان باستطاعتها أخذ طلب واحد فقط.
Expand Down
11 changes: 5 additions & 6 deletions content/adventures/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1358,12 +1358,11 @@ adventures:
print 'Dostala jsem správnou odpověď!'
16:
story_text: Už i naše seznamy mají vlastní závorky! Budeme je psát do hranatých závorek a jejich jednotlivé položky do jednoduchých uvozovek ('), které už známe.
example_code: |4

```
ovoce = ['jablko', 'banán', 'třešně']
print ovoce
```
example_code: |
```
ovoce = ['jablko', 'banán', 'třešně']
print ovoce
```
17:
story_text: |-
Nyní trochu změníme odsazení. Pokaždé, když potřebujeme odsazení, je třeba zapsat znak `:` na řádku před tímto odsazením.
Expand Down
2 changes: 1 addition & 1 deletion content/adventures/pl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3246,7 +3246,7 @@ adventures:
Następnie dodaj co najmniej 4 kolejne linie kodu do programu restauracji.
Zapytaj klienta, co chciałby wypić i czy chce zapłacić gotówką, czy kartą.
Na koniec wymyśl jakiś miły sposób pożegnania się z klientem.
example_code_2: "``` \n{print} Witaj w restauracji Hedy \U0001F35F\n_ Co chcesz zamówić?\n {echo} A więc chcesz zamówić\n{print} Dziękuje za zamówienie!\n{print} Zaraz podamy!\n```\n"
example_code_2: "``` \n{print} Witaj w restauracji Hedy 🍟\n_ Co chcesz zamówić?\n {echo} A więc chcesz zamówić\n{print} Dziękuje za zamówienie!\n{print} Zaraz podamy!\n```\n"
2:
story_text: |
Na poziomie 2 możesz rozbudować swoją restaurację za pomocą zmiennych. Na poziomie 1 Hedy mogła wyświetlić {echo} zamówienie tylko raz i pamiętała tylko ostatnią zamówioną rzecz.
Expand Down
2 changes: 1 addition & 1 deletion content/adventures/tn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3310,7 +3310,7 @@ adventures:
Then add at least 4 more lines of code to the restaurant program.
Ask the costumer what they would like to drink and ask if they want to pay with cash or card.
Lastly, think of a nice way to say goodbye to your costumer.
example_code_2: "```\n{print} Re a go amogela mo semausung sa Mosaditshwene \U0001F35F\n{ask} O bata go reka eng?\n{echo} Good, so o bata go reka \n{print} Thanks you for your order!\n{print} Dijo tsa gago di eta!\n```\n"
example_code_2: "```\n{print} Re a go amogela mo semausung sa Mosaditshwene 🍟\n{ask} O bata go reka eng?\n{echo} Good, so o bata go reka \n{print} Thanks you for your order!\n{print} Dijo tsa gago di eta!\n```\n"
2:
story_text: |
In level 2 you could expand your restaurant by using variables. In level 1 Hedy could only `{echo}` the order once and only remember the last thing that was ordered.
Expand Down
22 changes: 21 additions & 1 deletion dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ def task_devserver():
)


def task_normalize_yaml():
"""Normalize the YAML files by running a script.

Makes indentation and key ordering uniform, even if the files get rewritten by
Weblate.
"""
yamls = glob('content/**/*.yaml', recursive=True)

return dict(
title=lambda _: 'Normalize YAML',
file_dep=[
'tools/rewrite-content-yaml.py',
*yamls,
],
actions=[
[python3, 'tools/rewrite-content-yaml.py', *yamls]
]
)


######################################################################################
# Some useful task groups
#
Expand Down Expand Up @@ -408,13 +428,13 @@ def task__autopr():
'extract',
'backend',
'frontend',
'normalize_yaml',
],
actions=[
# Run a script to strip things that lead to conflicts from po files
[python3, 'build-tools/github/normalize-pofiles.py'],
])


######################################################################################
# Below this line are helpers for the task definitions
#
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Flask-Commonmark==1.0.4
bcrypt==3.2.0
boto3>=1.16.50
MarkupSafe==2.1.2
ruamel.yaml==0.17.4
ruamel.yaml==0.18.6
docopt==0.6.2
pydantic==1.8.2
lazy==1.4
Expand Down
26 changes: 19 additions & 7 deletions tools/rewrite-content-yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,7 @@ def main():
filenames = sys.argv[1:]

with Pool() as p:
changes = p.map(rewrite_yaml_file, filenames)

if any(changes):
sys.exit(1)
else:
sys.exit(0)
p.map(rewrite_yaml_file, filenames)


def rewrite_yaml_file(fn):
Expand Down Expand Up @@ -146,11 +141,28 @@ def custom_rewrite_data(obj, strip_strings):
for key in sorted(obj.keys()):
copy[key] = custom_rewrite_data(obj[key], strip_strings)
return copy
elif isinstance(obj, list):
if isinstance(obj, list):
# with lists simply recurse into the directory structure
for (i, el) in enumerate(obj):
obj[i] = custom_rewrite_data(el, strip_strings)
return obj
if isinstance(obj, str):
# No string ever needs to have leading whitespace, and it messes
# with rendering and parsing.
#
# We could talk about trailing whitespace, but the lack of a trailing
# `\n` forces the block indicator to `|-` instead of `|`, and it ultimately
# doesn't matter that much.
#
# We could also force all (multiline) strings to be `|` blocks here if
# we wanted to. For now, we're just messing with things that cause problems.
#
# Only replace the original object if we have a change, to not
# destroy YAML metadata that may be attached to the string.
stripped = obj.lstrip()
clazz = type(obj)

return clazz(stripped) if obj != stripped else obj
# everything else we leave alone
return obj

Expand Down
Loading