Skip to content

Commit 6a5368a

Browse files
Merge pull request #22 from Pilifer/typing
Type annotations in api wrappers and scripts
2 parents 8c7bb10 + 2bb719b commit 6a5368a

17 files changed

+94
-2
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ target/
6969
# IPython Notebook
7070
.ipynb_checkpoints
7171

72+
# Mypy
73+
.mypy_cache/
74+
7275
# pyenv
7376
.python-version
7477

@@ -83,7 +86,7 @@ celerybeat-schedule
8386
venv/
8487
ENV/
8588

86-
#PyCharm project folder
89+
# PyCharm project folder
8790
.idea/
8891

8992
# Spyder project settings

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ install:
2020
script:
2121
- pytest
2222
- pytest --cov=pythonanywhere --cov=scripts --cov-fail-under=65
23+
- pytest --mypy -m mypy

mypy.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[mypy]
2+
ignore_missing_imports = True

pythonanywhere/api.pyi

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pathlib import Path
2+
from typing import Dict, List, Any
3+
4+
from requests import Response
5+
6+
PYTHON_VERSIONS = Dict[str, str]
7+
8+
class AuthenticationError(Exception): ...
9+
class NoTokenError(Exception): ...
10+
11+
def get_api_endpoint() -> str: ...
12+
def call_api(url: str, method: str, **kwargs) -> Response: ...
13+
14+
class Webapp:
15+
domain: str = ...
16+
def __init__(self, domain: str) -> None: ...
17+
def __eq__(self, other: Webapp) -> bool: ...
18+
def sanity_checks(self, nuke: bool) -> None: ...
19+
def create(self, python_version: str, virtualenv_path: Path, project_path: Path, nuke: bool) -> None: ...
20+
def add_default_static_files_mappings(self, project_path: Path) -> None: ...
21+
def reload(self) -> None: ...
22+
def set_ssl(self, certificate: str, private_key: str) -> None: ...
23+
def get_ssl_info(self) -> Dict[str, Any]: ...
24+
def delete_log(self, log_type: str, index: int = 0) -> None: ...
25+
def get_log_info(self) -> Dict[str, List[int]]: ...

pythonanywhere/django_project.pyi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pathlib import Path
2+
3+
from pythonanywhere.project import Project
4+
from typing import Optional
5+
6+
class DjangoProject(Project):
7+
def download_repo(self, repo: str, nuke: bool) -> None: ...
8+
def create_virtualenv(self, django_version: Optional[str] = ..., nuke: bool = ...) -> None: ...
9+
def detect_requirements(self): ...
10+
def run_startproject(self, nuke: bool) -> None: ...
11+
settings_path: Path = ...
12+
manage_py_path: Path = ...
13+
def find_django_files(self) -> None: ...
14+
def update_settings_file(self) -> None: ...
15+
def run_collectstatic(self) -> None: ...
16+
def run_migrate(self) -> None: ...
17+
def update_wsgi_file(self) -> None: ...

pythonanywhere/exceptions.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class SanityException(Exception): ...

pythonanywhere/project.pyi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from pathlib import Path
2+
3+
from pythonanywhere.api import Webapp
4+
from pythonanywhere.virtualenvs import Virtualenv
5+
6+
class Project:
7+
domain: str = ...
8+
python_version: str = ...
9+
project_path: Path = ...
10+
virtualenv: Virtualenv = ...
11+
wsgi_file_path: Path = ...
12+
webapp: Webapp = ...
13+
def __init__(self, domain: str, python_version: str) -> None: ...
14+
def sanity_checks(self, nuke: bool) -> None: ...
15+
def create_webapp(self, nuke: bool) -> None: ...
16+
def add_static_file_mappings(self) -> None: ...
17+
def start_bash(self) -> None: ...

pythonanywhere/snakesay.pyi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import Type, Tuple, List, Iterator
2+
3+
MESSAGE = Type[str]
4+
5+
def snakesay(*things) -> str: ...
6+
def speech_bubble_lines(speech: str) -> Iterator[str]: ...
7+
def rewrap(speech: str) -> Tuple[List[str], int]: ...

pythonanywhere/virtualenvs.pyi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pathlib import Path
2+
from typing import List
3+
4+
5+
class Virtualenv:
6+
domain: str = ...
7+
python_version: str = ...
8+
path: Path = ...
9+
def __init__(self, domain: str, python_version: str) -> None: ...
10+
def __eq__(self, other: Virtualenv) -> bool: ...
11+
def create(self, nuke: bool) -> None: ...
12+
def pip_install(self, packages: List[str]) -> None: ...

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ psutil==5.4.0
99
py==1.7.0
1010
pytest==3.2.3
1111
pytest-cov==2.6.0
12+
pytest-mypy==0.4.2
1213
python-dateutil==2.7.5
1314
requests==2.22.0
1415
responses==0.8.1

0 commit comments

Comments
 (0)