-
Notifications
You must be signed in to change notification settings - Fork 83
/
pipenv.lua
165 lines (145 loc) · 4.06 KB
/
pipenv.lua
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
local matchers = require("matchers")
local w = require("tables").wrap
local parser = clink.arg.new_parser
local function pipenv_libs_list(token)
local result = ""
local handle = io.popen('2>nul python -c "import sys; print(\\";\\".join(sys.path))"')
if handle then
result = handle:read("*a")
handle:close()
end
-- trim spaces
result = clink.get_cwd() .. result:gsub("^%s*(.-)%s*$", "%1")
local lib_paths = clink.split(result, ";")
local list = w()
for _,lib_path in ipairs(lib_paths) do
lib_path = lib_path .. "\\"
local finder = matchers.create_files_matcher(lib_path .. "*")
local libs = finder(token)
for _,v in ipairs(libs) do
local ext = path.getextension(v):lower()
if ext == ".py" then
v = v:sub(1, #v - #ext)
table.insert(list, v)
elseif ext == ".dist-info" then
if clink.is_dir(lib_path .. "/" .. v) then
local tmp = v:sub(1, #v - #ext)
if tmp:match("%-%d[%d%.]+$") then
v = tmp:gsub("%-%d[%d%.]+$", "")
table.insert(list, v)
end
end
end
end
end
return list
end
local pipenv_default_flags = {
"--python",
"--three",
"--two",
"--clear",
"--verbose",
"-v",
"--pypi-mirror",
"--help",
"-h"
}
local pipenv_check_parser = parser():add_flags(pipenv_default_flags, "--unused", "--ignore", "-i", "--system"):loop(1)
local pipenv_clean_parser = parser():add_flags(pipenv_default_flags, "--bare", "--dry-run")
local pipenv_graph_parser = parser():add_flags(pipenv_default_flags, "--bare", "--json", "--json-tree", "--reverse")
local pipenv_install_parser =
parser():add_flags(
pipenv_default_flags,
"--system",
"--code",
"-c",
"--deploy",
"--skip-lock",
"--editable",
"-e",
"--ignore-pipfile",
"--selective-upgrade",
"--pre",
"--requirements" .. parser({clink.matches_are_files}),
"-r" .. parser({clink.matches_are_files}),
"--extra-index-url",
"--index",
"-i",
"--sequential",
"--keep-outdated",
"--dev",
"-d"
):loop(1)
local pipenv_lock_parser =
parser():add_flags(pipenv_default_flags, "--requirements", "-r", "--keep-outdated", "--pre", "--dev", "-d")
local pipenv_open_parser = parser({pipenv_libs_list}):add_flags(pipenv_default_flags)
local pipenv_run_parser = parser():add_flags(pipenv_default_flags)
local pipenv_shell_parser = parser():add_flags("--fancy", "--anyway", pipenv_default_flags)
local pipenv_sync_parser =
parser():add_flags("--bare", "--sequential", "--keep-outdated", "--pre", "--dev", "-d", pipenv_default_flags)
local pipenv_uninstall_parser =
parser():add_flags(
"--skip-lock",
"--lock",
"--all-dev",
"--all",
"--editable",
"-e",
"--keep-outdated",
"--pre",
"--dev",
"-d",
pipenv_default_flags
)
local pipenv_update_parser =
parser():add_flags(
"--bare",
"--outdated",
"--dry-run",
"--editable",
"-e",
"--ignore-pipfile",
"--selective-upgrade",
"--pre",
"--requirements",
"-r",
"--extra-index-url",
"--index",
"-i",
"--sequential",
"--keep-outdated",
"--dev",
"-d",
pipenv_default_flags
)
local pipenv_parser =
parser(
{
"check" .. pipenv_check_parser,
"clean" .. pipenv_clean_parser,
"graph" .. pipenv_graph_parser,
"install" .. pipenv_install_parser,
"lock" .. pipenv_lock_parser,
"open" .. pipenv_open_parser,
"run" .. pipenv_run_parser,
"shell" .. pipenv_shell_parser,
"sync" .. pipenv_sync_parser,
"uninstall" .. pipenv_uninstall_parser,
"update" .. pipenv_update_parser
}
):add_flags(
pipenv_default_flags,
"--where",
"--venv",
"--py",
"--envs",
"--rm",
"--bare",
"--completion",
"--man",
"--support",
"--site-packages",
"--version"
)
clink.arg.register_parser("pipenv", pipenv_parser)