11import contextlib
22import logging
33import os
4- import pathlib
54import sys
65import typing
76from tempfile import gettempdir
1211
1312from common .core .cli import healthcheck
1413from common .core .constants import DEFAULT_PROMETHEUS_MULTIPROC_DIR_NAME
15- from common .core .utils import clear_directory
14+ from common .core .utils import clear_directory , make_writable_directory
1615
1716logger = logging .getLogger (__name__ )
1817
@@ -38,25 +37,13 @@ def ensure_cli_env() -> typing.Generator[None, None, None]:
3837 # TODO @khvn26 Move logging setup to here
3938
4039 # Prometheus multiproc support
41- prom_dir = pathlib .Path (
42- os .environ .setdefault (
43- "PROMETHEUS_MULTIPROC_DIR" ,
44- os .path .join (gettempdir (), DEFAULT_PROMETHEUS_MULTIPROC_DIR_NAME ),
45- )
40+ prom_dir = os .environ .setdefault (
41+ "PROMETHEUS_MULTIPROC_DIR" ,
42+ os .path .join (gettempdir (), DEFAULT_PROMETHEUS_MULTIPROC_DIR_NAME ),
4643 )
47-
48- if prom_dir .exists ():
44+ if os .path .exists (prom_dir ):
4945 clear_directory (prom_dir )
50-
51- prom_dir .mkdir (parents = True , exist_ok = True )
52-
53- # While `mkdir` sets mode=0o777 by default, this can be affected by umask resulting in
54- # lesser permissions for other users. This step ensures the directory is writable for
55- # all users.
56- try :
57- prom_dir .chmod (0o777 )
58- except Exception :
59- pass
46+ make_writable_directory (prom_dir )
6047
6148 # Currently we don't install Flagsmith modules as a package, so we need to add
6249 # $CWD to the Python path to be able to import them
0 commit comments