Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork398
Mejorar script para encontrar diferencias de formato#1783
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:3.13
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
526a3f2518517d981ac285dbf45e0697764File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,111 @@ | ||
| importcollections | ||
| importre | ||
| importsys | ||
| frompathlibimportPath | ||
| frompprintimportpprint | ||
| fromtypingimportList | ||
| importpolib | ||
| _patterns= [ | ||
| ":c:func:`[^`]+`", | ||
| ":c:type:`[^`]+`", | ||
| ":c:macro:`[^`]+`", | ||
| ":c:member:`[^`]+`", | ||
| ":c:data:`[^`]+`", | ||
| ":py:data:`[^`]+`", | ||
| ":py:mod:`[^`]+`", | ||
| ":func:`[^`]+`", | ||
| ":mod:`[^`]+`", | ||
Comment on lines +11 to +19 Collaborator 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. Yo creo que esto se podría escribir de una forma más genérica usando más regex: Esa por ejemplo, encuentra "uno o más espacios luego del primer Encuentra un "un espacio luego del segundo De esta forma, solo tenemos que escribir "un par de regex" para encontrar los espacios en todas las posibles variaciones de todos los roles de Sphinx. ¿Qué te parece? Lo mismo se puede hacer para cursiva y negrita. CollaboratorAuthor 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. me parece super :D | ||
| ":ref:`[^`]+`", | ||
| ":class:`[^`]+`", | ||
| ":pep:`[^`]+`", | ||
| ":data:`[^`]+`", | ||
| ":exc:`[^`]+`", | ||
| ":term:`[^`]+`", | ||
| ":meth:`[^`]+`", | ||
| ":envvar:`[^`]+`", | ||
| ":file:`[^`]+`", | ||
| ":attr:`[^`]+`", | ||
| ":const:`[^`]+`", | ||
| ":issue:`[^`]+`", | ||
| ":opcode:`[^`]+`", | ||
| ":option:`[^`]+`", | ||
| ":program:`[^`]+`", | ||
| ":keyword:`[^`]+`", | ||
| ":RFC:`[^`]+`", | ||
| ":rfc:`[^`]+`", | ||
| ":doc:`[^`]+`", | ||
| "``[^`]+``", | ||
| "`[^`]+`__", | ||
| "`[^`]+`_", | ||
| r"\*\*[^\*]+\*\*",# bold text between ** | ||
| r"\*[^\*]+\*",# italic text between * | ||
| ] | ||
| _exps= [re.compile(e)forein_patterns] | ||
| defget_sphinx_directives(s:str)->List[str]: | ||
| """ | ||
| Parameters: | ||
| string containing the text to translate | ||
| Returns: | ||
| dictionary containing all the placeholder text as keys | ||
| and the correct value. | ||
| """ | ||
| output:List[str]= [] | ||
| forexpin_exps: | ||
| matches=exp.findall(s) | ||
| formatchinmatches: | ||
| output.append(match) | ||
| # remove the found pattern from the original string | ||
| s=s.replace(match,"") | ||
| returnoutput | ||
| defind(level=0): | ||
| returnf"{' '*4*level}" | ||
| if__name__=="__main__": | ||
| PO_DIR=Path(__file__).resolve().parent.parent | ||
| VENV_DIR=PO_DIR/"venv" | ||
| iflen(sys.argv)>1: | ||
| filename=sys.argv[1] | ||
| files= [] | ||
| iffilename: | ||
| ifPath(filename).is_dir(): | ||
| files= [iforiinPO_DIR.glob(f"{filename}/*.po")ifnoti.is_relative_to(VENV_DIR)] | ||
| elifnotPath(filename).is_file(): | ||
| print(f"File not found: '{filename}'") | ||
| sys.exit(-1) | ||
| else: | ||
| files= [filename] | ||
| else: | ||
| files= [iforiinPO_DIR.glob("**/**/*.po")ifnoti.is_relative_to(VENV_DIR)] | ||
| forpofilenameinfiles: | ||
| print(f"\n> Processing{pofilename}") | ||
| po=polib.pofile(pofilename) | ||
| forentryinpo: | ||
| directives_id=get_sphinx_directives(entry.msgid) | ||
| directives_str=get_sphinx_directives(entry.msgstr) | ||
| # Check if any of them is not empty | ||
| ifdirectives_idordirectives_str: | ||
| # Check if the directives are the same | ||
| forori,dstinzip(directives_id,directives_str): | ||
| ifori==dst: | ||
| continue | ||
| ifori!=dst: | ||
| occs= [f"{ind(2)}{t[0]}:{t[1]}"fortinentry.occurrences] | ||
| print(f"\n{ind(1)}{pofilename}:{entry.linenum}") | ||
| print(f"\n".join(occs)) | ||
| print(f"{ind(3)}{ori}") | ||
| print(f"{ind(3)}{dst}") | ||