-
-
Notifications
You must be signed in to change notification settings - Fork 15
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
Initial translation mechanism setup #13
Open
thepabloaguilar
wants to merge
9
commits into
sobolevn:master
Choose a base branch
from
thepabloaguilar:issue-12-initial
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
541d341
feat: create script to render schemas
thepabloaguilar 1fd594d
feat: create docker files
thepabloaguilar 23d86af
chore: render schemas with script
thepabloaguilar 81d61e7
chore: create GitHub Action to test generated schemas
thepabloaguilar 6d00dc7
feat: finish schemas setup
thepabloaguilar 0a476c6
chore: remove duplicated "backend"
thepabloaguilar 8a33c5f
chore: rename `reset` to `discard`
thepabloaguilar 259f1af
chore: rename `hidden_card` to `face_down_card`
thepabloaguilar 5ee378a
chore: move `certificate` to the right card type
thepabloaguilar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/** | ||
!requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,6 @@ end_of_line = lf | |
indent_style = space | ||
insert_final_newline = true | ||
indent_size = 2 | ||
|
||
[*.py] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
test-schemas: | ||
runs-on: ubuntu-latest | ||
name: Test if schemas were generated | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: isbang/[email protected] | ||
with: | ||
up-flags: "--build" | ||
down-flags: "--volumes" | ||
|
||
- name: Generate images | ||
run: docker exec -i ship-it-boardgame-renderer-1 python render.py | ||
|
||
- name: Verify diff | ||
run: git diff --exit-code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM python:3.12-alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY . . | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
CMD [ "sleep", "infinity" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: '3' | ||
services: | ||
renderer: | ||
build: | ||
dockerfile: Dockerfile | ||
depends_on: | ||
image-export: | ||
condition: service_healthy | ||
volumes: | ||
- "./render.py:/app/render.py" | ||
- "./ru:/app/ru" | ||
image-export: | ||
image: jgraph/export-server | ||
healthcheck: | ||
test: [ "CMD-SHELL", "if [ $(curl -o /dev/null -s -w '%{http_code}\n' http://localhost:8000) -ne '400' ]; then exit 1; fi;" ] | ||
interval: 2s | ||
timeout: 5s | ||
retries: 5 | ||
ports: | ||
- "8000:8000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,52 @@ | ||||||
import shutil | ||||||
import logging | ||||||
from typing import Final | ||||||
|
||||||
import yaml | ||||||
import requests | ||||||
from jinja2 import Environment, FileSystemLoader, select_autoescape | ||||||
|
||||||
logging.basicConfig( | ||||||
format='%(asctime)s %(message)s', | ||||||
datefmt='%Y-%m-%d %H:%M:%S', | ||||||
level=logging.INFO, | ||||||
) | ||||||
logger = logging.getLogger(__name__) | ||||||
|
||||||
# Add your language folder below when it's ready to be rendered | ||||||
LANGUAGE_FOLDERS: Final = {'ru'} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
|
||||||
def render_schemas(language: str) -> None: | ||||||
logger.info('[%s] rendering language', language) | ||||||
|
||||||
with open(f'{language}/schemas-info.yml') as f: | ||||||
info = yaml.safe_load(f) | ||||||
|
||||||
for template_name in env.list_templates(): | ||||||
logger.info('[%s] rendering template "%s"', language, template_name) | ||||||
|
||||||
rendered = env.get_template(template_name).render(**info) | ||||||
|
||||||
logger.info('[%s] generating schema image from template', language) | ||||||
response = requests.post( | ||||||
'http://image-export:8000/', | ||||||
json={'format': 'jpg', 'xml': rendered}, | ||||||
stream=True, | ||||||
) | ||||||
assert response.status_code == 200, response.text | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
image_name, *_ = template_name.split('.') | ||||||
logger.info('[%s] saving image %s.jpg', language, image_name) | ||||||
with open(f'{language}/schemas/{image_name}.jpg', 'wb') as f: | ||||||
shutil.copyfileobj(response.raw, f) | ||||||
|
||||||
|
||||||
if __name__ == '__main__': | ||||||
env = Environment( | ||||||
loader=FileSystemLoader('ru/schema-sources'), | ||||||
autoescape=select_autoescape(), | ||||||
) | ||||||
|
||||||
for language in LANGUAGE_FOLDERS: | ||||||
render_schemas(language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
certifi==2024.2.2 | ||
charset-normalizer==3.3.2 | ||
idna==3.6 | ||
Jinja2==3.1.3 | ||
MarkupSafe==2.1.5 | ||
PyYAML==6.0.1 | ||
requests==2.31.0 | ||
urllib3==2.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this file to
tools/
and name it
render-diagram.py