cmdpackage 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cmdpackage-0.1.3.dist-info/METADATA +211 -0
- cmdpackage-0.1.3.dist-info/RECORD +17 -0
- cmdpackage-0.1.3.dist-info/WHEEL +5 -0
- cmdpackage-0.1.3.dist-info/entry_points.txt +2 -0
- cmdpackage-0.1.3.dist-info/licenses/LICENSE +21 -0
- cmdpackage-0.1.3.dist-info/top_level.txt +1 -0
- src/__init__.py +73 -0
- src/defs/__init__.py +0 -0
- src/defs/createzVirtualEnv.py +27 -0
- src/defs/runSubProc.py +10 -0
- src/defs/writeCLIPackage.py +98 -0
- src/defs/writePyProject.py +140 -0
- src/defs/writeSetup.py +124 -0
- src/templates/__init__.py +0 -0
- src/templates/cmdTemplate.py +772 -0
- src/templates/pyprojectTemplate.py +114 -0
- src/templates/setupTemplates.py +113 -0
src/defs/writeSetup.py
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
from ..templates.setupTemplates import (
|
4
|
+
setup_base_template, setup_line, gitignore_content, classifiers_line,
|
5
|
+
classifiers_template)
|
6
|
+
from sys import version_info
|
7
|
+
from .runSubProc import runSubProc
|
8
|
+
from subprocess import Popen, PIPE
|
9
|
+
from getpass import getuser
|
10
|
+
import os
|
11
|
+
|
12
|
+
def writeSetup() -> dict:
|
13
|
+
rtnDict = {}
|
14
|
+
fields = ['name', 'version', 'description', 'license', 'author']
|
15
|
+
setup_lines = ''
|
16
|
+
|
17
|
+
for field_name in fields:
|
18
|
+
default_value = default_values(field_name)
|
19
|
+
if field_name == 'description':
|
20
|
+
default_value = default_value.replace('name', rtnDict['name'])
|
21
|
+
input_msg = input_message(field_name, default_value)
|
22
|
+
input_value = get_input(input_msg, default=default_value)
|
23
|
+
rtnDict[field_name] = input_value
|
24
|
+
setup_lines += setup_line.substitute(
|
25
|
+
name=field_name, value=input_value
|
26
|
+
)
|
27
|
+
|
28
|
+
setup_content = setup_base_template.substitute(
|
29
|
+
setup_lines=setup_lines,
|
30
|
+
name=rtnDict['name'],
|
31
|
+
classifiers=gen_classifiers()
|
32
|
+
)
|
33
|
+
|
34
|
+
with open('setup.py', 'w') as setup_file:
|
35
|
+
write_content(setup_file, setup_content)
|
36
|
+
|
37
|
+
with_gitignore = get_input('commit a git repo [Y/n]?: ',
|
38
|
+
default='y')
|
39
|
+
if with_gitignore.lower() == 'y':
|
40
|
+
with open('.gitignore', 'w') as gitignore_file:
|
41
|
+
write_content(gitignore_file, gitignore_content)
|
42
|
+
initGitRepo()
|
43
|
+
return rtnDict
|
44
|
+
|
45
|
+
def input_message(field_name, default_value):
|
46
|
+
return u'{} ({}): '.format(field_name, default_value)
|
47
|
+
|
48
|
+
|
49
|
+
def gen_classifiers():
|
50
|
+
mayor, minor = version_info[:2]
|
51
|
+
python = "Programming Language :: Python"
|
52
|
+
local = "Programming Language :: Python :: {}.{}".format(mayor, minor)
|
53
|
+
classifiers = [python, local]
|
54
|
+
|
55
|
+
classifiers_lines = ''
|
56
|
+
for cls in classifiers:
|
57
|
+
classifiers_lines += classifiers_line.substitute(classifier=cls)
|
58
|
+
|
59
|
+
return classifiers_template.substitute(classifiers=classifiers_lines)
|
60
|
+
|
61
|
+
def initGitRepo():
|
62
|
+
rtnStr = runSubProc('ls .git')
|
63
|
+
if rtnStr.returncode != 0:
|
64
|
+
rtnStr = runSubProc(f'git init')
|
65
|
+
if rtnStr.returncode == 0:
|
66
|
+
rtnStr = runSubProc(f'git add .')
|
67
|
+
if rtnStr.returncode == 0:
|
68
|
+
rtnStr = runSubProc(f'git commit -m "inital commit"',noOutput=False)
|
69
|
+
|
70
|
+
def get_username():
|
71
|
+
'''Get git config values.'''
|
72
|
+
username = ''
|
73
|
+
|
74
|
+
# use try-catch to prevent crashes if user doesn't install git
|
75
|
+
try:
|
76
|
+
# run git config --global <key> to get username
|
77
|
+
git_command = ['git', 'config', '--global', 'user.name']
|
78
|
+
p = Popen(git_command, stdout=PIPE, stderr=PIPE)
|
79
|
+
output, err = p.communicate()
|
80
|
+
|
81
|
+
# turn stdout into unicode and strip it
|
82
|
+
username = output.decode('utf-8').strip()
|
83
|
+
|
84
|
+
# if user doesn't set global git config name, then use getuser()
|
85
|
+
if not username:
|
86
|
+
username = getuser()
|
87
|
+
except OSError:
|
88
|
+
# if git command is not found, then use getuser()
|
89
|
+
username = getuser()
|
90
|
+
|
91
|
+
return username
|
92
|
+
|
93
|
+
|
94
|
+
def default_values(field_name):
|
95
|
+
if field_name == 'name':
|
96
|
+
rtnStr = os.path.relpath('.', '..')
|
97
|
+
rtnStr = rtnStr.replace("-","_")
|
98
|
+
return rtnStr
|
99
|
+
if field_name == 'version':
|
100
|
+
return '0.1.0'
|
101
|
+
elif field_name == 'description':
|
102
|
+
return 'name pip package'
|
103
|
+
elif field_name == 'license':
|
104
|
+
return 'MIT'
|
105
|
+
elif field_name == 'author':
|
106
|
+
return get_username()
|
107
|
+
|
108
|
+
|
109
|
+
def get_input(input_msg, default=None):
|
110
|
+
if version_info >= (3, 0):
|
111
|
+
input_value = input(input_msg)
|
112
|
+
else:
|
113
|
+
input_value = raw_input(input_msg.encode('utf8')).decode('utf8')
|
114
|
+
|
115
|
+
if input_value == '':
|
116
|
+
return default
|
117
|
+
return input_value
|
118
|
+
|
119
|
+
|
120
|
+
def write_content(file, content):
|
121
|
+
if version_info >= (3, 0):
|
122
|
+
file.write(content)
|
123
|
+
else:
|
124
|
+
file.write(content.encode('utf8'))
|
File without changes
|