From f8c10bd2f384292fc43e6a9df1407786d3cf8d71 Mon Sep 17 00:00:00 2001 From: Kent Huang Date: Wed, 6 Sep 2023 22:35:22 +0800 Subject: [PATCH 1/3] [Chore] sc-32247 Fallback to use temp folder to store profile.yml Signed-off-by: Kent Huang [Fix] test failed issue Signed-off-by: Kent Huang [Fix] Code review issue - Enhance piperider user home dir logic in piperider_cli/__init__.py Signed-off-by: Kent Huang [Fix] typo Signed-off-by: Kent Huang --- piperider_cli/__init__.py | 3 +++ piperider_cli/event/__init__.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/piperider_cli/__init__.py b/piperider_cli/__init__.py index 55f525f01..52910eda7 100644 --- a/piperider_cli/__init__.py +++ b/piperider_cli/__init__.py @@ -3,6 +3,7 @@ import os import re import sys +import tempfile import webbrowser from datetime import datetime @@ -11,6 +12,8 @@ from ruamel import yaml PIPERIDER_USER_HOME = os.path.expanduser('~/.piperider') +if os.access(os.path.expanduser('~/'), os.W_OK) is False: + PIPERIDER_USER_HOME = os.path.join(tempfile.gettempdir(), '.piperider') PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml') diff --git a/piperider_cli/event/__init__.py b/piperider_cli/event/__init__.py index 46ff75a5d..39a43c959 100644 --- a/piperider_cli/event/__init__.py +++ b/piperider_cli/event/__init__.py @@ -1,4 +1,5 @@ import os +import tempfile import uuid from typing import Union @@ -8,6 +9,9 @@ from piperider_cli.event.collector import Collector PIPERIDER_USER_HOME = os.path.expanduser('~/.piperider') +if os.access(os.path.expanduser('~/'), os.W_OK) is False: + # If we can't create file in user home directory, fallback to use temp folder + PIPERIDER_USER_HOME = os.path.join(tempfile.gettempdir(), '.piperider') PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml') PIPERIDER_USER_EVENT_PATH = os.path.join(PIPERIDER_USER_HOME, '.unsend_events.json') PIPERIDER_FLUSH_EVENTS_WHITELIST = ['init', 'run', 'generate-report', 'compare-reports'] From 828317c2bdd5beb9b852c4e7ddb3b2e547e42dc5 Mon Sep 17 00:00:00 2001 From: Kent Huang Date: Thu, 7 Sep 2023 10:45:04 +0800 Subject: [PATCH 2/3] [Refactor] Define PIPERIDER_USER_HOME in a single place Signed-off-by: Kent Huang --- piperider_cli/__init__.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/piperider_cli/__init__.py b/piperider_cli/__init__.py index 52910eda7..67ed97a12 100644 --- a/piperider_cli/__init__.py +++ b/piperider_cli/__init__.py @@ -3,7 +3,6 @@ import os import re import sys -import tempfile import webbrowser from datetime import datetime @@ -11,10 +10,7 @@ from rich.console import Console from ruamel import yaml -PIPERIDER_USER_HOME = os.path.expanduser('~/.piperider') -if os.access(os.path.expanduser('~/'), os.W_OK) is False: - PIPERIDER_USER_HOME = os.path.join(tempfile.gettempdir(), '.piperider') -PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml') +from piperider_cli.event import PIPERIDER_USER_HOME, PIPERIDER_USER_PROFILE def create_logger(name) -> logging.Logger: From 8fdfef807db549923ed938f573dfa48f675dc452 Mon Sep 17 00:00:00 2001 From: Kent Huang Date: Thu, 7 Sep 2023 10:50:37 +0800 Subject: [PATCH 3/3] [Fix] circular import issue Signed-off-by: Kent Huang --- piperider_cli/__init__.py | 7 ++++++- piperider_cli/event/__init__.py | 7 +------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/piperider_cli/__init__.py b/piperider_cli/__init__.py index 67ed97a12..665c72c8b 100644 --- a/piperider_cli/__init__.py +++ b/piperider_cli/__init__.py @@ -3,6 +3,7 @@ import os import re import sys +import tempfile import webbrowser from datetime import datetime @@ -10,7 +11,11 @@ from rich.console import Console from ruamel import yaml -from piperider_cli.event import PIPERIDER_USER_HOME, PIPERIDER_USER_PROFILE +PIPERIDER_USER_HOME = os.path.expanduser('~/.piperider') +if os.access(os.path.expanduser('~/'), os.W_OK) is False: + # If we can't create file in user home directory, fallback to use temp folder + PIPERIDER_USER_HOME = os.path.join(tempfile.gettempdir(), '.piperider') +PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml') def create_logger(name) -> logging.Logger: diff --git a/piperider_cli/event/__init__.py b/piperider_cli/event/__init__.py index 39a43c959..f76a2ef43 100644 --- a/piperider_cli/event/__init__.py +++ b/piperider_cli/event/__init__.py @@ -1,18 +1,13 @@ import os -import tempfile import uuid from typing import Union from rich.console import Console from ruamel import yaml +from piperider_cli import PIPERIDER_USER_HOME, PIPERIDER_USER_PROFILE from piperider_cli.event.collector import Collector -PIPERIDER_USER_HOME = os.path.expanduser('~/.piperider') -if os.access(os.path.expanduser('~/'), os.W_OK) is False: - # If we can't create file in user home directory, fallback to use temp folder - PIPERIDER_USER_HOME = os.path.join(tempfile.gettempdir(), '.piperider') -PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml') PIPERIDER_USER_EVENT_PATH = os.path.join(PIPERIDER_USER_HOME, '.unsend_events.json') PIPERIDER_FLUSH_EVENTS_WHITELIST = ['init', 'run', 'generate-report', 'compare-reports']