From 802ce9ee52b2c7bcb033c13e39eb8350865bdabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herman=20Zvonimir=20Do=C5=A1ilovi=C4=87?= Date: Sat, 26 Jul 2025 17:10:06 +0200 Subject: [PATCH 1/4] Update working version. Update docs for creating a release. --- docs/source/contributors_guide/release_notes.rst | 3 ++- pyproject.toml | 2 +- src/judge0/__init__.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/contributors_guide/release_notes.rst b/docs/source/contributors_guide/release_notes.rst index da50b25..af4e92a 100644 --- a/docs/source/contributors_guide/release_notes.rst +++ b/docs/source/contributors_guide/release_notes.rst @@ -18,6 +18,7 @@ Creating a release is a simple process that involves a few steps: #. Release title should be ``Judge0 Python SDK vX.Y.Z``. #. Release notes should include a changes from the previous release to the newest release. #. Use the `template `_ from the repo to organize the changes. + #. Click the `Generate release notes` button and use only `Full Changelog` section. #. Create the release. ("Set as a pre-release" should NOT be checked.) #. **Release on PyPI**: #. Use the `GitHub Actions workflow `_ to create a release on PyPI. @@ -29,4 +30,4 @@ that updates the working version in ``judge0/__init__.py`` and ``judge0/pyproje to the minor version. Merge the pull request and you're done! For example, if the new release was ``1.2.2``, the working version should be updated to ``1.3.0.dev0``. -You've successfully created a release! Congratulations! 🎉 \ No newline at end of file +You've successfully created a release! Congratulations! 🎉 diff --git a/pyproject.toml b/pyproject.toml index 665f9ac..c869e23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "judge0" -version = "0.0.4" +version = "0.0.5.dev0" description = "The official Python SDK for Judge0." readme = "README.md" requires-python = ">=3.9" diff --git a/src/judge0/__init__.py b/src/judge0/__init__.py index 6e569c4..a468623 100644 --- a/src/judge0/__init__.py +++ b/src/judge0/__init__.py @@ -29,7 +29,7 @@ from .retry import MaxRetries, MaxWaitTime, RegularPeriodRetry from .submission import Submission -__version__ = "0.0.4" +__version__ = "0.0.5.dev0" __all__ = [ "ATD", From de933507326b438dc8f1da63d11572902ae2e47f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herman=20Zvonimir=20Do=C5=A1ilovi=C4=87?= Date: Sat, 26 Jul 2025 18:04:33 +0200 Subject: [PATCH 2/4] Add warning when using preview client --- src/judge0/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/judge0/__init__.py b/src/judge0/__init__.py index a468623..3e487e0 100644 --- a/src/judge0/__init__.py +++ b/src/judge0/__init__.py @@ -1,3 +1,4 @@ +import logging import os from typing import Union @@ -65,6 +66,8 @@ JUDGE0_IMPLICIT_CE_CLIENT = None JUDGE0_IMPLICIT_EXTRA_CE_CLIENT = None +logger = logging.getLogger(__name__) + def _get_implicit_client(flavor: Flavor) -> Client: global JUDGE0_IMPLICIT_CE_CLIENT, JUDGE0_IMPLICIT_EXTRA_CE_CLIENT @@ -104,6 +107,12 @@ def _get_implicit_client(flavor: Flavor) -> Client: def _get_preview_client(flavor: Flavor) -> Union[SuluJudge0CE, SuluJudge0ExtraCE]: + logger.warning( + "You are using a preview version of the client which is not recommended" + " for production.\n" + "For production, please specify your API key in the environment variable." + ) + if flavor == Flavor.CE: return SuluJudge0CE(retry_strategy=RegularPeriodRetry(0.5)) else: From 59175c5d106608c9261cf5d31909e6d58f9b6d08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herman=20Zvonimir=20Do=C5=A1ilovi=C4=87?= Date: Sat, 26 Jul 2025 18:11:24 +0200 Subject: [PATCH 3/4] Use default endpoints for JUDGE0_CE_ENDPOINT and JUDGE0_EXTRA_CE_ENDPOINT --- src/judge0/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/judge0/__init__.py b/src/judge0/__init__.py index 3e487e0..4bb3d6c 100644 --- a/src/judge0/__init__.py +++ b/src/judge0/__init__.py @@ -122,9 +122,11 @@ def _get_preview_client(flavor: Flavor) -> Union[SuluJudge0CE, SuluJudge0ExtraCE def _get_custom_client(flavor: Flavor) -> Union[Client, None]: from json import loads - ce_endpoint = os.getenv("JUDGE0_CE_ENDPOINT") + ce_endpoint = os.getenv("JUDGE0_CE_ENDPOINT", "https://ce.judge0.com") ce_auth_header = os.getenv("JUDGE0_CE_AUTH_HEADERS") - extra_ce_endpoint = os.getenv("JUDGE0_EXTRA_CE_ENDPOINT") + extra_ce_endpoint = os.getenv( + "JUDGE0_EXTRA_CE_ENDPOINT", "https://extra-ce.judge0.com" + ) extra_ce_auth_header = os.getenv("JUDGE0_EXTRA_CE_AUTH_HEADERS") if flavor == Flavor.CE and ce_endpoint is not None and ce_auth_header is not None: From dd3ba0cc1047d8c666e0cdddb0033acb4bbc3cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herman=20Zvonimir=20Do=C5=A1ilovi=C4=87?= Date: Sat, 26 Jul 2025 18:57:47 +0200 Subject: [PATCH 4/4] Add support for Judge0 Cloud client --- src/judge0/__init__.py | 16 +++++---- src/judge0/clients.py | 76 ++++++++++++++++++++++++++++++++++++++++-- tests/conftest.py | 26 +++++++++++++++ tests/test_clients.py | 2 ++ 4 files changed, 112 insertions(+), 8 deletions(-) diff --git a/src/judge0/__init__.py b/src/judge0/__init__.py index 4bb3d6c..65c842d 100644 --- a/src/judge0/__init__.py +++ b/src/judge0/__init__.py @@ -19,6 +19,9 @@ ATDJudge0CE, ATDJudge0ExtraCE, Client, + Judge0Cloud, + Judge0CloudCE, + Judge0CloudExtraCE, Rapid, RapidJudge0CE, RapidJudge0ExtraCE, @@ -39,6 +42,9 @@ "Client", "File", "Filesystem", + "Judge0Cloud", + "Judge0CloudCE", + "Judge0CloudExtraCE", "Language", "LanguageAlias", "MaxRetries", @@ -54,12 +60,12 @@ "SuluJudge0ExtraCE", "TestCase", "async_execute", + "async_run", "execute", "get_client", - "async_run", - "sync_run", "run", "sync_execute", + "sync_run", "wait", ] @@ -122,11 +128,9 @@ def _get_preview_client(flavor: Flavor) -> Union[SuluJudge0CE, SuluJudge0ExtraCE def _get_custom_client(flavor: Flavor) -> Union[Client, None]: from json import loads - ce_endpoint = os.getenv("JUDGE0_CE_ENDPOINT", "https://ce.judge0.com") + ce_endpoint = os.getenv("JUDGE0_CE_ENDPOINT") ce_auth_header = os.getenv("JUDGE0_CE_AUTH_HEADERS") - extra_ce_endpoint = os.getenv( - "JUDGE0_EXTRA_CE_ENDPOINT", "https://extra-ce.judge0.com" - ) + extra_ce_endpoint = os.getenv("JUDGE0_EXTRA_CE_ENDPOINT") extra_ce_auth_header = os.getenv("JUDGE0_EXTRA_CE_AUTH_HEADERS") if flavor == Flavor.CE and ce_endpoint is not None and ce_auth_header is not None: diff --git a/src/judge0/clients.py b/src/judge0/clients.py index 2d8366a..ae7c8d5 100644 --- a/src/judge0/clients.py +++ b/src/judge0/clients.py @@ -715,5 +715,77 @@ def __init__(self, api_key=None, **kwargs): super().__init__(self.DEFAULT_ENDPOINT, api_key, **kwargs) -CE = (SuluJudge0CE, RapidJudge0CE, ATDJudge0CE) -EXTRA_CE = (SuluJudge0ExtraCE, RapidJudge0ExtraCE, ATDJudge0ExtraCE) +class Judge0Cloud(Client): + """Base class for all Judge0 Cloud clients. + + Parameters + ---------- + endpoint : str + Default request endpoint. + auth_headers : str or dict + Judge0 Cloud authentication headers, either as a JSON string or a dictionary. + **kwargs : dict + Additional keyword arguments for the base Client. + """ + + def __init__(self, endpoint, auth_headers, **kwargs): + if isinstance(auth_headers, str): + from json import loads + + auth_headers = loads(auth_headers) + + super().__init__( + endpoint, + auth_headers, + **kwargs, + ) + + +class Judge0CloudCE(Judge0Cloud): + """Judge0 Cloud client for CE flavor. + + Parameters + ---------- + endpoint : str + Default request endpoint. + auth_headers : str or dict + Judge0 Cloud authentication headers, either as a JSON string or a dictionary. + **kwargs : dict + Additional keyword arguments for the base Client. + """ + + DEFAULT_ENDPOINT: ClassVar[str] = "https://ce.judge0.com" + HOME_URL: ClassVar[str] = "https://ce.judge0.com" + API_KEY_ENV: ClassVar[str] = "JUDGE0_CLOUD_CE_AUTH_HEADERS" + + def __init__(self, auth_headers, **kwargs): + super().__init__( + self.DEFAULT_ENDPOINT, + auth_headers, + **kwargs, + ) + + +class Judge0CloudExtraCE(Judge0Cloud): + """Judge0 Cloud client for Extra CE flavor. + + Parameters + ---------- + endpoint : str + Default request endpoint. + auth_headers : str or dict + Judge0 Cloud authentication headers, either as a JSON string or a dictionary. + **kwargs : dict + Additional keyword arguments for the base Client. + """ + + DEFAULT_ENDPOINT: ClassVar[str] = "https://extra-ce.judge0.com" + HOME_URL: ClassVar[str] = "https://extra-ce.judge0.com" + API_KEY_ENV: ClassVar[str] = "JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS" + + def __init__(self, auth_headers, **kwargs): + super().__init__(self.DEFAULT_ENDPOINT, auth_headers, **kwargs) + + +CE = (Judge0CloudCE, SuluJudge0CE, RapidJudge0CE, ATDJudge0CE) +EXTRA_CE = (Judge0CloudExtraCE, SuluJudge0ExtraCE, RapidJudge0ExtraCE, ATDJudge0ExtraCE) diff --git a/tests/conftest.py b/tests/conftest.py index 4e1547c..b8c950e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -91,6 +91,26 @@ def sulu_extra_ce_client(): return clients.SuluJudge0ExtraCE(api_key) +@pytest.fixture(scope="session") +def judge0_cloud_ce_client(): + auth_headers = os.getenv("JUDGE0_CLOUD_CE_AUTH_HEADERS") + + if auth_headers is None: + return None + else: + return clients.Judge0CloudCE(auth_headers) + + +@pytest.fixture(scope="session") +def judge0_cloud_extra_ce_client(): + auth_headers = os.getenv("JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS") + + if auth_headers is None: + return None + else: + return clients.Judge0CloudExtraCE(auth_headers) + + @pytest.fixture(scope="session") def preview_ce_client() -> clients.SuluJudge0CE: return clients.SuluJudge0CE(retry_strategy=RegularPeriodRetry(0.5)) @@ -104,6 +124,7 @@ def preview_extra_ce_client() -> clients.SuluJudge0ExtraCE: @pytest.fixture(scope="session") def ce_client( custom_ce_client, + judge0_cloud_ce_client, sulu_ce_client, rapid_ce_client, atd_ce_client, @@ -111,6 +132,8 @@ def ce_client( ): if custom_ce_client is not None: return custom_ce_client + if judge0_cloud_ce_client is not None: + return judge0_cloud_ce_client if sulu_ce_client is not None: return sulu_ce_client if rapid_ce_client is not None: @@ -126,6 +149,7 @@ def ce_client( @pytest.fixture(scope="session") def extra_ce_client( custom_extra_ce_client, + judge0_cloud_extra_ce_client, sulu_extra_ce_client, rapid_extra_ce_client, atd_extra_ce_client, @@ -133,6 +157,8 @@ def extra_ce_client( ): if custom_extra_ce_client is not None: return custom_extra_ce_client + if judge0_cloud_extra_ce_client is not None: + return judge0_cloud_extra_ce_client if sulu_extra_ce_client is not None: return sulu_extra_ce_client if rapid_extra_ce_client is not None: diff --git a/tests/test_clients.py b/tests/test_clients.py index c22c9dc..e5ccd45 100644 --- a/tests/test_clients.py +++ b/tests/test_clients.py @@ -7,6 +7,8 @@ "rapid_extra_ce_client", "sulu_ce_client", "sulu_extra_ce_client", + "judge0_cloud_ce_client", + "judge0_cloud_extra_ce_client", ) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy