Skip to content

Commit

Permalink
fix: resolve tilde in paths in wizard (#554)
Browse files Browse the repository at this point in the history
Fixes #539
  • Loading branch information
joanise authored Sep 23, 2024
1 parent 7f418d4 commit bbc883d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
9 changes: 9 additions & 0 deletions everyvoice/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sys
from enum import Enum
from typing import Optional, Sequence
Expand Down Expand Up @@ -42,6 +43,14 @@ def sanitize_input(self, response):
"""
return response

def sanitize_paths(self, response):
"""For steps that return path, have sanitize_input call sanitize_paths"""
# Remove surrounding whitespace
response = response.strip()
# Support ~ and ~username path expansions
response = os.path.expanduser(response)
return response

def validate(self, response) -> bool:
"""Validate the response.
Expand Down
3 changes: 1 addition & 2 deletions everyvoice/wizard/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ def prompt(self):
).unsafe_ask()

def sanitize_input(self, response):
response = super().sanitize_input(response)
return response.strip()
return self.sanitize_paths(response)

def validate(self, response) -> bool:
path = Path(response)
Expand Down
6 changes: 2 additions & 4 deletions everyvoice/wizard/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ def prompt(self):
).unsafe_ask()

def sanitize_input(self, response):
response = super().sanitize_input(response)
return response.strip()
return self.sanitize_paths(response)

def validate(self, response) -> bool:
valid_path = validate_path(response, is_dir=True, exists=True)
Expand Down Expand Up @@ -142,8 +141,7 @@ def prompt(self):
).unsafe_ask()

def sanitize_input(self, response):
response = super().sanitize_input(response)
return response.strip()
return self.sanitize_paths(response)

def validate(self, response) -> bool:
return validate_path(response, is_file=True, exists=True)
Expand Down

0 comments on commit bbc883d

Please sign in to comment.