Skip to content

Commit a5c2864

Browse files
Removes snakesay.
1 parent d932d3e commit a5c2864

File tree

6 files changed

+25
-47
lines changed

6 files changed

+25
-47
lines changed

poetry.lock

Lines changed: 2 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "pythonanywhere-core"
3-
version = "0.2.8"
3+
version = "0.2.9"
44
description = "API wrapper for programmatic management of PythonAnywhere services."
55
authors = ["PythonAnywhere <[email protected]>"]
66
license = "MIT"
@@ -13,6 +13,7 @@ classifiers = [
1313
"Intended Audience :: Developers",
1414
"Topic :: Software Development :: Libraries",
1515
"License :: OSI Approved :: MIT License",
16+
"Programming Language :: Python :: 3.14",
1617
"Programming Language :: Python :: 3.13",
1718
"Programming Language :: Python :: 3.12",
1819
"Programming Language :: Python :: 3.11",
@@ -24,7 +25,6 @@ keywords = ["pythonanywhere", "api", "cloud", "web hosting"]
2425
python = "^3.10"
2526
python-dateutil = "^2.8.2"
2627
requests = "^2.30.0"
27-
snakesay = "^0.10.3"
2828
typing_extensions = "^4.5.0"
2929

3030
[tool.poetry.group.dev.dependencies]

pythonanywhere_core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.2.8"
1+
__version__ = "0.2.9"

pythonanywhere_core/exceptions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,14 @@ class NoTokenError(PythonAnywhereApiException):
1515

1616

1717
class DomainAlreadyExistsException(PythonAnywhereApiException):
18-
pass
18+
pass
19+
20+
21+
class MissingCNAMEException(PythonAnywhereApiException):
22+
def __init__(self):
23+
super().__init__(
24+
"Could not find a CNAME for your website. If you're using an A record, "
25+
"CloudFlare, or some other way of pointing your domain at PythonAnywhere "
26+
"then that should not be a problem. If you're not, you should double-check "
27+
"your DNS setup."
28+
)

pythonanywhere_core/webapp.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77
from typing import Any
88

99
from dateutil.parser import parse
10-
from snakesay import snakesay
1110

1211
from pythonanywhere_core.base import call_api, get_api_endpoint, PYTHON_VERSIONS
13-
from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException
12+
from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException, MissingCNAMEException
1413

1514

1615
class Webapp:
@@ -54,7 +53,6 @@ def sanity_checks(self, nuke: bool) -> None:
5453
5554
:raises SanityException: if API token is missing or webapp already exists
5655
"""
57-
print(snakesay("Running API sanity checks"))
5856
token = os.environ.get("API_TOKEN")
5957
if not token:
6058
raise SanityException(
@@ -127,24 +125,13 @@ def add_default_static_files_mappings(self, project_path: Path) -> None:
127125
def reload(self) -> None:
128126
"""Reload webapp
129127
128+
:raises MissingCNAMEException: if CNAME not found (reload succeeded)
130129
:raises PythonAnywhereApiException: if API call fails"""
131130
url = f"{self.domain_url}reload/"
132131
response = call_api(url, "post")
133132
if not response.ok:
134133
if response.status_code == 409 and response.json()["error"] == "cname_error":
135-
print(
136-
snakesay(
137-
dedent(
138-
"""
139-
Could not find a CNAME for your website. If you're using an A record,
140-
CloudFlare, or some other way of pointing your domain at PythonAnywhere
141-
then that should not be a problem. If you're not, you should double-check
142-
your DNS setup.
143-
"""
144-
)
145-
)
146-
)
147-
return
134+
raise MissingCNAMEException()
148135
raise PythonAnywhereApiException(f"POST to reload webapp via API failed, got {response}:{response.text}")
149136

150137
def set_ssl(self, certificate: str, private_key: str) -> None:
@@ -155,7 +142,6 @@ def set_ssl(self, certificate: str, private_key: str) -> None:
155142
156143
:raises PythonAnywhereApiException: if API call fails
157144
"""
158-
print(snakesay(f"Setting up SSL for {self.domain} via API"))
159145
url = f"{self.domain_url}ssl/"
160146
response = call_api(url, "post", json={"cert": certificate, "private_key": private_key})
161147
if not response.ok:
@@ -193,12 +179,6 @@ def delete_log(self, log_type: str, index: int = 0) -> None:
193179
194180
:raises PythonAnywhereApiException: if API call fails
195181
"""
196-
if index:
197-
message = f"Deleting old (archive number {index}) {log_type} log file for {self.domain} via API"
198-
else:
199-
message = f"Deleting current {log_type} log file for {self.domain} via API"
200-
print(snakesay(message))
201-
202182
if index == 1:
203183
suffix = ".1"
204184
elif index > 1:

tests/test_webapp.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from urllib.parse import urlencode
1010

1111
from pythonanywhere_core.base import get_api_endpoint, PYTHON_VERSIONS
12-
from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException
12+
from pythonanywhere_core.exceptions import SanityException, PythonAnywhereApiException, MissingCNAMEException
1313
from pythonanywhere_core.webapp import Webapp
1414

1515

@@ -298,7 +298,7 @@ def test_raises_if_post_does_not_20x_that_is_not_a_cname_error(api_responses, ap
298298
assert "nope" in str(e.value)
299299

300300

301-
def test_does_not_raise_if_post_responds_with_a_cname_error(api_responses, api_token, domain_url, webapp):
301+
def test_raises_missing_cname_exception_on_cname_error(api_responses, api_token, domain_url, webapp):
302302
reload_url = f"{domain_url}reload/"
303303
api_responses.add(
304304
responses.POST,
@@ -307,7 +307,10 @@ def test_does_not_raise_if_post_responds_with_a_cname_error(api_responses, api_t
307307
json={"status": "error", "error": "cname_error"},
308308
)
309309

310-
webapp.reload() # Should not raise
310+
with pytest.raises(MissingCNAMEException) as e:
311+
webapp.reload()
312+
313+
assert "Could not find a CNAME for your website" in str(e.value)
311314

312315

313316
# SET SSL

0 commit comments

Comments
 (0)