Skip to content

Commit c4c307d

Browse files
committed
update: WIP
1 parent 34832db commit c4c307d

23 files changed

+365
-75
lines changed

.readthedocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ python:
2222
version: 3.8
2323
install:
2424
- requirements: docs/requirements.txt
25+
- requirements: requirements.txt

devinstaller/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -----------------------------------------------------------------------------
22
# Created: Mon 25 May 2020 15:10:17 IST
3-
# Last-Updated: Sat 8 Aug 2020 15:20:44 IST
3+
# Last-Updated: Mon 10 Aug 2020 01:11:15 IST
44
#
55
# __main__.py is part of devinstaller
66
# URL: https://gitlab.com/justinekizhak/devinstaller
@@ -36,7 +36,7 @@
3636
"""The main entrypoint module for running CLI commands
3737
"""
3838
import os
39-
from typing import Optional
39+
from typing import List, Optional
4040

4141
import click
4242

devinstaller/commands.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -----------------------------------------------------------------------------
22
# Created: Mon 25 May 2020 16:55:05 IST
3-
# Last-Updated: Sat 1 Aug 2020 21:20:16 IST
3+
# Last-Updated: Mon 10 Aug 2020 01:49:41 IST
44
#
55
# commands.py is part of devinstaller
66
# URL: https://gitlab.com/justinekizhak/devinstaller
@@ -37,9 +37,18 @@
3737
import re
3838
import shlex
3939
import subprocess
40+
from dataclasses import dataclass
4041

4142
from devinstaller import exceptions as e
42-
from devinstaller import models as m
43+
44+
45+
@dataclass
46+
class CommandResponse:
47+
"""Response object for the `devinstaller.comands.check_cmd`
48+
"""
49+
50+
prog: str
51+
cmd: str
4352

4453

4554
def run_shell(command: str) -> None:
@@ -73,14 +82,14 @@ def run(command: str) -> None:
7382
command_functions[res.prog](res.cmd)
7483

7584

76-
def check_cmd(command: str) -> m.CommandResponse:
85+
def check_cmd(command: str) -> CommandResponse:
7786
"""Check the command and returns the command response object
7887
"""
7988
try:
8089
pattern = r"^(py|sh): (.*)"
8190
result = re.match(pattern, command)
8291
assert result is not None
83-
data = m.CommandResponse(prog=result.group(0), cmd=result.group(1))
92+
data = CommandResponse(prog=result.group(0), cmd=result.group(1))
8493
return data
8594
except AssertionError:
8695
raise e.SpecificationError(

devinstaller/file_handler.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -----------------------------------------------------------------------------
22
# Created: Mon 25 May 2020 15:40:37 IST
3-
# Last-Updated: Sat 1 Aug 2020 18:17:53 IST
3+
# Last-Updated: Mon 10 Aug 2020 01:50:05 IST
44
#
55
# file_handler.py is part of devinstaller
66
# URL: https://gitlab.com/justinekizhak/devinstaller
@@ -37,14 +37,32 @@
3737
import hashlib
3838
import os
3939
import re
40+
from dataclasses import dataclass
4041
from typing import Any, Callable, Dict
4142

4243
import anymarkup
4344
import requests
4445
from typeguard import typechecked
4546

4647
from devinstaller import exceptions as e
47-
from devinstaller import models as m
48+
49+
50+
@dataclass
51+
class FileResponse:
52+
"""Response object for the `devinstaller.file_handler.get_data`
53+
"""
54+
55+
digest: str
56+
contents: str
57+
58+
59+
@dataclass
60+
class PathResponse:
61+
"""Response object for the `devinstaller.file_handler.check_path`
62+
"""
63+
64+
method: str
65+
path: str
4866

4967

5068
@typechecked
@@ -83,8 +101,8 @@ def read_file(file_path: str) -> str:
83101
"""
84102
# TODO check if the path is starting with dot or two dots
85103
full_path = os.path.expanduser(file_path)
86-
with open(full_path, "r") as f:
87-
return f.read()
104+
with open(full_path, "r") as _f:
105+
return _f.read()
88106

89107

90108
@typechecked
@@ -126,7 +144,7 @@ def write_file(file_content: str, file_path: str) -> None:
126144

127145

128146
@typechecked
129-
def get_data(file_path: str) -> m.FileResponse:
147+
def get_data(file_path: str) -> FileResponse:
130148
"""Checks the input_str and downloads or reads the file.
131149
132150
Methods:
@@ -159,18 +177,18 @@ def get_data(file_path: str) -> m.FileResponse:
159177
"data": lambda x: x,
160178
}
161179
file_contents = function[method](file_path)
162-
data = m.FileResponse(digest=hash(str(file_contents)), contents=file_contents)
180+
data = FileResponse(digest=hash_data(str(file_contents)), contents=file_contents)
163181
return data
164182

165183

166184
@typechecked
167-
def hash(input_data: str) -> str:
185+
def hash_data(input_data: str) -> str:
168186
"""Hashes the input string and returns its digest
169187
"""
170188
return hashlib.sha256(input_data.encode("utf-8")).hexdigest()
171189

