Skip to content

Commit 6567116

Browse files
committed
fixed control alignment and size, fixed AUTHORS
1 parent 387e4c1 commit 6567116

File tree

5 files changed

+210
-118
lines changed

5 files changed

+210
-118
lines changed

README.md

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,36 @@
1-
# 🐍 edit-python.pe
2-
## *Textual Tool for Creating Member Profiles for python.pe*
3-
1+
# edit-python.pe
42

3+
## *Textual Tool for Creating Member Profiles for python.pe*
54

6-
## **QUICK START**
5+
## **QUICK START**
76

8-
> **🔥 Welcome to the future!** This tutorial will guide you step-by-step to create your profile on python.pe quickly and securely.
7+
> This tutorial will guide you step-by-step to create your profile on python.pe
8+
> quickly and securely.
99
10-
### 🔧 **PREREQUISITES**
10+
### **PREREQUISITES**
1111

1212
```bash
13-
# Check required versions
14-
python --version # >= 3.13
15-
uv --version # >= 0.8.11
13+
# Check required versions
14+
uv --version # >= 0.8.11
1615
```
1716

18-
> ** ⚠️ IMPORTANTE: ** Asegúrese de que todas las dependencias estén actualizadas antes de continuar.
17+
## **INSTALLING edit-python.pe**
1918

19+
### Installing dependencies
2020

21-
## 🎯 **INSTALLING edit-python.pe**
21+
```bash
22+
uv sync
23+
```
2224

2325
### **Creating the access token**
2426

