diff --git a/poetry.lock b/poetry.lock index 0e2f87d..bc8a2d7 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.1.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.2.1 and should not be changed by hand. [[package]] name = "alabaster" @@ -667,21 +667,6 @@ files = [ {file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"}, ] -[[package]] -name = "snakesay" -version = "0.10.4" -description = "speaking snake" -optional = false -python-versions = ">=3.10" -groups = ["main"] -files = [ - {file = "snakesay-0.10.4-py3-none-any.whl", hash = "sha256:44eed09dc6d0e0ee9ea76a642bf591f5f5309dcefc59670a3b07c09bcf6952d1"}, - {file = "snakesay-0.10.4.tar.gz", hash = "sha256:d5765fbab9c7dd73cd20472614ba8eeb5066a743a88ff7cd9ae1d8d00aef326f"}, -] - -[package.extras] -dev = ["pytest", "pytest-cov"] - [[package]] name = "snowballstemmer" version = "2.2.0" @@ -937,4 +922,4 @@ zstd = ["zstandard (>=0.18.0)"] [metadata] lock-version = "2.1" python-versions = "^3.10" -content-hash = "10108845ed4e9bfb89ee173e65d8e535384ef7a4357ae37247b7cad25dd1d199" +content-hash = "d5f7d9113bb7d3301aea643cbe406a369bf71a3408604c6bdaba2329e4146aae" diff --git a/pyproject.toml b/pyproject.toml index 9762aca..d454120 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "pythonanywhere-core" -version = "0.2.8" +version = "0.2.9" description = "API wrapper for programmatic management of PythonAnywhere services." authors = ["PythonAnywhere "] license = "MIT" @@ -13,6 +13,7 @@ classifiers = [ "Intended Audience :: Developers", "Topic :: Software Development :: Libraries", "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.14", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.11", @@ -24,7 +25,6 @@ keywords = ["pythonanywhere", "api", "cloud", "web hosting"] python = "^3.10" python-dateutil = "^2.8.2" requests = "^2.30.0" -snakesay = "^0.10.3" typing_extensions = "^4.5.0" [tool.poetry.group.dev.dependencies] @@ -32,7 +32,7 @@ pytest = "^9.0.0" pytest-cov = "^7.0.0" pytest-mock = "^3.10.0" responses = "^0.25.0" -sphinx = "7.4.7" +sphinx = "8.2.3" sphinx-rtd-theme = "^3.0.0" [tool.black] diff --git a/pythonanywhere_core/__init__.py b/pythonanywhere_core/__init__.py index c49a95c..75cf783 100644 --- a/pythonanywhere_core/__init__.py +++ b/pythonanywhere_core/__init__.py @@ -1 +1 @@ -__version__ = "0.2.8" +__version__ = "0.2.9" diff --git a/pythonanywhere_core/exceptions.py b/pythonanywhere_core/exceptions.py index 625066a..fcdd1ec 100644 --- a/pythonanywhere_core/exceptions.py +++ b/pythonanywhere_core/exceptions.py @@ -15,4 +15,14 @@ class NoTokenError(PythonAnywhereApiException): class DomainAlreadyExistsException(PythonAnywhereApiException): - pass \ No newline at end of file + pass + + +class MissingCNAMEException(PythonAnywhereApiException): + def __init__(self): + super().__init__( + "Could not find a CNAME for your website. If you're using an A record, " + "CloudFlare, or some other way of pointing your domain at PythonAnywhere " + "then that should not be a problem. If you're not, you should double-check " + "your DNS setup." + ) \ No newline at end of file diff --git a/pythonanywhere_core/webapp.py b/pythonanywhere_core/webapp.py index dd42de3..3e00b22 100644 --- a/pythonanywhere_core/webapp.py +++ b/pythonanywhere_core/webapp.py @@ -7,10 +7,9 @@ from typing import Any from dateutil.parser import parse -from snakesay import snakesay from pythonanywhere_core.base import call_api, get_api_endpoint, PYTHON_VERSIONS -from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException +from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException, MissingCNAMEException class Webapp: @@ -54,7 +53,6 @@ def sanity_checks(self, nuke: bool) -> None: :raises SanityException: if API token is missing or webapp already exists """ - print(snakesay("Running API sanity checks")) token = os.environ.get("API_TOKEN") if not token: raise SanityException( @@ -127,24 +125,13 @@ def add_default_static_files_mappings(self, project_path: Path) -> None: def reload(self) -> None: """Reload webapp + :raises MissingCNAMEException: if CNAME not found (reload succeeded) :raises PythonAnywhereApiException: if API call fails""" url = f"{self.domain_url}reload/" response = call_api(url, "post") if not response.ok: if response.status_code == 409 and response.json()["error"] == "cname_error": - print( - snakesay( - dedent( - """ - Could not find a CNAME for your website. If you're using an A record, - CloudFlare, or some other way of pointing your domain at PythonAnywhere - then that should not be a problem. If you're not, you should double-check - your DNS setup. - """ - ) - ) - ) - return + raise MissingCNAMEException() raise PythonAnywhereApiException(f"POST to reload webapp via API failed, got {response}:{response.text}") def set_ssl(self, certificate: str, private_key: str) -> None: @@ -155,7 +142,6 @@ def set_ssl(self, certificate: str, private_key: str) -> None: :raises PythonAnywhereApiException: if API call fails """ - print(snakesay(f"Setting up SSL for {self.domain} via API")) url = f"{self.domain_url}ssl/" response = call_api(url, "post", json={"cert": certificate, "private_key": private_key}) if not response.ok: @@ -193,12 +179,6 @@ def delete_log(self, log_type: str, index: int = 0) -> None: :raises PythonAnywhereApiException: if API call fails """ - if index: - message = f"Deleting old (archive number {index}) {log_type} log file for {self.domain} via API" - else: - message = f"Deleting current {log_type} log file for {self.domain} via API" - print(snakesay(message)) - if index == 1: suffix = ".1" elif index > 1: diff --git a/tests/test_webapp.py b/tests/test_webapp.py index 367ac9b..8e38076 100644 --- a/tests/test_webapp.py +++ b/tests/test_webapp.py @@ -9,7 +9,7 @@ from urllib.parse import urlencode from pythonanywhere_core.base import get_api_endpoint, PYTHON_VERSIONS -from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException +from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException, MissingCNAMEException from pythonanywhere_core.webapp import Webapp @@ -298,7 +298,7 @@ def test_raises_if_post_does_not_20x_that_is_not_a_cname_error(api_responses, ap assert "nope" in str(e.value) -def test_does_not_raise_if_post_responds_with_a_cname_error(api_responses, api_token, domain_url, webapp): +def test_raises_missing_cname_exception_on_cname_error(api_responses, api_token, domain_url, webapp): reload_url = f"{domain_url}reload/" api_responses.add( responses.POST, @@ -307,7 +307,10 @@ def test_does_not_raise_if_post_responds_with_a_cname_error(api_responses, api_t json={"status": "error", "error": "cname_error"}, ) - webapp.reload() # Should not raise + with pytest.raises(MissingCNAMEException) as e: + webapp.reload() + + assert "Could not find a CNAME for your website" in str(e.value) # SET SSL