Skip to content

Commit

Permalink
ENH: use tempfile.gettempdir() for temp dir (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
qianduoduo0904 authored Apr 7, 2023
1 parent c90deba commit a66fafd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
7 changes: 4 additions & 3 deletions python/xoscar/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import getpass
import os
import tempfile

from .utils import get_current_user

XOSCAR_TEMP_DIR = f"/tmp/{get_current_user()}/xoscar"
TEMPDIR = tempfile.gettempdir()
XOSCAR_TEMP_DIR = os.path.join(TEMPDIR, getpass.getuser(), "xoscar")

# unix socket.
XOSCAR_UNIX_SOCKET_DIR = os.path.join(XOSCAR_TEMP_DIR, "socket")
8 changes: 0 additions & 8 deletions python/xoscar/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,3 @@ def test_timer():
time.sleep(0.1)

assert timer.duration >= 0.1


def test_get_current_user():
user = utils.get_current_user()
# WINDOWS env USERNAME
# UNIX env USER
actual_user = os.environ.get("USER", os.environ.get("USERNAME"))
assert user == actual_user
9 changes: 0 additions & 9 deletions python/xoscar/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import asyncio
import dataclasses
import functools
import getpass
import importlib
import inspect
import io
Expand Down Expand Up @@ -447,11 +446,3 @@ def retry_call(*args, **kwargs):
raise ex # pylint: disable-msg=E0702

return retry_call


def get_current_user() -> str:
"""
Get current login user.
Compatible for unix and windows.
"""
return getpass.getuser()

0 comments on commit a66fafd

Please sign in to comment.