Skip to content

Commit

Permalink
[Chore] sc-32247 Fallback to use temp folder to store profile.yml
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Huang <[email protected]>

[Fix] test failed issue

Signed-off-by: Kent Huang <[email protected]>

[Fix] Code review issue

 - Enhance piperider user home dir logic in piperider_cli/__init__.py

Signed-off-by: Kent Huang <[email protected]>

[Fix] typo

Signed-off-by: Kent Huang <[email protected]>
  • Loading branch information
kentwelcome committed Sep 7, 2023
1 parent 47999a3 commit f8c10bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions piperider_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import sys
import tempfile
import webbrowser
from datetime import datetime

Expand All @@ -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')

Check warning on line 16 in piperider_cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/__init__.py#L16

Added line #L16 was not covered by tests
PIPERIDER_USER_PROFILE = os.path.join(PIPERIDER_USER_HOME, 'profile.yml')


Expand Down
4 changes: 4 additions & 0 deletions piperider_cli/event/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import tempfile
import uuid
from typing import Union

Expand All @@ -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')

Check warning on line 14 in piperider_cli/event/__init__.py

View check run for this annotation

Codecov / codecov/patch

piperider_cli/event/__init__.py#L14

Added line #L14 was not covered by tests
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']
Expand Down

0 comments on commit f8c10bd

Please sign in to comment.