-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·110 lines (92 loc) · 2.84 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
105
106
107
108
109
110
#! /usr/bin/env python
import os
import re
import site
import sys
from distutils import sysconfig
from setuptools import find_packages, setup
def is_venv():
real, base = map(lambda arg: hasattr(sys, arg),
["real_prefix", "base_prefix"])
return real or base and base != sys.prefix
def get_site():
func = getattr(site, "getsitepackages", None)
if func:
return func()[0]
return sysconfig.get_python_lib()
def read(fpath):
check = os.path.isfile
path = os.path.join(os.path.dirname(__file__), fpath)
if not check(path):
path = fpath
if not check(path):
return None
with open(path) as stream:
return stream.read()
def get_requirements(path="requirements.txt"):
data = read(path)
lines = []
if not data:
return lines
for line in data.splitlines():
line = line.strip()
if not line or line.startswith("#"):
continue
if line.startswith("-r"):
new_path = line[2:].strip()
lines.extend(get_requirements(path=new_path))
continue
lines.append(line)
return lines
def get_data_files(source, files, use_source=False):
destination = (source if use_source else
os.path.join(get_site(), source))
paths = [os.path.join(source, name) for name in files]
return destination, paths
UNIX = bool(re.search(r"linux|darwin", sys.platform))
VENV = is_venv()
PIP = "--single-version-externally-managed" in sys.argv
LOCAL = PIP and any(map(lambda arg: arg.startswith("--home"), sys.argv))
USE_SOURCE = not UNIX or LOCAL or (VENV and not PIP)
ETC, RES = map(lambda arg: os.path.join(arg, "libmorse"), ["etc", "res"])
setup(
name="libmorse",
version="0.6.8",
description="Convert timed signals into alphabet.",
long_description=read("README.md") or "",
url="https://github.com/cmin764/libmorse",
license="MIT",
author="Cosmin Poieana",
author_email="[email protected]",
packages=find_packages(),
scripts=[os.path.join("bin", "libmorse")],
include_package_data=True,
zip_safe=False,
install_requires=get_requirements(),
test_suite="tests",
data_files = [
get_data_files(source, files, use_source=USE_SOURCE)
for source, files in [
(
ETC,
[
"libmorse.conf",
]
),
(
RES,
[
"basic_fluctuation.mor",
"basic.mor",
"basic_noise.mor",
"basic_slow.mor",
"invalid_char.mor",
"isolated_noise.mor",
"long_pause.mor",
"morse.json",
"signal_fractions.mor",
]
)
]
]
)