Spaces:
Sleeping
Sleeping
File size: 1,188 Bytes
2f386cc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import logging
import os
EXTENSION_TO_LANGUAGE_MAP = {
".py": "python",
".js": "javascript",
".java": "java",
".cpp": "cpp",
".c": "c",
".rb": "ruby",
".php": "php",
".cs": "csharp",
".go": "go",
".swift": "swift",
".ts": "typescript",
".rs": "rust",
".kt": "kotlin",
".m": "objective-c",
}
def load_environment_variables(file_path: str) -> None:
if os.path.exists(file_path):
with open(file_path) as f:
for line in f:
if line.strip():
key, value = line.strip().split("=")
os.environ[key] = value
def set_environment_variables() -> None:
os.environ["TOKENIZERS_PARALLELISM"] = "false"
def configure_logging(log_file: str, level: int = logging.INFO) -> None:
logging.basicConfig(filename=log_file, level=level)
class TempDirContext:
def __init__(self, temp_dir: str) -> None:
self.cwd = os.getcwd()
self.temp_dir = temp_dir
def __enter__(self):
os.makedirs(self.temp_dir, exist_ok=True)
os.chdir(self.temp_dir)
def __exit__(self, exc_type, exc_value, traceback):
os.chdir(self.cwd)
|