|
97 | 97 | ApiListCompetitionTopicsResponse, |
98 | 98 | ApiListTopicMessagesRequest, |
99 | 99 | ApiListTopicMessagesResponse, |
| 100 | + ApiGetHackathonOverviewRequest, |
| 101 | + ApiListHackathonWriteUpsRequest, |
100 | 102 | ) |
101 | 103 | from kagglesdk.discussions.types.discussions_api_service import ( |
102 | 104 | ApiDiscussionComment, |
@@ -2652,81 +2654,17 @@ def entity_topic_show_cli( |
2652 | 2654 | hackathon_overview_page_fields = ["name"] |
2653 | 2655 | hackathon_writeup_link_fields = ["url", "type", "title"] |
2654 | 2656 |
|
2655 | | - def _require_sdk_method(self, client, method_name: str, hint: str): |
2656 | | - """Return ``client.method_name`` or raise a clear error. |
2657 | | -
|
2658 | | - The hackathon endpoints landed in kagglesdk after this CLI release |
2659 | | - was cut, so older SDK installs may not have them yet. |
2660 | | - """ |
2661 | | - method = getattr(client, method_name, None) |
2662 | | - if method is None: |
2663 | | - raise ValueError( |
2664 | | - f"This command requires a newer kagglesdk that exposes " f"`{hint}`. Please upgrade kagglesdk." |
2665 | | - ) |
2666 | | - return method |
2667 | | - |
2668 | | - def _build_hackathon_overview_request(self, competition: str): |
2669 | | - try: |
2670 | | - from kagglesdk.competitions.types.competition_api_service import ( # type: ignore |
2671 | | - ApiGetHackathonOverviewRequest, |
2672 | | - ) |
2673 | | - except ImportError as exc: |
2674 | | - raise ValueError("kagglesdk is missing ApiGetHackathonOverviewRequest; please upgrade kagglesdk.") from exc |
2675 | | - request = ApiGetHackathonOverviewRequest() |
2676 | | - request.competition_name = competition |
2677 | | - return request |
2678 | | - |
2679 | | - def _build_list_hackathon_writeups_request(self, competition: str): |
2680 | | - try: |
2681 | | - from kagglesdk.competitions.types.competition_api_service import ( # type: ignore |
2682 | | - ApiListHackathonWriteUpsRequest, |
2683 | | - ) |
2684 | | - except ImportError as exc: |
2685 | | - raise ValueError("kagglesdk is missing ApiListHackathonWriteUpsRequest; please upgrade kagglesdk.") from exc |
2686 | | - request = ApiListHackathonWriteUpsRequest() |
2687 | | - request.competition_name = competition |
2688 | | - return request |
2689 | | - |
2690 | | - def _build_export_hackathon_writeups_csv_request(self, competition: str): |
2691 | | - try: |
2692 | | - from kagglesdk.competitions.types.hackathon_service import ( # type: ignore |
2693 | | - ExportHackathonWriteUpsCsvRequest, |
2694 | | - ) |
2695 | | - except ImportError as exc: |
2696 | | - raise ValueError( |
2697 | | - "kagglesdk is missing ExportHackathonWriteUpsCsvRequest; please upgrade kagglesdk." |
2698 | | - ) from exc |
2699 | | - request = ExportHackathonWriteUpsCsvRequest() |
2700 | | - request.competition_name = competition |
2701 | | - return request |
2702 | | - |
2703 | | - def _build_get_resolved_writeup_links_request(self, write_up_id: int): |
2704 | | - try: |
2705 | | - from kagglesdk.discussions.types.writeups_service import ( # type: ignore |
2706 | | - GetResolvedWriteUpLinksRequest, |
2707 | | - ) |
2708 | | - except ImportError as exc: |
2709 | | - raise ValueError("kagglesdk is missing GetResolvedWriteUpLinksRequest; please upgrade kagglesdk.") from exc |
2710 | | - request = GetResolvedWriteUpLinksRequest() |
2711 | | - request.write_up_id = write_up_id |
2712 | | - return request |
2713 | | - |
2714 | 2657 | def hackathon_get_overview(self, competition: str): |
2715 | 2658 | """Get the overview page content for a hackathon competition. |
2716 | 2659 |
|
2717 | 2660 | Mirrors the ``get_hackathon_overview`` MCP tool. |
2718 | 2661 | """ |
2719 | 2662 | if not competition: |
2720 | 2663 | raise ValueError("No competition specified") |
| 2664 | + request = ApiGetHackathonOverviewRequest() |
| 2665 | + request.competition_name = competition |
2721 | 2666 | with self.build_kaggle_client() as kaggle: |
2722 | | - request = self._build_hackathon_overview_request(competition) |
2723 | | - client = kaggle.competitions.competition_api_client |
2724 | | - method = self._require_sdk_method( |
2725 | | - client, |
2726 | | - "get_hackathon_overview", |
2727 | | - "CompetitionApiClient.get_hackathon_overview", |
2728 | | - ) |
2729 | | - return method(request) |
| 2667 | + return kaggle.competitions.competition_api_client.get_hackathon_overview(request) |
2730 | 2668 |
|
2731 | 2669 | def hackathon_get_overview_cli(self, competition=None, csv_display=False, quiet=False): |
2732 | 2670 | """CLI wrapper for ``kaggle hackathons get <competition>``.""" |
@@ -2757,15 +2695,10 @@ def hackathon_list_writeups(self, competition: str): |
2757 | 2695 | """ |
2758 | 2696 | if not competition: |
2759 | 2697 | raise ValueError("No competition specified") |
| 2698 | + request = ApiListHackathonWriteUpsRequest() |
| 2699 | + request.competition_name = competition |
2760 | 2700 | with self.build_kaggle_client() as kaggle: |
2761 | | - request = self._build_list_hackathon_writeups_request(competition) |
2762 | | - client = kaggle.competitions.competition_api_client |
2763 | | - method = self._require_sdk_method( |
2764 | | - client, |
2765 | | - "list_hackathon_write_ups", |
2766 | | - "CompetitionApiClient.list_hackathon_write_ups", |
2767 | | - ) |
2768 | | - return method(request) |
| 2701 | + return kaggle.competitions.competition_api_client.list_hackathon_write_ups(request) |
2769 | 2702 |
|
2770 | 2703 | def hackathon_list_writeups_cli(self, competition=None, csv_display=False, quiet=False): |
2771 | 2704 | """CLI wrapper for ``kaggle hackathons writeups list <competition>``.""" |
@@ -2815,15 +2748,16 @@ def hackathon_download_writeups(self, competition: str, path: Optional[str] = No |
2815 | 2748 | """ |
2816 | 2749 | if not competition: |
2817 | 2750 | raise ValueError("No competition specified") |
| 2751 | + # Not yet exported by any released kagglesdk; import lazily so the |
| 2752 | + # rest of the module still loads. Drop this once kagglesdk ships it. |
| 2753 | + from kagglesdk.competitions.types.hackathon_service import ( # type: ignore |
| 2754 | + ExportHackathonWriteUpsCsvRequest, |
| 2755 | + ) |
| 2756 | + |
| 2757 | + request = ExportHackathonWriteUpsCsvRequest() |
| 2758 | + request.competition_name = competition |
2818 | 2759 | with self.build_kaggle_client() as kaggle: |
2819 | | - request = self._build_export_hackathon_writeups_csv_request(competition) |
2820 | | - client = kaggle.competitions.hackathon_client |
2821 | | - method = self._require_sdk_method( |
2822 | | - client, |
2823 | | - "export_hackathon_write_ups_csv", |
2824 | | - "HackathonClient.export_hackathon_write_ups_csv", |
2825 | | - ) |
2826 | | - response = method(request) |
| 2760 | + response = kaggle.competitions.hackathon_client.export_hackathon_write_ups_csv(request) |
2827 | 2761 |
|
2828 | 2762 | csv_body = ( |
2829 | 2763 | getattr(response, "csv", None) |
@@ -2869,19 +2803,21 @@ def hackathon_resolve_writeup_links(self, write_up_id: int): |
2869 | 2803 | """ |
2870 | 2804 | if write_up_id is None: |
2871 | 2805 | raise ValueError("No write_up_id specified") |
| 2806 | + # Not yet exported by any released kagglesdk; import lazily so the |
| 2807 | + # rest of the module still loads. Drop this once kagglesdk ships it. |
| 2808 | + from kagglesdk.discussions.types.writeups_service import ( # type: ignore |
| 2809 | + GetResolvedWriteUpLinksRequest, |
| 2810 | + ) |
| 2811 | + |
| 2812 | + request = GetResolvedWriteUpLinksRequest() |
| 2813 | + request.write_up_id = int(write_up_id) |
2872 | 2814 | with self.build_kaggle_client() as kaggle: |
2873 | | - request = self._build_get_resolved_writeup_links_request(int(write_up_id)) |
2874 | 2815 | client = getattr(kaggle.discussions, "writeups_client", None) or getattr( |
2875 | 2816 | kaggle.discussions, "write_ups_client", None |
2876 | 2817 | ) |
2877 | 2818 | if client is None: |
2878 | 2819 | raise ValueError("kagglesdk is missing the WriteUpsClient; please upgrade kagglesdk.") |
2879 | | - method = self._require_sdk_method( |
2880 | | - client, |
2881 | | - "get_resolved_writeup_links", |
2882 | | - "WriteUpsClient.get_resolved_writeup_links", |
2883 | | - ) |
2884 | | - return method(request) |
| 2820 | + return client.get_resolved_writeup_links(request) |
2885 | 2821 |
|
2886 | 2822 | def hackathon_resolve_writeup_links_cli(self, writeup_id=None, csv_display=False, quiet=False): |
2887 | 2823 | """CLI wrapper for ``kaggle hackathons writeups resolve-links <writeup_id>``.""" |
|
0 commit comments