fix: 🐛 automigrate between short/long imports
This commit is contained in:
parent
98f340bd97
commit
eecc2b57c5
2 changed files with 46 additions and 7 deletions
|
|
@ -5,7 +5,11 @@ from typing import Coroutine, List, Optional, Union
|
|||
from ..libs.llm import LLM
|
||||
from ..libs.util.devdata import dev_data_logger
|
||||
from ..libs.util.logging import logger
|
||||
from ..libs.util.paths import getConfigFilePath, getDiffsFolderPath
|
||||
from ..libs.util.paths import (
|
||||
convertConfigImports,
|
||||
getConfigFilePath,
|
||||
getDiffsFolderPath,
|
||||
)
|
||||
from ..libs.util.telemetry import posthog_logger
|
||||
from ..models.filesystem import RangeInFile
|
||||
from ..models.filesystem_edit import (
|
||||
|
|
@ -236,14 +240,27 @@ class ContinueSDK(AbstractContinueSDK):
|
|||
|
||||
_last_valid_config: ContinueConfig = None
|
||||
|
||||
def _load_config_dot_py(self) -> ContinueConfig:
|
||||
path = getConfigFilePath()
|
||||
config = ContinueConfig.from_filepath(path)
|
||||
self._last_valid_config = config
|
||||
def _load_config_dot_py(self, retry: bool = True) -> ContinueConfig:
|
||||
try:
|
||||
path = getConfigFilePath()
|
||||
config = ContinueConfig.from_filepath(path)
|
||||
self._last_valid_config = config
|
||||
|
||||
logger.debug("Loaded Continue config file from %s", path)
|
||||
logger.debug("Loaded Continue config file from %s", path)
|
||||
|
||||
return config
|
||||
return config
|
||||
except ModuleNotFoundError as e:
|
||||
if not retry:
|
||||
raise e
|
||||
# Check if the module was "continuedev.src"
|
||||
if e.name == "continuedev.src":
|
||||
convertConfigImports(shorten=True)
|
||||
return self._load_config_dot_py(retry=False)
|
||||
elif e.name.startswith("continuedev."):
|
||||
convertConfigImports(shorten=False)
|
||||
return self._load_config_dot_py(retry=False)
|
||||
else:
|
||||
raise e
|
||||
|
||||
def get_code_context(
|
||||
self, only_editing: bool = False
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
from ..constants.default_config import default_config
|
||||
|
|
@ -111,6 +112,27 @@ def getConfigFilePath() -> str:
|
|||
return path
|
||||
|
||||
|
||||
def convertConfigImports(shorten: bool) -> str:
|
||||
path = getConfigFilePath()
|
||||
# Make any necessary migrations
|
||||
with open(path, "r") as f:
|
||||
existing_content = f.read()
|
||||
|
||||
if shorten:
|
||||
migrated = existing_content.replace(
|
||||
"from continuedev.src.continuedev.", "from continuedev."
|
||||
)
|
||||
else:
|
||||
migrated = re.sub(
|
||||
r"(?<!src\.)continuedev\.(?!src)",
|
||||
"continuedev.src.continuedev.",
|
||||
existing_content,
|
||||
)
|
||||
|
||||
with open(path, "w") as f:
|
||||
f.write(migrated)
|
||||
|
||||
|
||||
def getLogFilePath():
|
||||
path = os.path.join(getGlobalFolderPath(), "continue.log")
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue