diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-14 16:34:07 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-09-14 16:42:44 +0300 |
commit | 65e983f916c022329f41054c72ca552faf372941 (patch) | |
tree | be2e2380b20ac115946c2e43e10bb900d6ee67a6 /contrib/python/ipython/py3/IPython/core/profiledir.py | |
parent | abdb8cda9345851fdea911b3016fafc5780c12f3 (diff) | |
download | ydb-65e983f916c022329f41054c72ca552faf372941.tar.gz |
Intermediate changes
commit_hash:315a764ebe0b22f720e1d1f1147e3f2ab88f6ea4
Diffstat (limited to 'contrib/python/ipython/py3/IPython/core/profiledir.py')
-rw-r--r-- | contrib/python/ipython/py3/IPython/core/profiledir.py | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/contrib/python/ipython/py3/IPython/core/profiledir.py b/contrib/python/ipython/py3/IPython/core/profiledir.py index cb4d39339a..a38d771ef5 100644 --- a/contrib/python/ipython/py3/IPython/core/profiledir.py +++ b/contrib/python/ipython/py3/IPython/core/profiledir.py @@ -14,6 +14,8 @@ from ..paths import get_ipython_package_dir from ..utils.path import expand_path, ensure_dir_exists from traitlets import Unicode, Bool, observe +from typing import Optional + #----------------------------------------------------------------------------- # Module errors #----------------------------------------------------------------------------- @@ -68,18 +70,31 @@ class ProfileDir(LoggingConfigurable): self.pid_dir = os.path.join(new, self.pid_dir_name) self.static_dir = os.path.join(new, self.static_dir_name) self.check_dirs() - - def _mkdir(self, path, mode=None): + + def _mkdir(self, path: str, mode: Optional[int] = None) -> bool: """ensure a directory exists at a given path This is a version of os.mkdir, with the following differences: - - returns True if it created the directory, False otherwise + - returns whether the directory has been created or not. - ignores EEXIST, protecting against race conditions where the dir may have been created in between the check and the creation - sets permissions if requested and the dir already exists + + Parameters + ---------- + path: str + path of the dir to create + mode: int + see `mode` of `os.mkdir` + + Returns + ------- + bool: + returns True if it created the directory, False otherwise """ + if os.path.exists(path): if mode and os.stat(path).st_mode != mode: try: @@ -109,14 +124,14 @@ class ProfileDir(LoggingConfigurable): @observe('startup_dir') def check_startup_dir(self, change=None): - self._mkdir(self.startup_dir) - - readme = os.path.join(self.startup_dir, 'README') - - if not os.path.exists(readme): - import pkgutil - with open(readme, 'wb') as f: - f.write(pkgutil.get_data(__name__, 'profile/README_STARTUP')) + if self._mkdir(self.startup_dir): + readme = os.path.join(self.startup_dir, "README") + + if not os.path.exists(readme): + import pkgutil + with open(readme, "wb") as f: + f.write(pkgutil.get_data(__name__, "profile/README_STARTUP")) + return @observe('security_dir') def check_security_dir(self, change=None): |