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..65c842d 100644 --- a/src/judge0/__init__.py +++ b/src/judge0/__init__.py @@ -1,3 +1,4 @@ +import logging import os from typing import Union @@ -18,6 +19,9 @@ ATDJudge0CE, ATDJudge0ExtraCE, Client, + Judge0Cloud, + Judge0CloudCE, + Judge0CloudExtraCE, Rapid, RapidJudge0CE, RapidJudge0ExtraCE, @@ -29,7 +33,7 @@ from .retry import MaxRetries, MaxWaitTime, RegularPeriodRetry from .submission import Submission -__version__ = "0.0.4" +__version__ = "0.0.5.dev0" __all__ = [ "ATD", @@ -38,6 +42,9 @@ "Client", "File", "Filesystem", + "Judge0Cloud", + "Judge0CloudCE", + "Judge0CloudExtraCE", "Language", "LanguageAlias", "MaxRetries", @@ -53,18 +60,20 @@ "SuluJudge0ExtraCE", "TestCase", "async_execute", + "async_run", "execute", "get_client", - "async_run", - "sync_run", "run", "sync_execute", + "sync_run", "wait", ] 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 +113,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: 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