Skip to content

Commit

Permalink
chore: pep8 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrf0rtuna4 committed Aug 6, 2024
1 parent 6987c49 commit 7f7d927
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/translate-readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

push:
branches:
- master
- master

jobs:
translate:
Expand Down
3 changes: 2 additions & 1 deletion core/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .config import Config
""" Core's for app """
from .config import Config
4 changes: 3 additions & 1 deletion core/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" App methods and classes """

from .localization_manager import LocalizationManager
from .logger import log_error, log_info
from .markdown_processor import MarkdownProcessor
from .readme_handler import ReadmeHandler
from .readme_handler import ReadmeHandler
29 changes: 25 additions & 4 deletions core/app/localization_manager.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
"""
MIT License
Copyright (c) 2024 Mr_Fortuna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import asyncio
import os

import deep_translator

from app.readme_handler import ReadmeHandler
from app.markdown_processor import MarkdownProcessor
from app.logger import log_info, log_error
from app.markdown_processor import MarkdownProcessor
from app.readme_handler import ReadmeHandler

ERR_CODE_FAILED_TO_TRANSLATE = -1
ERR_CODE_FAILED_TO_WRITE = -2
Expand Down Expand Up @@ -48,7 +70,6 @@ async def update_localizations(self):

chunks, _ = self.processor.decompile_readme(readme_content)
languages = [lang.strip() for lang in self.langs.split(",")]
files = []

if not os.path.exists(self.dist_dir):
os.makedirs(self.dist_dir)
Expand Down
26 changes: 26 additions & 0 deletions core/app/logger.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
"""
MIT License
Copyright (c) 2024 Mr_Fortuna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import logging

logging.basicConfig(level=logging.INFO, format='%(levelname)s - %(message)s')


def log_error(message):
logging.error(message)


def log_info(message):
logging.info(message)
25 changes: 25 additions & 0 deletions core/app/markdown_processor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
"""
MIT License
Copyright (c) 2024 Mr_Fortuna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import re
import uuid

from app.logger import log_info, log_error


Expand Down Expand Up @@ -86,6 +110,7 @@ def build_readme(self, translated_chunks, lang):
Rebuild the translated chunks into a complete translated README content.
:param translated_chunks: List of translated text chunks.
:param lang: Language for build
:return: Translated README content.
"""
translated_content = " ".join(translated_chunks)
Expand Down
28 changes: 26 additions & 2 deletions core/app/readme_handler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
from app.logger import log_info, log_error
"""
MIT License
Copyright (c) 2024 Mr_Fortuna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""


class ReadmeHandler:
def __init__(self, file_path):
Expand All @@ -24,7 +47,8 @@ async def decompile_readme(self, processor):
chunks, placeholder_map = processor.decompile_readme(readme_content)
return chunks, placeholder_map

async def build_readme(self, translated_chunks, processor):
@staticmethod
async def build_readme(translated_chunks, processor):
"""
Rebuild the translated chunks into a complete translated README content using MarkdownProcessor.
Expand Down
27 changes: 27 additions & 0 deletions core/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
"""
MIT License
Copyright (c) 2024 Mr_Fortuna
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""

import asyncio
import os

from dotenv import load_dotenv

from app import LocalizationManager, log_info, log_error

load_dotenv()


async def main():
log_info("💚 AutoLocalizator | by mr_f0rtuna4")
selected_langs = os.getenv("LANGS")
Expand All @@ -15,5 +41,6 @@ async def main():
manager = LocalizationManager(selected_langs)
await manager.update_localizations()


if __name__ == "__main__":
asyncio.run(main())

0 comments on commit 7f7d927

Please sign in to comment.