μ½˜ν…μΈ λ‘œ κ±΄λ„ˆλ›°κΈ°

μ°Έμ‘° hub_sdk/modules/teams.py

μ°Έκ³ 

이 νŒŒμΌμ€ https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/modules/teams .pyμ—μ„œ 확인할 수 μžˆμŠ΅λ‹ˆλ‹€. 문제λ₯Ό λ°œκ²¬ν•˜λ©΄ ν’€ λ¦¬ν€˜μŠ€νŠΈ (πŸ› οΈ)λ₯Ό μ œκ³΅ν•˜μ—¬ 문제λ₯Ό ν•΄κ²°ν•˜λŠ” 데 도움을 μ£Όμ„Έμš”. κ°μ‚¬ν•©λ‹ˆλ‹€ πŸ™!



hub_sdk.modules.teams.Teams

베이슀: CRUDClient

CRUD μž‘μ—…μ„ 톡해 νŒ€κ³Ό μƒν˜Έ μž‘μš©ν•˜κΈ° μœ„ν•œ ν΄λΌμ΄μ–ΈνŠΈλ₯Ό λ‚˜νƒ€λ‚΄λŠ” ν΄λž˜μŠ€μž…λ‹ˆλ‹€. 이 ν΄λž˜μŠ€λŠ” CRUDClient 클래슀λ₯Ό ν™•μž₯ν•˜κ³  Teams와 μž‘μ—…ν•˜κΈ° μœ„ν•œ νŠΉμ • λ©”μ„œλ“œλ₯Ό μ œκ³΅ν•©λ‹ˆλ‹€.

속성:

이름 μœ ν˜• μ„€λͺ…
id (str, None)

νŒ€μ˜ 고유 μ‹λ³„μž(μ‚¬μš© κ°€λŠ₯ν•œ 경우)μž…λ‹ˆλ‹€.

data dict

νŒ€ 데이터λ₯Ό μ €μž₯ν•˜λŠ” μ‚¬μ „μž…λ‹ˆλ‹€.

μ°Έκ³ 

'id' 속성은 μ΄ˆκΈ°ν™” 쀑에 μ„€μ •λ˜λ©° νŒ€μ„ κ³ μœ ν•˜κ²Œ μ‹λ³„ν•˜λŠ” 데 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. '데이터' 속성은 APIμ—μ„œ κ°€μ Έμ˜¨ νŒ€ 데이터λ₯Ό μ €μž₯ν•˜λŠ” 데 μ‚¬μš©λ©λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
class Teams(CRUDClient):
    """
    A class representing a client for interacting with Teams through CRUD operations. This class extends the CRUDClient
    class and provides specific methods for working with Teams.

    Attributes:
        id (str, None): The unique identifier of the team, if available.
        data (dict): A dictionary to store team data.

    Note:
        The 'id' attribute is set during initialization and can be used to uniquely identify a team.
        The 'data' attribute is used to store team data fetched from the API.
    """

    def __init__(self, team_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None):
        """
        Initialize a Teams instance.

        Args:
            team_id (str, optional): The unique identifier of the team.
            headers (dict, optional): A dictionary of HTTP headers to be included in API requests.
        """
        super().__init__("teams", "team", headers)
        self.id = team_id
        self.data = {}
        if team_id:
            self.get_data()

    def get_data(self) -> None:
        """
        Retrieves data for the current team instance.

        If a valid team ID has been set, it sends a request to fetch the team data and stores it in the instance.
        If no team ID has been set, it logs an error message.

        Returns:
            (None): The method does not return a value.
        """
        if not self.id:
            self.logger.error("No team id has been set. Update the team id or create a team.")
            return

        try:
            response = super().read(self.id)

            if response is None:
                self.logger.error(f"Received no response from the server for team ID: {self.id}")
                return

            # Check if the response has a .json() method (it should if it's a response object)
            if not hasattr(response, "json"):
                self.logger.error(f"Invalid response object received for team ID: {self.id}")
                return

            resp_data = response.json()
            if resp_data is None:
                self.logger.error(f"No data received in the response for team ID: {self.id}")
                return

            data = resp_data.get("data", {})
            self.data = self._reconstruct_data(data)
            self.logger.debug(f"Team data retrieved for ID: {self.id}")

        except Exception as e:
            self.logger.error(f"An error occurred while retrieving data for team ID: {self.id}, {str(e)}")

    def create_team(self, team_data) -> None:
        """
        Creates a new team with the provided data and sets the team ID for the current instance.

        Args:
            team_data (dict): A dictionary containing the data for creating the team.

        Returns:
            (None): The method does not return a value.
        """
        resp = super().create(team_data).json()
        self.id = resp.get("data", {}).get("id")
        self.get_data()

    def delete(self, hard=False) -> Optional[Response]:
        """
        Delete the team resource represented by this instance.

        Args:
            hard (bool, optional): If True, perform a hard (permanent) delete.

        Note:
            The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
            In a soft delete, the team might be marked as deleted but retained in the system.
            In a hard delete, the team is permanently removed from the system.

        Returns:
            (Optional[Response]): The response from the delete request, or None if it fails.
        """
        return super().delete(self.id, hard)

    def update(self, data) -> Optional[Response]:
        """
        Update the team resource represented by this instance.

        Args:
            data (dict): The updated data for the team resource.

        Returns:
            (Optional[Response]): The response from the update request, or None if it fails.
        """
        return super().update(self.id, data)

__init__(team_id=None, headers=None)

Teams μΈμŠ€ν„΄μŠ€λ₯Ό μ΄ˆκΈ°ν™”ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
team_id str

νŒ€μ˜ 고유 μ‹λ³„μžμž…λ‹ˆλ‹€.

None
headers dict

API μš”μ²­μ— 포함될 HTTP ν—€λ”μ˜ μ‚¬μ „μž…λ‹ˆλ‹€.

None
의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
def __init__(self, team_id: Optional[str] = None, headers: Optional[Dict[str, Any]] = None):
    """
    Initialize a Teams instance.

    Args:
        team_id (str, optional): The unique identifier of the team.
        headers (dict, optional): A dictionary of HTTP headers to be included in API requests.
    """
    super().__init__("teams", "team", headers)
    self.id = team_id
    self.data = {}
    if team_id:
        self.get_data()

create_team(team_data)

제곡된 λ°μ΄ν„°λ‘œ μƒˆ νŒ€μ„ λ§Œλ“€κ³  ν˜„μž¬ μΈμŠ€ν„΄μŠ€μ— λŒ€ν•œ νŒ€ IDλ₯Ό μ„€μ •ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
team_data dict

νŒ€ 생성을 μœ„ν•œ 데이터가 ν¬ν•¨λœ μ‚¬μ „μž…λ‹ˆλ‹€.

ν•„μˆ˜

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
None

이 λ©”μ„œλ“œλŠ” 값을 λ°˜ν™˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
def create_team(self, team_data) -> None:
    """
    Creates a new team with the provided data and sets the team ID for the current instance.

    Args:
        team_data (dict): A dictionary containing the data for creating the team.

    Returns:
        (None): The method does not return a value.
    """
    resp = super().create(team_data).json()
    self.id = resp.get("data", {}).get("id")
    self.get_data()

delete(hard=False)

이 μΈμŠ€ν„΄μŠ€λ‘œ ν‘œμ‹œλ˜λŠ” νŒ€ λ¦¬μ†ŒμŠ€λ₯Ό μ‚­μ œν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
hard bool

True이면 ν•˜λ“œ(영ꡬ) μ‚­μ œλ₯Ό μˆ˜ν–‰ν•©λ‹ˆλ‹€.

False
μ°Έκ³ 

'ν•˜λ“œ' λ§€κ°œλ³€μˆ˜λŠ” μ†Œν”„νŠΈ μ‚­μ œ(κΈ°λ³Έκ°’)λ₯Ό μˆ˜ν–‰ν• μ§€, μ•„λ‹ˆλ©΄ ν•˜λ“œ μ‚­μ œλ₯Ό μˆ˜ν–‰ν• μ§€λ₯Ό κ²°μ •ν•©λ‹ˆλ‹€. μ†Œν”„νŠΈ μ‚­μ œμ˜ 경우 νŒ€μ€ μ‚­μ œλœ κ²ƒμœΌλ‘œ ν‘œμ‹œλ˜μ§€λ§Œ μ‹œμŠ€ν…œμ—λŠ” μœ μ§€λ  수 μžˆμŠ΅λ‹ˆλ‹€. ν•˜λ“œ μ‚­μ œμ—μ„œλŠ” νŒ€μ΄ μ‹œμŠ€ν…œμ—μ„œ 영ꡬ적으둜 μ œκ±°λ©λ‹ˆλ‹€.

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
Optional[Response]

μ‚­μ œ μš”μ²­μ˜ 응닡 λ˜λŠ” μ‹€νŒ¨ν•œ 경우 μ—†μŒμž…λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
def delete(self, hard=False) -> Optional[Response]:
    """
    Delete the team resource represented by this instance.

    Args:
        hard (bool, optional): If True, perform a hard (permanent) delete.

    Note:
        The 'hard' parameter determines whether to perform a soft delete (default) or a hard delete.
        In a soft delete, the team might be marked as deleted but retained in the system.
        In a hard delete, the team is permanently removed from the system.

    Returns:
        (Optional[Response]): The response from the delete request, or None if it fails.
    """
    return super().delete(self.id, hard)

get_data()

ν˜„μž¬ νŒ€ μΈμŠ€ν„΄μŠ€μ— λŒ€ν•œ 데이터λ₯Ό κ²€μƒ‰ν•©λ‹ˆλ‹€.

