-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path__init__.py
115 lines (87 loc) · 3.45 KB
/
__init__.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
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import datetime
import os
from pathlib import Path
from warnings import warn
import pkg_resources
from apppath import AppPath
__project__ = "NeodroidVision"
__author__ = "Christian Heider Nielsen"
__version__ = "0.3.0"
__doc__ = r"""
.. module:: neodroidvision
:platform: Unix, Windows
:synopsis: A set of general computer vision tools build for the neodroid platform.
.. moduleauthor:: Christian Heider Nielsen <christian.heider@alexandra.dk>
Created on 27/04/2019
@author: cnheider
"""
# __all__ = ['PROJECT_APP_PATH', 'PROJECT_NAME', 'PROJECT_VERSION', 'get_version']
from typing import Any
def dist_is_editable(dist: Any) -> bool:
"""
Return True if given Distribution is an editable installation."""
import sys
from pathlib import Path
for path_item in sys.path:
egg_link = Path(path_item) / f"{dist.project_name}.egg-link"
if egg_link.is_file():
return True
return False
PROJECT_NAME = __project__.lower().strip().replace(" ", "_")
PROJECT_VERSION = __version__
PROJECT_YEAR = 2018
PROJECT_AUTHOR = __author__.lower().strip().replace(" ", "_")
PROJECT_ORGANISATION = "Neodroid"
PROJECT_APP_PATH = AppPath(app_name=PROJECT_NAME, app_author=PROJECT_AUTHOR)
PACKAGE_DATA_PATH = Path(pkg_resources.resource_filename(PROJECT_NAME, "data"))
INCLUDE_PROJECT_READMES = False
distributions = {v.key: v for v in pkg_resources.working_set}
if PROJECT_NAME in distributions:
distribution = distributions[PROJECT_NAME]
DEVELOP = dist_is_editable(distribution)
else:
DEVELOP = True
def get_version(append_time: Any = DEVELOP) -> str:
"""
Args:
append_time:
Returns:
"""
version = __version__
if not version:
version = os.getenv("VERSION", "0.0.0")
if append_time:
now = datetime.datetime.utcnow()
date_version = now.strftime("%Y%m%d%H%M%S")
# date_version = time.time()
if version:
# Most git tags are prefixed with 'v' (example: v1.2.3) this is
# never desirable for artifact repositories, so we strip the
# leading 'v' if it's present.
version = (
version[1:]
if isinstance(version, str) and version.startswith("v")
else version
)
else:
# Default version is an ISO8601 compliant datetime. PyPI doesn't allow
# the colon ':' character in its versions, and time is required to allow
# for multiple publications to master in one day. This datetime string
# uses the 'basic' ISO8601 format for both its date and time components
# to avoid issues with the colon character (ISO requires that date and
# time components of a date-time string must be uniformly basic or
# extended, which is why the date component does not have dashes.
#
# Publications using datetime versions should only be made from master
# to represent the HEAD moving forward.
warn(
f"Environment variable VERSION is not set, only using datetime: {date_version}"
)
# warn(f'Environment variable VERSION is not set, only using timestamp: {version}')
version = f"{version}.{date_version}"
return version
if __version__ is None:
__version__ = get_version(append_time=True)
__version_info__ = tuple(int(segment) for segment in __version__.split("."))