Skip to content

Commit 3c802d2

Browse files
committed
feat(cli): make file paths multiplatform in various scripts
1 parent 440a436 commit 3c802d2

File tree

7 files changed

+73
-38
lines changed

7 files changed

+73
-38
lines changed

resumecraftr/cli/agent.py

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ def delete_all_resumecraftr_agents():
3838
console.print(f"[bold red]Error deleting agents: {e}[/bold red]")
3939

4040
def get_vector_store_id_by_name(agent_name: str) -> str:
41-
"""Retrieve the vector store ID by the agent's name."""
41+
"""
42+
Retrieve the vector store ID by the agent's name.
43+
44+
Args:
45+
agent_name (str): The name of the agent.
46+
47+
Returns:
48+
str: The ID of the vector store.
49+
"""
4250
vector_stores = client.beta.vector_stores.list()
4351
expected_name = f"{agent_name} Docs"
4452

@@ -51,20 +59,36 @@ def get_vector_store_id_by_name(agent_name: str) -> str:
5159
)
5260
return None
5361

54-
5562
def load_supported_files(directory: str) -> list:
56-
"""Load all supported document files from the given directory and subdirectories."""
63+
"""
64+
Load all supported document files from the given directory and subdirectories.
65+
66+
Args:
67+
directory (str): The directory to search for files.
68+
69+
Returns:
70+
list: A list of file paths.
71+
"""
5772
console.print(f"[bold blue]Loading documents from '{directory}'...[/bold blue]")
5873
files = []
5974
for ext in SUPPORTED_EXTENSIONS:
6075
files.extend(glob.glob(f"{directory}/**/*{ext}", recursive=True))
6176
return files
6277

63-
6478
def upload_files_to_vector_store(
6579
vector_store_id: str, progress: Progress = None, task=None
6680
):
67-
"""Upload all supported files to the specified vector store."""
81+
"""
82+
Upload all supported files to the specified vector store.
83+
84+
Args:
85+
vector_store_id (str): The ID of the vector store.
86+
progress (Progress, optional): The progress object for displaying progress.
87+
task (optional): The task object for updating progress.
88+
89+
Returns:
90+
None
91+
"""
6892
files = load_supported_files(CV_WORKSPACE)
6993

7094
if not files:
@@ -88,9 +112,16 @@ def upload_files_to_vector_store(
88112
f"[bold green]Files uploaded successfully to vector store '{vector_store_id}'.[/bold green]"
89113
)
90114

91-
92115
def create_or_get_agent(name=None):
93-
"""Create or retrieve an assistant for document processing."""
116+
"""
117+
Create or retrieve an assistant for document processing.
118+
119+
Args:
120+
name (str, optional): The name of the agent. Defaults to None.
121+
122+
Returns:
123+
assistant: The created or retrieved assistant.
124+
"""
94125
if not os.path.exists(CONFIG_FILE):
95126
console.print(
96127
"[bold red]Configuration file not found. Run 'resumecraftr init' first.[/bold red]"
@@ -135,11 +166,17 @@ def create_or_get_agent(name=None):
135166
)
136167
return assistant
137168

138-
139169
def execute_prompt(prompt: str, name=None) -> str:
140170
"""
141171
Execute a given prompt using the AI agent, ensuring the vector database is refreshed.
142172
Provides real-time feedback to the user using Rich.
173+
174+
Args:
175+
prompt (str): The prompt to send to the AI agent.
176+
name (str, optional): The name of the agent. Defaults to None.
177+
178+
Returns:
179+
str: The response from the AI agent.
143180
"""
144181
assistant = create_or_get_agent(name)
145182
thread = client.beta.threads.create()

resumecraftr/cli/cmd/jobs_desc.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from rich.prompt import Prompt
66

77
console = Console()
8-
CONFIG_FILE = "cv-workspace/resumecraftr.json"
9-
JOBS_DIR = "cv-workspace/job_descriptions"
10-
8+
CONFIG_FILE = os.path.join("cv-workspace", "resumecraftr.json")
9+
JOBS_DIR = os.path.join("cv-workspace", "job_descriptions")
1110

