Skip to content

Commit

Permalink
Utility for random string.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohinb2 committed Jan 28, 2025
1 parent 493c19a commit d81d3fa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 8 additions & 0 deletions runhouse/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import sys
import tempfile
import threading
import uuid
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime
from enum import Enum
Expand All @@ -34,6 +35,13 @@
logger = get_logger(__name__)


def get_random_str(length: int = 8):
if length > 32:
raise ValueError("Max length of random string is 32")

return str(uuid.uuid4())[:length]


####################################################################################################
# Simple env setup utilities
####################################################################################################
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/resource_fixtures.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import uuid
from datetime import datetime

import pytest

from runhouse.globals import rns_client
from runhouse.resources.resource import Resource
from runhouse.utils import get_random_str
from tests.conftest import init_args

from tests.constants import TEST_ORG
Expand Down Expand Up @@ -38,7 +38,7 @@ def saved_resource_pool():


def create_folder_path():
hash = uuid.uuid4().hex[:8]
hash = get_random_str(length=8)
return f"test-{hash}-{datetime.now().strftime('%Y%m%d-%H%M%S')}"


Expand Down
8 changes: 0 additions & 8 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import importlib
import json
import os
import uuid
from datetime import datetime
from pathlib import Path
from typing import Dict, Optional
Expand Down Expand Up @@ -52,13 +51,6 @@ def get_pid_and_ray_node(a=0):
return pid, node_id


def get_random_str(length: int = 8):
if length > 32:
raise ValueError("Max length of random string is 32")

return str(uuid.uuid4())[:length]


@contextlib.contextmanager
def friend_account():
"""Used for the purposes of testing resource sharing among different accounts.
Expand Down

0 comments on commit d81d3fa

Please sign in to comment.