-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpystdlib.nimble
More file actions
151 lines (123 loc) · 3.81 KB
/
pystdlib.nimble
File metadata and controls
151 lines (123 loc) · 3.81 KB
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
# Package
version = "0.1.0"
author = "litlighilit"
description = "Python stdlib porting to Nim"
license = "MIT"
srcDir = "src"
# Dependencies
requires "nim > 2.0.8"
var pylibPre = "https://github.com/nimpylib"
let envVal = getEnv("NIMPYLIB_PKGS_BARE_PREFIX")
if envVal != "": pylibPre = ""
#if pylibPre == Def: pylibPre = ""
elif pylibPre[^1] != '/':
pylibPre.add '/'
template pylib(x, ver) =
requires if pylibPre == "": x & ver
else: pylibPre & x
pylib "handy_sugars", " ^= 0.1.0"
pylib "py_version", " ^= 0.1.0"
pylib "pybuiltins", " ^= 0.1.0"
pylib "collections_abc", " ^= 0.1.0"
pylib "py_commontypes", " ^= 0.1.0"
pylib "auditfunc", " ^= 0.1.0"
pylib "pystrbytes_decl", " ^= 0.1.0"
pylib "py_constants", " ^= 0.1.0"
pylib "pystr", " ^= 0.1.0"
pylib "pysimperr", " ^= 0.1.0"
pylib "pyerrors", " ^= 0.1.0"
pylib "pysugar", " ^= 0.1.0"
# pystdlib/test/
pylib "pyops", " ^= 0.1.0"
pylib "py_intfloat", " ^= 0.1.0"
# builtins, sys
pylib "py_sys_stdio", " ^= 0.1.0"
pylib "autoconf_sugars", " ^= 0.1.0"
pylib "jscompat", " ^= 0.1.5"
pylib "pyio_abc", " ^= 0.1.0"
pylib "pyio", " ^= 0.1.0"
pylib "pywarnings", " ^= 0.1.0"
pylib "py_locale_utf8_encoding", " ^= 0.1.0"
pylib "posixos", " ^= 0.1.0"
pylib "grp_pwd", " ^= 0.1.0"
pylib "py_winapi", " ^= 0.1.0"
pylib "pytyping", " ^= 0.1.0"
pylib "pyrandom", " ^= 0.1.0"
pylib "pyshutil", " ^= 0.1.0"
pylib "pytempfile", " ^= 0.1.0"
pylib "pydatetime", " ^= 0.1.0"
pylib "pytime", " ^= 0.1.0"
# Lib/n_os
pylib "posixos", " ^= 0.1.0"
pylib "pyresource", " ^= 0.1.0"
pylib "functools", " ^= 0.1.0"
pylib "pypathlib", " ^= 0.1.0"
pylib "pysignal", " ^= 0.1.0"
pylib "pystat", " ^= 0.1.0"
pylib "pybisect", " ^= 0.1.0"
pylib "pyitertools", " ^= 0.1.0"
pylib "pyunittest", " ^= 0.1.0"
pylib "pycomplex", " ^= 0.1.0"
pylib "errno", " ^= 0.1.0"
pylib "pymath", " ^= 0.1.0"
pylib "pyarray", " ^= 0.1.0"
import std/os
func getArgs(taskName: string): seq[string] =
## cmdargs: 1 2 3 4 5 -> 1 4 3 2 5
var rargs: seq[string]
let argn = paramCount()
for i in countdown(argn, 0):
let arg = paramStr i
if arg == taskName:
break
rargs.add arg
if rargs.len > 1:
swap rargs[^1], rargs[0] # the file must be the last, others' order don't matter
return rargs
template mytask(name: untyped, taskDesc: string, body){.dirty.} =
task name, taskDesc:
let taskName = astToStr(name)
body
template taskWithArgs(name, taskDesc, body){.dirty.} =
mytask name, taskDesc:
var args = getArgs taskName
body
let
libDir = srcDir / "pystdlib"
func getSArg(taskName: string): string = quoteShellCommand getArgs taskName
func handledArgs(args: var seq[string], def_arg: string) =
## makes args: @[option..., arg/"ALL"]
if args.len == 0:
args.add def_arg
return
let lastArg = args[^1]
if lastArg[0] == '-': args.add def_arg
elif lastArg == "ALL": args[^1] = def_arg
# else, the last shall be a nim file
func getHandledArg(taskName: string, def_arg: string): string =
## the last param can be an arg, if given,
##
## def_arg is set as the last element when the last is not arg or is "ALL",
## if no arg, then sets def_arg as the only.
var args = getArgs taskName
args.handledArgs def_arg
result = quoteShellCommand args
const nimSuf = ".nim"
proc testLib(fp: string, sargs: string) =
var cmd = "doc"
if fp.endsWith nimSuf:
if (fp[0..(fp.len - nimSuf.len-1)] & "_impl").dirExists:
cmd.add " --project"
selfExec cmd & " --outdir:docs " & sargs & ' ' & fp
taskWithArgs testLibDoc, "Test doc-gen and runnableExamples, can pass several args":
let def = "ALL"
args.handledArgs def
let fpOrDef = args.pop()
let sargs = quoteShellCommand args
if fpOrDef == def:
for t in walkDir libDir:
if t.kind in {pcDir, pcLinkToDir}: continue
let fp = t.path
testLib fp, sargs
else:
testLib fpOrDef, sargs