μœ νš¨ν•œ νŒ€ IDκ°€ μ„€μ •λ˜μ–΄ 있으면 νŒ€ 데이터 κ°€μ Έμ˜€κΈ° μš”μ²­μ„ μ „μ†‘ν•˜μ—¬ μΈμŠ€ν„΄μŠ€μ— μ €μž₯ν•©λ‹ˆλ‹€. νŒ€ IDκ°€ μ„€μ •λ˜μ§€ μ•Šμ€ 경우 였λ₯˜ λ©”μ‹œμ§€λ₯Ό κΈ°λ‘ν•©λ‹ˆλ‹€.

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
None

이 λ©”μ„œλ“œλŠ” 값을 λ°˜ν™˜ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
def get_data(self) -> None:
    """
    Retrieves data for the current team instance.

    If a valid team ID has been set, it sends a request to fetch the team data and stores it in the instance.
    If no team ID has been set, it logs an error message.

    Returns:
        (None): The method does not return a value.
    """
    if not self.id:
        self.logger.error("No team id has been set. Update the team id or create a team.")
        return

    try:
        response = super().read(self.id)

        if response is None:
            self.logger.error(f"Received no response from the server for team ID: {self.id}")
            return

        # Check if the response has a .json() method (it should if it's a response object)
        if not hasattr(response, "json"):
            self.logger.error(f"Invalid response object received for team ID: {self.id}")
            return

        resp_data = response.json()
        if resp_data is None:
            self.logger.error(f"No data received in the response for team ID: {self.id}")
            return

        data = resp_data.get("data", {})
        self.data = self._reconstruct_data(data)
        self.logger.debug(f"Team data retrieved for ID: {self.id}")

    except Exception as e:
        self.logger.error(f"An error occurred while retrieving data for team ID: {self.id}, {str(e)}")

update(data)

이 μΈμŠ€ν„΄μŠ€λ‘œ λŒ€ν‘œλ˜λŠ” νŒ€ λ¦¬μ†ŒμŠ€λ₯Ό μ—…λ°μ΄νŠΈν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
data dict

νŒ€ λ¦¬μ†ŒμŠ€μ— λŒ€ν•œ μ—…λ°μ΄νŠΈλœ λ°μ΄ν„°μž…λ‹ˆλ‹€.

ν•„μˆ˜

λ°˜ν™˜ν•©λ‹ˆλ‹€:

μœ ν˜• μ„€λͺ…
Optional[Response]

The response from the update request, or None if it fails.

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
def update(self, data) -> Optional[Response]:
    """
    Update the team resource represented by this instance.

    Args:
        data (dict): The updated data for the team resource.

    Returns:
        (Optional[Response]): The response from the update request, or None if it fails.
    """
    return super().update(self.id, data)



hub_sdk.modules.teams.TeamList

베이슀: PaginatedList

의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
class TeamList(PaginatedList):
    def __init__(self, page_size=None, public=None, headers=None):
        """
        Initialize a TeamList instance.

        Args:
            page_size (int, optional): The number of items to request per page.
            public (bool, optional): Whether the items should be publicly accessible.
            headers (dict, optional): Headers to be included in API requests.
        """
        base_endpoint = "datasets"
        if public:
            base_endpoint = f"public/{base_endpoint}"
        super().__init__(base_endpoint, "team", page_size, headers)

__init__(page_size=None, public=None, headers=None)

TeamList μΈμŠ€ν„΄μŠ€λ₯Ό μ΄ˆκΈ°ν™”ν•©λ‹ˆλ‹€.

λ§€κ°œλ³€μˆ˜:

이름 μœ ν˜• μ„€λͺ… κΈ°λ³Έκ°’
page_size int

νŽ˜μ΄μ§€λ‹Ή μš”μ²­ν•  ν•­λͺ© μˆ˜μž…λ‹ˆλ‹€.

None
public bool

ν•­λͺ©μ΄ 곡개적으둜 μ•‘μ„ΈμŠ€ν•  수 μžˆλŠ”μ§€ μ—¬λΆ€μž…λ‹ˆλ‹€.

None
headers dict

API μš”μ²­μ— 포함할 ν—€λ”μž…λ‹ˆλ‹€.

None
의 μ†ŒμŠ€ μ½”λ“œ hub_sdk/modules/teams.py
def __init__(self, page_size=None, public=None, headers=None):
    """
    Initialize a TeamList instance.

    Args:
        page_size (int, optional): The number of items to request per page.
        public (bool, optional): Whether the items should be publicly accessible.
        headers (dict, optional): Headers to be included in API requests.
    """
    base_endpoint = "datasets"
    if public:
        base_endpoint = f"public/{base_endpoint}"
    super().__init__(base_endpoint, "team", page_size, headers)