172190

173-
def check_path(file_path: str) -> m.PathResponse:
191+
def check_path(file_path: str) -> PathResponse:
174192
"""Check if the given path is adhearing to the spec
175193
176194
Args:
@@ -183,7 +201,7 @@ def check_path(file_path: str) -> m.PathResponse:
183201
pattern = r"^(url|file|data): (.*)"
184202
result = re.match(pattern, file_path)
185203
assert result is not None
186-
data = m.PathResponse(method=result.group(1), path=result.group(2))
204+
data = PathResponse(method=result.group(1), path=result.group(2))
187205
return data
188206
except AssertionError:
189207
raise e.SpecificationError(

devinstaller/hookspecs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
hookspec = pluggy.HookspecMarker("devinstaller")
99

10+
# pylint: disable=unused-argument
11+
1012

1113
@hookspec
1214
def create_dependency_graph(

devinstaller/host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def run(
8484
prog_file_path: Optional[str] = None,
8585
spec_object: Optional[Dict[Any, Any]] = None,
8686
platform_codename: Optional[str] = None,
87-
) -> m.TypeFullDocument:
87+
) -> None:
8888
"""The `run` function.
8989
9090
This function is used for the interface block.

devinstaller/models/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"""
33
from devinstaller.models.base_module import ModuleInstallInstruction
44
from devinstaller.models.common_models import (
5-
CommandResponse,
6-
FileResponse,
7-
PathResponse,
85
TypeAnyModule,
96
TypeFullDocument,
107
TypeInterface,

devinstaller/models/app_module.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __post_init_post_parse__(self):
3838
return None
3939
for i in self.uninstall_inst:
4040
i = i.format(**self.constants)
41+
return None
4142

4243
def install(self) -> None:
4344
"""The function which installs app modules
@@ -52,6 +53,7 @@ def install(self) -> None:
5253
# installation_steps = create_instruction_list(self.install_inst)
5354
try:
5455
self.execute_instructions(self.install_inst)
56+
return None
5557
except ModuleRollbackFailed:
5658
print(f"Rollback instructions for {self.display} failed. Quitting program.")
5759
sys.exit(1)
@@ -69,6 +71,7 @@ def uninstall(self) -> None:
6971
try:
7072
for i in self.uninstall_inst:
7173
c.run(i)
74+
return None
7275
except ModuleInstallationFailed:
7376
print(f"Uninstallation of {self.display} failed. Quitting program.")
7477
sys.exit(1)

devinstaller/models/base_module.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from pydantic.dataclasses import dataclass
55
from typeguard import typechecked
66

7-
from devinstaller.commands import run_shell
7+
from devinstaller.commands import run
88
from devinstaller.exceptions import (
99
CommandFailed,
1010
ModuleInstallationFailed,
@@ -40,7 +40,7 @@ class BaseModule:
4040
@validator("constants", pre=True)
4141
@typechecked
4242
def convert_constant(
43-
cls, constants: Optional[List[Dict[str, str]]]
43+
self, constants: Optional[List[Dict[str, str]]]
4444
) -> Dict[str, str]:
4545
data: Dict[str, str] = {}
4646
if constants is None:
@@ -120,4 +120,3 @@ def rollback_instructions(
120120
run(inst.rollback)
121121
except CommandFailed:
122122
raise ModuleRollbackFailed
123-
return None

devinstaller/models/common_models.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -----------------------------------------------------------------------------
22
# Created: Thu 28 May 2020 23:37:47 IST
3-
# Last-Updated: Sat 1 Aug 2020 21:18:33 IST
3+
# Last-Updated: Mon 10 Aug 2020 01:43:03 IST
44
#
55
# models.py is part of devinstaller
66
# URL: https://gitlab.com/justinekizhak/devinstaller
@@ -81,6 +81,8 @@ class TypeCommonModule(TypedDict, total=False):
8181
target: str
8282
url: str
8383
version: str
84+
before: Optional[str]
85+
after: Optional[str]
8486

8587

8688
class TypeInterfaceModule(TypedDict, total=False):
@@ -154,33 +156,6 @@ class TypeValidateResponse(TypedDict):
154156
errors: Dict[Any, Any]
155157

156158

157-
@dataclass
158-
class FileResponse:
159-
"""Response object for the `devinstaller.file_handler.get_data`
160-
"""
161-
162-
digest: str
163-
contents: str
164-
165-
166-
@dataclass
167-
class PathResponse:
168-
"""Response object for the `devinstaller.file_handler.check_path`
169-
"""
170-
171-
method: str
172-
path: str
173-
174-
175-
@dataclass
176-
class CommandResponse:
177-
"""Response object for the `devinstaller.comands.check_cmd`
178-
"""
179-
180-
prog: str
181-
cmd: str
182-
183-
184159
TypeAnyModule = Union[
185160
AppModule, FileModule, FolderModule, LinkModule, GroupModule, PhonyModule
186161
]

0 commit comments

Comments
 (0)