-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
92 lines (74 loc) · 2.56 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
#!/usr/bin/env python3
"""
A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
import platform
import subprocess
import os
import re
def get_env_prefix():
"""
Automatically identify os_type information which use for
install path of bash_completion.d
"""
TARGET_BIN_PATH = '/usr/local/bin/'
os_type = platform.system()
cygwin = r'CYGWIN|cygwin'
if os_type == "Linux":
TARGET_COMPLETION_PATH = "/etc/bash_completion.d/"
# Darwin is indicate Mac OS
elif os_type == "Darwin":
proc = subprocess.Popen(
'brew --prefix', shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
brew_prefix = "{0}/etc/bash_completion.d/".format(
stdout.rstrip().decode("utf-8"))
TARGET_COMPLETION_PATH = brew_prefix
# Return true if CYGWIN or cygwin there in os type string
elif re.search(cygwin, os_type):
TARGET_COMPLETION_PATH = '/etc/bash_completion.d/'
TARGET_BIN_PATH = '/usr/bin/'
if not os.path.exists(TARGET_COMPLETION_PATH):
os.makedirs(TARGET_COMPLETION_PATH)
else:
raise ValueError(
'Unknown OS type found. This Operating System is not supported.')
return TARGET_COMPLETION_PATH, TARGET_BIN_PATH
def run_autocomplete():
"""
Run script that Generate file nita autocompletion.
"""
cmd = 'python3 autocomplete'
proc = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
TARGET_COMPLETION_PATH, TARGET_BIN_PATH = get_env_prefix()
run_autocomplete()
# Include data files if those exist
# for that we iterate the folder and append the files
data_files_list = [(TARGET_BIN_PATH, ['nita'])]
for file in os.listdir('bash_completion.d/'):
f1 = 'bash_completion.d/' + file
if os.path.isfile(f1): # skip directories
data_files_list.append((TARGET_COMPLETION_PATH, [f1]))
setup(
name='nita_cli',
version='20.0.0',
description='NITA CLI',
long_description='NITA command line wrapper',
author='Jose Miguel Izquierdo',
author_email='[email protected]',
include_package_data=True,
install_requires=['pyyaml <4, >=3.10', 'jinja2'],
url='',
license=license,
packages=find_packages(exclude=('tests', 'docs')),
data_files=data_files_list,
zip_safe=False
)