-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
104 lines (80 loc) · 3.06 KB
/
setup.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""Setup file for etudelib."""
from importlib.util import module_from_spec, spec_from_file_location
from pathlib import Path
from typing import List
from setuptools import find_packages, setup
def load_module(name: str = "etudelib/__init__.py"):
"""Load Python Module.
Args:
name (str, optional): Name of the module to load.
Defaults to "etudelib/__init__.py".
Returns:
_type_: _description_
"""
location = str(Path(__file__).parent / name)
spec = spec_from_file_location(name=name, location=location)
module = module_from_spec(spec) # type: ignore
spec.loader.exec_module(module) # type: ignore
return module
def get_version() -> str:
"""Get version from `etudelib.__init__`.
Version is stored in the main __init__ module in `etudelib`.
The varible storing the version is `__version__`. This function
reads `__init__` file, checks `__version__ variable and return
the value assigned to it.
Example:
>>> # Assume that __version__ = "0.0.1"
>>> get_version()
"0.0.1"
Returns:
str: `etudelib` version.
"""
etude2 = load_module(name="etudelib/__init__.py")
version = etude2.__version__
return version
def get_required_packages(requirement_files: List[str]) -> List[str]:
"""Get packages from requirements.txt file.
This function returns list of required packages from requirement files.
Args:
requirement_files (List[str]): txt files that contains list of required
packages.
Example:
>>> get_required_packages(requirement_files=["onnx"])
['onnx>=1.8.1', 'networkx~=2.5', ...]
Returns:
List[str]: List of required packages
"""
required_packages: List[str] = []
for requirement_file in requirement_files:
with open(f"requirements/{requirement_file}.txt", "r", encoding="utf8") as file:
for line in file:
package = line.strip()
if package and not package.startswith(("#", "-f")):
required_packages.append(package)
return required_packages
VERSION = get_version()
LONG_DESCRIPTION = (Path(__file__).parent / "README.md").read_text(encoding="utf8")
INSTALL_REQUIRES = get_required_packages(requirement_files=["base"])
EXTRAS_REQUIRE = {
"dev": get_required_packages(requirement_files=["dev"]),
"full": get_required_packages(requirement_files=["docs", "dev"]),
}
setup(
name="etudelib",
version=get_version(),
author="bolcom",
author_email="[email protected]",
description="etude",
long_description=LONG_DESCRIPTION,
long_description_content_type="text/markdown",
url="",
license="Copyright (c)"
'Licensed under the Apache License, Version 2.0 (the "License")'
"See LICENSE file for more details.",
python_requires=">=3.8",
packages=find_packages(exclude=("tests",)),
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRE,
package_data={"": ["config.yaml"]},
entry_points={"console_scripts": ["etudelib=etudelib.utils.cli.cli:main"]},
)