Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 79204a473e | |||
| 0802e81d41 | |||
| 2545d7ed9a | |||
| 4c104baf4f | |||
| 619a1b2660 | |||
| 8b2bf776e2 | |||
| 7f2018c83b | |||
| 94f989c282 | |||
| 37c7ed6218 | |||
| 98c1721db6 | |||
| 431e328909 | |||
| 35b3ede9e2 | |||
| c9059f2da8 |
28
.gitea/workflows/ci.yml
Normal file
28
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
name: Pack Validation CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
pull_request:
|
||||
branches: ["main"]
|
||||
|
||||
jobs:
|
||||
validate:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Install Test Dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install pytest
|
||||
|
||||
- name: Run Pack Verification Suite
|
||||
run: python -m pytest tests/ -v
|
||||
80
.gitea/workflows/publish.yml
Normal file
80
.gitea/workflows/publish.yml
Normal file
@@ -0,0 +1,80 @@
|
||||
name: Publish Language Pack
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*" # Fires directly on v0.1.0, v0.2.0 etc.
|
||||
|
||||
jobs:
|
||||
# Enforce that tests MUST pass before release can execute
|
||||
verify:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.11"
|
||||
- name: Install and Verify
|
||||
run: |
|
||||
pip install pytest
|
||||
pytest tests/ -v
|
||||
|
||||
publish:
|
||||
needs: verify # Blocks execution if verify job fails
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.11"
|
||||
|
||||
- name: Install Release Tools
|
||||
run: pip install build twine
|
||||
|
||||
- name: Build Wheel and Source Distribution
|
||||
# Automatically detects pyproject.toml and builds the correct pack
|
||||
run: python -m build .
|
||||
|
||||
- name: Publish Package to PyPI
|
||||
env:
|
||||
TWINE_USERNAME: __token__
|
||||
# Inherits your clean Organization level secret
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
|
||||
run: twine upload --skip-existing dist/*
|
||||
|
||||
- name: Build Gitea Release with Assets
|
||||
env:
|
||||
# Pulls your clean Organization level Gitea Token
|
||||
GIT_RELEASE_TOKEN: ${{ secrets.GIT_RELEASE_TOKEN }}
|
||||
run: |
|
||||
TAG=${GITHUB_REF#refs/tags/}
|
||||
REPO_NAME=${{ github.event.repository.name }}
|
||||
|
||||
# Delete existing release block if present
|
||||
EXISTING=$(curl -s -H "Authorization: token $GIT_RELEASE_TOKEN" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/tags/$TAG")
|
||||
EXISTING_ID=$(echo $EXISTING | python -c "import sys,json; d=json.load(sys.stdin); print(d.get('id',''))" 2>/dev/null || echo "")
|
||||
if [ -n "$EXISTING_ID" ]; then
|
||||
curl -s -X DELETE -H "Authorization: token $GIT_RELEASE_TOKEN" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$EXISTING_ID"
|
||||
fi
|
||||
|
||||
# Create fresh production release container
|
||||
RELEASE=$(curl -s -X POST \
|
||||
-H "Authorization: token $GIT_RELEASE_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"tag_name\": \"$TAG\",
|
||||
\"name\": \"$TAG\",
|
||||
\"body\": \"Language pack release version $TAG for the foreignthon transpiler framework.\",
|
||||
\"draft\": false,
|
||||
\"prerelease\": false
|
||||
}" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases")
|
||||
|
||||
RELEASE_ID=$(echo $RELEASE | python -c "import sys,json; print(json.load(sys.stdin)['id'])")
|
||||
|
||||
# Upload wheels directly into Gitea Assets tab
|
||||
for FILE in dist/*; do
|
||||
curl -s -X POST -H "Authorization: token $GIT_RELEASE_TOKEN" -F "attachment=@$FILE" "${{ github.server_url }}/api/v1/repos/${{ github.repository }}/releases/$RELEASE_ID/assets"
|
||||
done
|
||||
21
.gitea/workflows/trigger-docs.yml
Normal file
21
.gitea/workflows/trigger-docs.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
name: Trigger Docs Rebuild
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["main"]
|
||||
paths:
|
||||
- "README.md"
|
||||
|
||||
jobs:
|
||||
trigger:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Trigger docs rebuild
|
||||
env:
|
||||
DOCS_TOKEN: ${{ secrets.DOCS_TRIGGER_TOKEN }}
|
||||
run: |
|
||||
curl -s -X POST \
|
||||
-H "Authorization: token $DOCS_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"ref": "main"}' \
|
||||
"https://git.keshavanand.net/api/v1/repos/foreign-thon/foreignthon-docs/actions/workflows/deploy.yml/dispatches"
|
||||
107
README.md
107
README.md
@@ -1 +1,108 @@
|
||||
# foreignthon-es
|
||||
|
||||
Spanish language pack for [ForeignThon](https://foreignthon.keshavanand.net/) — write Python in Español.
|
||||
|
||||
---
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
pip install foreignthon foreignthon-es
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
|
||||
**`fizzbuzz.es.py`**
|
||||
|
||||
```python
|
||||
def fizzbuzz(n):
|
||||
para i en dist(1, n + 1):
|
||||
si i % 15 == 0:
|
||||
imprimir("FizzBuzz")
|
||||
osi i % 3 == 0:
|
||||
imprimir("Fizz")
|
||||
osi i % 5 == 0:
|
||||
imprimir("Buzz")
|
||||
sino:
|
||||
imprimir(i)
|
||||
|
||||
fizzbuzz(20)
|
||||
```
|
||||
|
||||
Compiles to standard Python:
|
||||
|
||||
```python
|
||||
def fizzbuzz(n):
|
||||
for i in range(1, n + 1):
|
||||
if i % 15 == 0:
|
||||
print("FizzBuzz")
|
||||
elif i % 3 == 0:
|
||||
print("Fizz")
|
||||
elif i % 5 == 0:
|
||||
print("Buzz")
|
||||
else:
|
||||
print(i)
|
||||
|
||||
fizzbuzz(20)
|
||||
```
|
||||
|
||||
Run it directly:
|
||||
|
||||
```bash
|
||||
fpy run fizzbuzz.es.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Keyword reference
|
||||
|
||||
| Python | Español |
|
||||
|---|---|
|
||||
| `if` | `si` |
|
||||
| `else` | `sino` |
|
||||
| `elif` | `osi` |
|
||||
| `for` | `para` |
|
||||
| `while` | `mientras` |
|
||||
| `def` | `def` |
|
||||
| `class` | `clase` |
|
||||
| `return` | `retornar` |
|
||||
| `import` | `importar` |
|
||||
| `True` | `Verda` |
|
||||
| `False` | `Falso` |
|
||||
| `None` | `Nada` |
|
||||
| `print` | `imprimir` |
|
||||
| `input` | `entrada` |
|
||||
| `len` | `lon` |
|
||||
| `range` | `dist` |
|
||||
|
||||
Full mapping: [`src/foreignthon_es/es.json`](https://git.keshavanand.net/foreign-thon/foreignthon-es/raw/branch/main/src/foreignthon_es/es.json)
|
||||
|
||||
---
|
||||
|
||||
## Start a project
|
||||
|
||||
```bash
|
||||
fpy new myproject --lang es
|
||||
cd myproject
|
||||
fpy run src/main.es.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Documentation
|
||||
|
||||
→ [foreignthon.keshavanand.net](https://foreignthon.keshavanand.net/)
|
||||
|
||||
---
|
||||
|
||||
## Contributing
|
||||
|
||||
Found a missing translation or a better keyword choice? Open an issue or PR — no access to the core repo needed.
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
GPL v3
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "foreignthon-es"
|
||||
version = "0.3.0"
|
||||
version = "0.3.2"
|
||||
description = "Spanish language pack for ForeignThon."
|
||||
license = { text = "GPL v3" }
|
||||
requires-python = ">=3.9"
|
||||
@@ -14,7 +14,17 @@ authors = [
|
||||
]
|
||||
keywords = ["foreignthon", "spanish", "español"]
|
||||
|
||||
dependencies = ["foreignthon>=0.5.2"]
|
||||
dependencies = ["foreignthon>=0.5.3"]
|
||||
|
||||
classifiers = [
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
||||
"Operating System :: OS Independent",
|
||||
"Topic :: Software Development :: Compilers",
|
||||
]
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://git.keshavanand.net/foreign-thon/foreignthon-ta"
|
||||
|
||||
[project.entry-points."foreignthon.langs"]
|
||||
es = "foreignthon_es"
|
||||
|
||||
114
tests/test_pack.py
Normal file
114
tests/test_pack.py
Normal file
@@ -0,0 +1,114 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import builtins
|
||||
import json
|
||||
import keyword
|
||||
from pathlib import Path
|
||||
import pytest
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Dynamic Discovery: Find the pack file in this specific repository
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def find_pack_file() -> Path:
|
||||
"""Scans the repository root for a Foreignthon language pack JSON."""
|
||||
repo_root = Path(__file__).parent.parent
|
||||
|
||||
for path in repo_root.rglob("*.json"):
|
||||
# Ignore virtual environments, cache files, and CI directories
|
||||
ignored_dirs = {".venv", "venv", ".git", ".pytest_cache", ".gitea", ".github"}
|
||||
if any(part in path.parts for part in ignored_dirs):
|
||||
continue
|
||||
|
||||
# Peek inside the JSON to see if it's a Foreignthon pack
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
content = json.load(f)
|
||||
if "meta" in content and "keywords" in content:
|
||||
return path
|
||||
except (json.JSONDecodeError, KeyError, TypeError):
|
||||
continue
|
||||
|
||||
raise FileNotFoundError(
|
||||
"Could not find a valid Foreignthon language pack JSON file in this repository."
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Global Validation Sets
|
||||
# ---------------------------------------------------------------------------
|
||||
VALID_KEYWORDS = set(keyword.kwlist) | {"True", "False", "None"}
|
||||
VALID_BUILTINS = set(dir(builtins))
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# The Universal Test Suite
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def pack_data() -> tuple[Path, dict]:
|
||||
"""Loads the dynamically discovered pack file once for the test module."""
|
||||
path = find_pack_file()
|
||||
with open(path, encoding="utf-8") as f:
|
||||
return path, json.load(f)
|
||||
|
||||
|
||||
def test_meta_section_integrity(pack_data):
|
||||
path, data = pack_data
|
||||
assert "meta" in data, f"Missing 'meta' section in {path.name}"
|
||||
meta = data["meta"]
|
||||
|
||||
assert meta.get("name"), "meta.name cannot be empty"
|
||||
assert meta.get("native_name"), "meta.native_name cannot be empty"
|
||||
assert meta.get("code"), "meta.code cannot be empty"
|
||||
|
||||
# Enforce that the file name matches the language code (e.g., es.json matches code 'es')
|
||||
assert (
|
||||
path.stem == meta["code"]
|
||||
), f"Filename '{path.name}' must exactly match meta.code '{meta['code']}'"
|
||||
|
||||
|
||||
def test_keywords_integrity(pack_data):
|
||||
path, data = pack_data
|
||||
assert "keywords" in data, f"Missing 'keywords' section in {path.name}"
|
||||
|
||||
for foreign_word, python_keyword in data["keywords"].items():
|
||||
assert python_keyword in VALID_KEYWORDS, (
|
||||
f"Invalid target '{python_keyword}' for foreign keyword '{foreign_word}' in {path.name}. "
|
||||
"It is not a recognized Python keyword."
|
||||
)
|
||||
|
||||
|
||||
def test_builtins_and_exceptions_integrity(pack_data):
|
||||
path, data = pack_data
|
||||
|
||||
# Validate Builtins
|
||||
assert "builtins" in data, f"Missing 'builtins' section in {path.name}"
|
||||
for foreign_word, python_builtin in data["builtins"].items():
|
||||
assert (
|
||||
python_builtin in VALID_BUILTINS
|
||||
), f"Invalid target '{python_builtin}' for builtin function '{foreign_word}' in {path.name}."
|
||||
|
||||
# Validate Exceptions
|
||||
assert "exceptions" in data, f"Missing 'exceptions' section in {path.name}"
|
||||
for foreign_word, python_exception in data["exceptions"].items():
|
||||
assert (
|
||||
python_exception in VALID_BUILTINS
|
||||
), f"Invalid target '{python_exception}' for exception '{foreign_word}' in {path.name}."
|
||||
|
||||
|
||||
def test_postfix_keywords_integrity(pack_data):
|
||||
path, data = pack_data
|
||||
assert "postfix_keywords" in data, f"Missing 'postfix_keywords' section in {path.name}"
|
||||
assert isinstance(data["postfix_keywords"], list), "'postfix_keywords' must be an array/list"
|
||||
|
||||
# Extract all the English Python keywords that have been mapped in this pack
|
||||
mapped_python_targets = set(data["keywords"].values())
|
||||
|
||||
# Ensure any declared English postfix keyword actually has a mapped translation
|
||||
for post_kw in data["postfix_keywords"]:
|
||||
assert post_kw in mapped_python_targets, (
|
||||
f"English postfix keyword '{post_kw}' is missing from the mapped values "
|
||||
f"in the main 'keywords' dictionary in {path.name}."
|
||||
)
|
||||
Reference in New Issue
Block a user