mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Move the Project.save function within the file
This commit is contained in:
@@ -92,6 +92,24 @@ class Project(object):
|
|||||||
"The Jedi version of this project seems newer than what we can handle."
|
"The Jedi version of this project seems newer than what we can handle."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
"""
|
||||||
|
Saves the project configuration in the project in ``.jedi/project.json``.
|
||||||
|
"""
|
||||||
|
data = dict(self.__dict__)
|
||||||
|
data.pop('_environment', None)
|
||||||
|
data.pop('_django', None) # TODO make django setting public?
|
||||||
|
data = {k.lstrip('_'): v for k, v in data.items()}
|
||||||
|
|
||||||
|
# TODO when dropping Python 2 use pathlib.Path.mkdir(parents=True, exist_ok=True)
|
||||||
|
try:
|
||||||
|
os.makedirs(self._get_config_folder_path(self._path))
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno != errno.EEXIST:
|
||||||
|
raise
|
||||||
|
with open(self._get_json_path(self._path), 'w') as f:
|
||||||
|
return json.dump((_SERIALIZER_VERSION, data), f)
|
||||||
|
|
||||||
def __init__(self, path, **kwargs):
|
def __init__(self, path, **kwargs):
|
||||||
"""
|
"""
|
||||||
:param path: The base path for this project.
|
:param path: The base path for this project.
|
||||||
@@ -179,24 +197,6 @@ class Project(object):
|
|||||||
path = prefixed + sys_path + suffixed
|
path = prefixed + sys_path + suffixed
|
||||||
return list(_force_unicode_list(_remove_duplicates_from_path(path)))
|
return list(_force_unicode_list(_remove_duplicates_from_path(path)))
|
||||||
|
|
||||||
def save(self):
|
|
||||||
"""
|
|
||||||
Saves the project configuration in the project in ``.jedi/project.json``.
|
|
||||||
"""
|
|
||||||
data = dict(self.__dict__)
|
|
||||||
data.pop('_environment', None)
|
|
||||||
data.pop('_django', None) # TODO make django setting public?
|
|
||||||
data = {k.lstrip('_'): v for k, v in data.items()}
|
|
||||||
|
|
||||||
# TODO when dropping Python 2 use pathlib.Path.mkdir(parents=True, exist_ok=True)
|
|
||||||
try:
|
|
||||||
os.makedirs(self._get_config_folder_path(self._path))
|
|
||||||
except OSError as e:
|
|
||||||
if e.errno != errno.EEXIST:
|
|
||||||
raise
|
|
||||||
with open(self._get_json_path(self._path), 'w') as f:
|
|
||||||
return json.dump((_SERIALIZER_VERSION, data), f)
|
|
||||||
|
|
||||||
def get_environment(self):
|
def get_environment(self):
|
||||||
if self._environment is None:
|
if self._environment is None:
|
||||||
if self._python_path is not None:
|
if self._python_path is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user