1211
@click.command()
1312
@click.argument("job_name")
@@ -54,6 +53,5 @@ def add_job_description(job_name, content, file):
5453
f"[bold green]Updated {CONFIG_FILE} with job description reference.[/bold green]"
5554
)
5655

57-
5856
if __name__ == "__main__":
5957
add_job_description()

resumecraftr/cli/cmd/latex.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
LATEX_TEMPLATE = "cv-workspace/resume_template.tex"
1414
CUSTOM_PROMPT = "cv-workspace/custom.md"
1515

16-
17-
1816
def check_xelatex():
1917
"""Check if xelatex is installed and provide installation instructions if not."""
2018
try:
@@ -28,7 +26,6 @@ def check_xelatex():
2826
except (FileNotFoundError, subprocess.CalledProcessError):
2927
return False
3028

31-
3229
def print_xelatex_installation_guide():
3330
"""Prints installation instructions for XeLaTeX in Markdown format using rich."""
3431
instructions = """
@@ -77,7 +74,6 @@ def print_xelatex_installation_guide():
7774
"""
7875
console.print(Markdown(instructions))
7976

80-
8177
@click.command()
8278
def generate_pdf():
8379
"""Generate a PDF resume using the optimized LaTeX template with OpenAI."""
@@ -219,12 +215,12 @@ def generate_pdf():
219215
check=True,
220216
)
221217
console.print(
222-
f"[bold green]PDF successfully generated: {output_pdf_file}[/bold green]"
218+
f"[bold green]PDF successfully generated: {output_pdf_file}[bold green]"
223219
)
224220
except subprocess.CalledProcessError as e:
225221
console.print(f"[bold red]Error during LaTeX compilation: {e}[bold red]")
226222
console.print(
227-
"[bold yellow]Attempting automatic LaTeX correction...[/bold yellow]"
223+
"[bold yellow]Attempting automatic LaTeX correction...[bold yellow]"
228224
)
229225

230226
# Use OpenAI to correct the LaTeX document
@@ -240,7 +236,7 @@ def generate_pdf():
240236
f.write(corrected_latex.replace("```latex", "").replace("```", ""))
241237

242238
console.print(
243-
f"[bold cyan]Re-compiling corrected LaTeX file: {output_tex_file}[/bold cyan]"
239+
f"[bold cyan]Re-compiling corrected LaTeX file: {output_tex_file}[bold cyan]"
244240
)
245241
try:
246242
subprocess.run(
@@ -253,17 +249,16 @@ def generate_pdf():
253249
check=True,
254250
)
255251
console.print(
256-
f"[bold green]PDF successfully generated after correction: {output_pdf_file}[/bold green]"
252+
f"[bold green]PDF successfully generated after correction: {output_pdf_file}[bold green]"
257253
)
258254
except subprocess.CalledProcessError:
259255
console.print(
260-
"[bold red]Final LaTeX compilation failed. Please review the LaTeX file manually.[/bold red]"
256+
"[bold red]Final LaTeX compilation failed. Please review the LaTeX file manually.[bold red]"
261257
)
262258
else:
263259
console.print(
264-
"[bold red]OpenAI could not correct the LaTeX document. Manual intervention required.[/bold red]"
260+
"[bold red]OpenAI could not correct the LaTeX document. Manual intervention required.[bold red]"
265261
)
266262

267-
268263
if __name__ == "__main__":
269264
generate_pdf()

resumecraftr/cli/cmd/pdf.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,18 @@
99
CONFIG_FILE = "cv-workspace/resumecraftr.json"
1010
LATEX_TEMPLATE = "cv-workspace/resume_template.tex"
1111

12-
1312
@click.command()
1413
@click.argument("pdf_path", type=click.Path(exists=True))
1514
def extract_text(pdf_path):
16-
"""Extract text from a PDF and save it in the workspace directory, updating the config file."""
15+
"""
16+
Extract text from a PDF and save it in the workspace directory, updating the config file.
17+
18+
Args:
19+
pdf_path (str): The path to the PDF file.
20+
21+
Returns:
22+
None
23+
"""
1724
workspace_dir = "cv-workspace"
1825
os.makedirs(workspace_dir, exist_ok=True)
1926

resumecraftr/cli/cmd/resume.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from resumecraftr.cli.utils.json import clean_json_response, merge_json_files
1010

1111
console = Console()
12-
CONFIG_FILE = "cv-workspace/resumecraftr.json"
13-
OUTPUT_FILE = "cv-workspace/{0}.optimized_sections.json"
12+
CONFIG_FILE = os.path.join("cv-workspace", "resumecraftr.json")
13+
OUTPUT_FILE = os.path.join("cv-workspace", "{0}.optimized_sections.json")
1414

1515

1616
def optimize_section(config, section_name, content, job_description):

resumecraftr/cli/cmd/sections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
console = Console()
15-
CONFIG_FILE = "cv-workspace/resumecraftr.json"
15+
CONFIG_FILE = os.path.join("cv-workspace", "resumecraftr.json")
1616
try:
1717
with importlib.resources.path(
1818
"resumecraftr.templates", "sections.json"
@@ -22,7 +22,7 @@
2222
console.print(
2323
"[bold red]Error: Could not locate the sections file inside the installed package.[/bold red]"
2424
)
25-
OUTPUT_FILE = "cv-workspace/{0}.extracted_sections.json"
25+
OUTPUT_FILE = os.path.join("cv-workspace", "{0}.extracted_sections.json")
2626

2727

2828
def process_section(config, section_name, text_content, language):
@@ -129,7 +129,7 @@ def extract_sections():
129129
json.dump(extracted_data, f, indent=4, ensure_ascii=False)
130130

131131
console.print(
132-
f"[bold green]Extracted sections saved to: {OUTPUT_FILE}[/bold green]"
132+
f"[bold green]Extracted sections saved to: {output_path}[/bold green]"
133133
)
134134

135135

resumecraftr/cli/main.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
console = Console()
1616

17-
CONFIG_FILE = "cv-workspace/resumecraftr.json"
18-
CUSTOM_FILE = "cv-workspace/custom.md"
17+
CONFIG_FILE = os.path.join("cv-workspace", "resumecraftr.json")
18+
CUSTOM_FILE = os.path.join("cv-workspace", "custom.md")
1919

2020
try:
2121
with importlib.resources.path(
@@ -28,7 +28,7 @@
2828
)
2929
TEMPLATE_SRC = None
3030

31-
TEMPLATE_DEST = "cv-workspace/resume_template.tex"
31+
TEMPLATE_DEST = os.path.join("cv-workspace", "resume_template.tex")
3232

3333
DEFAULT_CONFIG = {
3434
"primary_language": "EN",
@@ -70,9 +70,7 @@ def init(language, gpt_model):
7070
config = DEFAULT_CONFIG.copy()
7171
config["primary_language"] = language
7272
config["chat_gpt"] = {
73-
"model": gpt_model,
74-
"temperature": 0.7,
75-
"top_p": 1.0
73+
"model": gpt_model
7674
}
7775

7876
# Save configuration
@@ -110,7 +108,7 @@ def init(language, gpt_model):
110108
with open(CUSTOM_FILE, "w", encoding="utf-8") as config_file:
111109
config_file.writelines("PUT HERE YOUR COMPLEMENTARY INFO AND INSTRUCTIONS")
112110
console.print(
113-
f"[bold green]CUSTOM initialized with empty:[/bold green] {CONFIG_FILE}"
111+
f"[bold green]CUSTOM initialized with empty:[/bold green] {CUSTOM_FILE}"
114112
)
115113

116114
# Copy LaTeX template if it doesn't exist
@@ -159,4 +157,4 @@ def delete_agents():
159157
cli.add_command(generate_pdf, name="toPdf")
160158

161159
if __name__ == "__main__":
162-
cli()
160+
cli()

0 commit comments

Comments
 (0)