-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_utils.py
74 lines (67 loc) · 2.55 KB
/
setup_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os.path
import re
class SetupConfig:
PACKAGE_NAME = "xfilios"
@staticmethod
def parse_pipfile():
"""Parse a Pipfile and store it in Dictionary"""
pipfile_dict = dict()
current_option = None
with open("Pipfile", "r") as f:
for line in f:
if line.startswith("["):
option = re.sub(r"\[|\]|\n", "", line)
pipfile_dict[option] = list()
current_option = option.strip()
if line != "" and not line.startswith("[") and len(line) > 0:
pipfile_dict[current_option].append(line.strip().replace('"', ""))
return pipfile_dict
@staticmethod
def format_requirements(item):
"""Format Package name for install requires"""
if "*" in item[1]:
return item[0]
return "".join(item)
@classmethod
def get_install_requirements(cls):
"""Generate Install Requirements"""
try:
pipfile_dict = cls.parse_pipfile()
packages = [
item.split(" = ")
for item in pipfile_dict["packages"]
if "editable" not in item and len(item) > 0
]
packages = [cls.format_requirements(item) for item in packages]
print("Following are the required packages: {}".format(", ".join(packages)))
return packages
except Exception as e:
raise IOError(e)
@staticmethod
def read_metadata_from_readme():
"""Read the readme file for setup."""
readme_txt = ""
try:
with open("README.md", "rt", encoding="utf-8") as f:
readme_text = f.read()
print("Read me read successfully !")
return readme_text
except FileNotFoundError as e:
print(e)
return readme_txt
except Exception as e:
print(e)
return readme_txt
@classmethod
def get_version_from_package(cls):
"""Read the current version from the package"""
with open(
os.path.join("src", cls.PACKAGE_NAME, "__init__.py"), "rt", encoding="utf-8"
) as f:
for line in f:
if "VERSION" in line:
version: str = line.split("=")[1]
version = version.strip().replace('"', "")
print(f"The version tag will be used for the build: {version}")
return version
raise KeyError("Could not find the VERSION tag in the __init__.py file")