Skip to content

Commit f4fa41e

Browse files
committed
fix codestyle, add getversion script
1 parent 91e81b8 commit f4fa41e

File tree

3 files changed

+105
-27
lines changed

3 files changed

+105
-27
lines changed

getversion.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import re
4+
5+
6+
class GitVersion:
7+
def __init__(self):
8+
self._default_version = "0.0.1.0a"
9+
os.chdir(os.path.dirname(os.path.realpath(__file__)))
10+
11+
@property
12+
def tag(self):
13+
stream = os.popen("git describe --match v[0-9]* --abbrev=0 --tags")
14+
return stream.read().strip()
15+
16+
@property
17+
def version(self):
18+
version = f"{self.tag[1:]}.{self.build}"
19+
20+
if version == ".":
21+
return self._default_version
22+
23+
return version
24+
25+
@property
26+
def default_branch(self):
27+
stream = os.popen("git config --get init.defaultBranch")
28+
result = stream.read().strip()
29+
30+
if not result:
31+
result = "main"
32+
33+
return result
34+
35+
@property
36+
def build(self):
37+
stream = os.popen("git rev-list {}.. --count".format(self.tag))
38+
return stream.read().strip()
39+
40+
@property
41+
def branch(self):
42+
stream = os.popen("git branch --show-current")
43+
return stream.read().strip()
44+
45+
@property
46+
def full(self):
47+
return f"{self.version}-{self.branch}"
48+
49+
@property
50+
def standard(self):
51+
standard = f"{self.version}-{self.branch}"
52+
if self.branch == self.default_branch or re.match("release/.*", self.branch):
53+
standard = f"{self.version}"
54+
return standard
55+
56+
@property
57+
def commit(self):
58+
stream = os.popen("git rev-parse HEAD")
59+
return stream.read().strip()
60+
61+
@property
62+
def commit_hash(self):
63+
stream = os.popen("git rev-parse --short HEAD")
64+
return stream.read().strip()
65+
66+
def __str__(self):
67+
return f"""
68+
Tag: {self.tag}
69+
Version: {self.version}
70+
Full: {self.full}
71+
Branch: {self.branch}
72+
Build: {self.build}
73+
Standard: {self.standard}
74+
Commit: {self.commit}
75+
76+
Current: {self.full} {self.commit_hash}
77+
"""
78+
79+
80+
if __name__ == "__main__":
81+
git_version = GitVersion()
82+
print(git_version)

pyechonext/config.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ class SettingsLoader:
5959
This class describes a settings loader.
6060
"""
6161

62-
__slots__ = (
63-
'config',
64-
'config_type',
65-
'filename'
66-
)
62+
__slots__ = ("config", "config_type", "filename")
6763

6864
def __init__(self, config_type: SettingsConfigType, filename: str = None):
6965
"""Initialize a basic settings info

pyechonext/schemas/fields.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# дай угадаю, кто то украл твой сладкий рулет?
2-
from typing import Any, Optional, Dict, Optional, Callable, Union, Type, List
2+
from typing import Any, Callable, Dict, List, Optional, Type
33

44

55
class BaseField:
@@ -16,16 +16,18 @@ class BaseField:
1616
8. name - name of field
1717
"""
1818

19-
def __init__(self,
20-
name: str,
21-
datatype: Type,
22-
nullable: bool = False,
23-
default: Optional[Any] = None,
24-
max_length: Optional[int] = None,
25-
desc: Optional[str] = None,
26-
exclude: bool = False,
27-
transformer: Optional[Callable[[Any], Any]] = None,
28-
dependencies: Optional[List[str]] = None) -> None:
19+
def __init__(
20+
self,
21+
name: str,
22+
datatype: Type,
23+
nullable: bool = False,
24+
default: Optional[Any] = None,
25+
max_length: Optional[int] = None,
26+
desc: Optional[str] = None,
27+
exclude: bool = False,
28+
transformer: Optional[Callable[[Any], Any]] = None,
29+
dependencies: Optional[List[str]] = None,
30+
) -> None:
2931
self.name = name
3032
self.nullable = nullable
3133
self.datatype: Type = datatype
@@ -45,16 +47,11 @@ def fast_validate(self, value: Any) -> bool:
4547
Returns:
4648
bool: True if all conditions is right, otherwise False
4749
"""
48-
conditions = [
49-
isinstance(value, self.datatype),
50-
len(value) <= max_length
51-
]
50+
conditions = [isinstance(value, self.datatype), len(value) <= max_length]
5251

5352
return all(conditions)
54-
55-
def validate(self,
56-
value: Any,
57-
context: Optional[Dict[str, Any]] = None) -> Any:
53+
54+
def validate(self, value: Any, context: Optional[Dict[str, Any]] = None) -> Any:
5855
"""Validate field value
5956
6057
Args:
@@ -81,8 +78,11 @@ def validate(self,
8178

8279
if context:
8380
for dependency in self.dependencies:
84-
if dependency in context and not self._validate_dependency(value, context[dependency]):
85-
raise ValueError(f"Field '{self.name}' is invalid based on dependency {dependency}.")
81+
if dependency in context and not self._validate_dependency(
82+
value, context[dependency]
83+
):
84+
raise ValueError(
85+
f"Field '{self.name}' is invalid based on dependency {dependency}."
86+
)
8687

8788
return value
88-

0 commit comments

Comments
 (0)