25-
1. Generate a [Personal access token (classic)](https://github.com/settings/tokens).
27+
1. Generate a [Personal access token
28+
(classic)](https://github.com/settings/tokens).
2629
2. Grant the scope: `public_repo`.
2730
3. Copy the token and keep it handy for the command below
2831

32+
### **For users seeking maximum speed**
2933

30-
### 🌟 **For users seeking maximum speed**
31-
32-
```bash
33-
# 🚀 Single command to start the project
34-
uvx edit-python-pe
35-
36-
# 🎊 That's it! You can now enter your data
34+
```bash uvx edit-python-pe
35+
# Next you'll be prompted for your access token
3736
```
38-
39-
40-
41-
42-
43-
<div align="center">
44-
45-
## 🎊 **CONGRATULATIONS!**
46-
47-
### *You've completed the process*
48-
49-
![Success](https://img.shields.io/badge/STATUS-INSTALLATION%20SUCCESS-00ff88?style=for-the-badge&logo=checkmarx&logoColor=white)
50-
51-
**🤝 Contribute to the project****🐛 Report bugs****💡 Suggest improvements****⭐ Give us a star**
52-
53-
#### Built with ❤️ by the python.pe team
54-
55-
</div>
56-
57-
---
58-
59-
<div align="center">
60-
<sub>📋 Tutorial version: v1.0.0</sub>
61-
</div>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "edit-python-pe"
3-
version = "0.1.7"
3+
version = "0.2.0"
44
description = "Allows member and project profile editing onto python.pe git repository"
55
readme = "README.md"
66
license = { file = "LICENSE" }

src/edit_python_pe/main.py

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import os
55
import pathlib
66
import re
7-
from datetime import datetime
7+
from datetime import date, datetime
88
from time import sleep
99

1010
import pygit2
@@ -83,7 +83,7 @@ def on_mount(self) -> None:
8383
self.back_button = Button("Atrás", id="back")
8484
self.quit_button = Button("Salir", id="quit")
8585

86-
# Mount them in the form container
86+
# 3) Mount them in the form container
8787
self.form_container.mount(self.form_header)
8888
self.form_container.mount(self.name_input)
8989
self.form_container.mount(self.email_input)
@@ -186,10 +186,10 @@ def load_file_into_form(self, filename: str) -> None:
186186
if not os.path.exists(path_md):
187187
return
188188
try:
189-
with open(path_md, "r", encoding="utf-8") as fh:
190-
content = fh.read()
189+
with open(path_md, "r", encoding="utf-8") as fd:
190+
content = fd.read()
191191
except Exception as e:
192-
self.exit(f"Error loading file {filename}: {e}")
192+
self.exit(f"Error al leer el archivo {filename}: {e}")
193193
return
194194

195195
self.clear_form()
@@ -308,6 +308,18 @@ def on_button_pressed(self, event: Button.Pressed) -> None:
308308

309309
def add_social_entry(self) -> None:
310310
class SocialEntry(Horizontal):
311+
DEFAULT_CSS = """
312+
SocialEntry Select {
313+
width: 25%;
314+
}
315+
SocialEntry Input {
316+
width: 50%;
317+
}
318+
SocialEntry Button {
319+
width: 25%;
320+
}
321+
"""
322+
311323
def __init__(se, index):
312324
super().__init__()
313325
se.index = index
@@ -348,7 +360,16 @@ def remove_social_entry(self, index: int) -> None:
348360
found.remove()
349361

350362
def add_alias_entry(self) -> None:
351-
class AliasEntryRow(Horizontal):
363+
class AliasEntry(Horizontal):
364+
DEFAULT_CSS = """
365+
AliasEntry Input {
366+
width: 75%;
367+
}
368+
AliasEntry Button {
369+
width: 25%;
370+
}
371+
"""
372+
352373
def __init__(se, index):
353374
super().__init__()
354375
se.index = index
@@ -359,7 +380,7 @@ def compose(se) -> ComposeResult:
359380
yield se.alias_input
360381
yield se.delete_btn
361382

362-
row = AliasEntryRow(self.alias_index)
383+
row = AliasEntry(self.alias_index)
363384
self.alias_index += 1
364385
self.alias_entries.append(row)
365386
self.alias_container.mount(row)
@@ -403,16 +424,15 @@ def save_member(self) -> None:
403424
md_lines = [
404425
"---",
405426
"blogpost: true",
406-
f"author: {name}",
427+
f"date: {date.today().strftime("%d %b, %Y")}",
428+
f"author: {get_alias(aliases, name)}",
407429
f"location: {city}",
408430
"category: members",
409431
"language: Español",
410432
"image: 1",
411433
"excerpt: 1",
412434
"---",
413435
"",
414-
"% NOTA: No olvidar poner la fecha de publicación debajo de `blogpost: true`",
415-
"",
416436
f"# {name}",
417437
"",
418438
f"```{{gravatar}} {email}",
@@ -553,18 +573,28 @@ def compute_file_name(aliases: list[str], name: str, email: str) -> str:
553573
return f"{alias_for_name}-{sha_hash}.md"
554574

555575

576+
def read_file(file_path: str) -> str:
577+
with open(file_path, "r", encoding="utf-8") as fd:
578+
return fd.read()
579+
580+
581+
def append_file(file_content: str, file_path: str) -> None:
582+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
583+
with open(file_path, "a", encoding="utf-8") as fd:
584+
fd.write(file_content)
585+
586+
556587
def write_file(file_content: str, file_path: str) -> None:
557588
os.makedirs(os.path.dirname(file_path), exist_ok=True)
558-
with open(file_path, "w", encoding="utf-8") as f:
559-
f.write(file_content)
589+
with open(file_path, "w", encoding="utf-8") as fd:
590+
fd.write(file_content)
560591

561592

562593
def commit_and_push(
563594
repo_path: str,
564595
token: str,
565596
was_changed: bool,
566597
name_file: str,
567-
file_path: str,
568598
name: str,
569599
email: str,
570600
) -> tuple[
@@ -574,11 +604,7 @@ def commit_and_push(
574604
pygit2.callbacks.RemoteCallbacks,
575605
]:
576606
repo = pygit2.repository.Repository(repo_path)
577-
rel_path = os.path.relpath(file_path, repo_path)
578-
rel_path = pathlib.Path(
579-
rel_path
580-
).as_posix() # Force path to POSIX format so Windows backslashes (\) don't break pygit2
581-
repo.index.add(rel_path)
607+
repo.index.add_all()
582608
repo.index.write()
583609
author_sig = pygit2.Signature(name or "Unknown", email or "unknown@email")
584610
tree_id = repo.index.write_tree()
@@ -598,17 +624,20 @@ def commit_and_push(
598624
return commit_msg, repo, remote, callbacks
599625

600626

601-
def create_pr(
627+
def get_alias(aliases: list[str], name: str) -> str:
628+
if aliases:
629+
return aliases[0]
630+
return name
631+
632+
633+
def create_member_file(
602634
file_content: str,
603635
current_file: str | None,
604636
repo_path: str,
605-
original_repo: Repository,
606-
forked_repo: Repository,
607-
token: str,
608637
aliases: list[str],
609638
name: str,
610639
email: str,
611-
) -> str:
640+
) -> tuple[str, str]:
612641
# Name the file
613642
name_file = (
614643
current_file
@@ -619,14 +648,41 @@ def create_pr(
619648
# Write file
620649
file_path = os.path.join(repo_path, "blog", "members", name_file)
621650
write_file(file_content, file_path)
651+
return name_file, file_path
652+
653+
654+
def write_authors_file(
655+
repo_path: str, aliases: list[str], name: str, email: str
656+
):
657+
file_path = os.path.join(repo_path, "AUTHORS")
658+
contents = read_file(file_path)
659+
file_content = f"\n{name}({get_alias(aliases, name)}) <{email}>"
660+
if file_content.strip() not in contents:
661+
append_file(file_content, file_path)
662+
663+
664+
def create_pr(
665+
file_content: str,
666+
current_file: str | None,
667+
repo_path: str,
668+
original_repo: Repository,
669+
forked_repo: Repository,
670+
token: str,
671+
aliases: list[str],
672+
name: str,
673+
email: str,
674+
) -> str:
675+
name_file, file_path = create_member_file(
676+
file_content, current_file, repo_path, aliases, name, email
677+
)
678+
write_authors_file(repo_path, aliases, name, email)
622679

623680
# commit & push
624681
commit_msg, repo, remote, callbacks = commit_and_push(
625682
repo_path,
626683
token,
627684
current_file is not None,
628685
name_file,
629-
file_path,
630686
name,
631687
email,
632688
)

0 commit comments

Comments
 (0)