Ahmedik95316 commited on
Commit
5a5ce97
·
1 Parent(s): fcd0e82

Update path_config.py

Browse files
Files changed (1) hide show
  1. path_config.py +22 -9
path_config.py CHANGED
@@ -4,7 +4,18 @@ from pathlib import Path
4
  from typing import Dict, Optional
5
  import logging
6
 
7
- logger = logging.getLogger(__name__)
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  class EnvironmentPathManager:
10
  """Dynamic path management for different deployment environments"""
@@ -89,32 +100,34 @@ class EnvironmentPathManager:
89
  try:
90
  test_file.touch()
91
  test_file.unlink()
92
- logger.debug(f"Ensured directory exists with write access: {path}")
 
 
93
  except (PermissionError, OSError):
94
- logger.warning(f"Directory exists but no write access: {path}")
95
 
96
  except PermissionError:
97
- logger.warning(f"Cannot create directory {path}, using fallback")
98
  if path_name in ['cache', 'temp']:
99
  # Fallback to user's home directory for cache/temp
100
  fallback_path = Path.home() / f'.fake_news_detector/{path_name}'
101
  try:
102
  fallback_path.mkdir(parents=True, exist_ok=True)
103
  self.base_paths[path_name] = fallback_path
104
- logger.info(f"Using fallback directory: {fallback_path}")
105
  except Exception as e:
106
- logger.error(f"Fallback directory creation failed: {e}")
107
  elif path_name == 'logs':
108
  # For logs, try using a temporary directory
109
  try:
110
  import tempfile
111
  temp_logs = Path(tempfile.mkdtemp(prefix='logs_'))
112
  self.base_paths[path_name] = temp_logs
113
- logger.info(f"Using temporary logs directory: {temp_logs}")
114
  except Exception as e:
115
- logger.error(f"Cannot create temporary logs directory: {e}")
116
  except Exception as e:
117
- logger.error(f"Failed to create directory {path}: {e}")
118
 
119
  def get_data_path(self, filename: str = '') -> Path:
120
  """Get data directory path"""
 
4
  from typing import Dict, Optional
5
  import logging
6
 
7
+ # Get logger, but handle case where it might not be configured yet
8
+ try:
9
+ logger = logging.getLogger(__name__)
10
+ if not logger.handlers:
11
+ # If no handlers, add a basic one
12
+ logger.addHandler(logging.StreamHandler())
13
+ logger.setLevel(logging.INFO)
14
+ except:
15
+ # Fallback - create a simple logger
16
+ logger = logging.getLogger(__name__)
17
+ logger.addHandler(logging.StreamHandler())
18
+ logger.setLevel(logging.INFO)
19
 
20
  class EnvironmentPathManager:
21
  """Dynamic path management for different deployment environments"""
 
100
  try:
101
  test_file.touch()
102
  test_file.unlink()
103
+ # Use print for critical startup messages to avoid logging dependency issues
104
+ if self.environment == 'huggingface_spaces':
105
+ print(f"Directory {path} created with write access")
106
  except (PermissionError, OSError):
107
+ print(f"Directory exists but no write access: {path}")
108
 
109
  except PermissionError:
110
+ print(f"Cannot create directory {path}, using fallback")
111
  if path_name in ['cache', 'temp']:
112
  # Fallback to user's home directory for cache/temp
113
  fallback_path = Path.home() / f'.fake_news_detector/{path_name}'
114
  try:
115
  fallback_path.mkdir(parents=True, exist_ok=True)
116
  self.base_paths[path_name] = fallback_path
117
+ print(f"Using fallback directory: {fallback_path}")
118
  except Exception as e:
119
+ print(f"Fallback directory creation failed: {e}")
120
  elif path_name == 'logs':
121
  # For logs, try using a temporary directory
122
  try:
123
  import tempfile
124
  temp_logs = Path(tempfile.mkdtemp(prefix='logs_'))
125
  self.base_paths[path_name] = temp_logs
126
+ print(f"Using temporary logs directory: {temp_logs}")
127
  except Exception as e:
128
+ print(f"Cannot create temporary logs directory: {e}")
129
  except Exception as e:
130
+ print(f"Failed to create directory {path}: {e}")
131
 
132
  def get_data_path(self, filename: str = '') -> Path:
133
  """Get data directory path"""