Skip to content

Commit dfc7a2d

Browse files
committed
f-string is simpler to read
1 parent 1eb5432 commit dfc7a2d

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

docs/pipdeptree_replacement.ipynb

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,17 @@
101101
"\n",
102102
"\n",
103103
"def pipdownraw(pp, extra=\"\", version_req=\"\", depth=20, path=[]):\n",
104+
" \"\"\"build downward requirements for the package on given extra and depth\"\"\"\n",
104105
" envi = {\"extra\": extra, **environment}\n",
105106
" p = normalize(pp)\n",
106107
" ret_all = []\n",
107108
" if p in path:\n",
108109
" print(\"cycle!\", \"->\".join(path + [p]))\n",
109110
" elif p in distro and len(path) <= depth:\n",
110111
" if extra == \"\":\n",
111-
" ret = [p + \"==\" + distro[p][\"version\"] + \" \" + version_req]\n",
112+
" ret = [f'{p}=={distro[p][\"version\"]} {version_req}']\n",
112113
" else:\n",
113-
" ret = [\n",
114-
" p + \"[\" + extra + \"]\" + \"==\" + distro[p][\"version\"] + \" \" + version_req\n",
115-
" ]\n",
114+
" ret = [f'{p}[{extra}]=={distro[p][\"version\"]} {version_req}']\n",
116115
" for r in distro[p][\"requires_dist\"]:\n",
117116
" if r[\"req_key\"] in distro:\n",
118117
" if \"req_marker\" not in r or Marker(r[\"req_marker\"]).evaluate(\n",
@@ -130,21 +129,17 @@
130129
"\n",
131130
"\n",
132131
"def pipupraw(pp, extra=\"\", version_req=\"\", depth=20, path=[]):\n",
132+
" \"\"\"build upward needs for the package on given extra and depth\"\"\"\n",
133133
" envi = {\"extra\": extra, **environment}\n",
134134
" p = normalize(pp)\n",
135135
" ret_all = []\n",
136136
" if p in path:\n",
137137
" print(\"cycle!\", \"->\".join(path + [p]))\n",
138138
" if p in distro and len(path) <= depth:\n",
139139
" if extra == \"\":\n",
140-
" ret_all = [p + \"==\" + distro[p][\"version\"] + \" \" + version_req]\n",
140+
" ret_all = [f'{p}=={distro[p][\"version\"]} {version_req}']\n",
141141
" else:\n",
142-
" ret_all = [\n",
143-
" p + \"[\" + extra + \"]\" + \"==\" + distro[p][\"version\"] + \" \" + version_req\n",
144-
" ]\n",
145-
" if len(path) > 20:\n",
146-
" print(path)\n",
147-
" z = 1 / 0\n",
142+
" ret_all = [f'{p}[{extra}]=={distro[p][\"version\"]} {version_req}']\n",
148143
" ret = []\n",
149144
" for r in distro[p][\"wanted_per\"]:\n",
150145
" # print(distro[p]['wanted_per'][r]['req,_version'])\n",
@@ -156,11 +151,9 @@
156151
" ret += pipupraw(\n",
157152
" r[\"req_key\"],\n",
158153
" \"\",\n",
159-
" \"[requires: \"\n",
160-
" + p\n",
154+
" f\"[requires: {p}\"\n",
161155
" + (\"[\" + r[\"req_extra\"] + \"]\" if r[\"req_extra\"] != \"\" else \"\")\n",
162-
" + r[\"req_version\"]\n",
163-
" + \"]\",\n",
156+
" + f'{r[\"req_version\"]}]',\n",
164157
" depth,\n",
165158
" path + [p],\n",
166159
" )\n",
@@ -425,18 +418,9 @@
425418
" meta = p['metadata']\n",
426419
" if meta['name'] in list_of_package:\n",
427420
" # print(json.dumps(meta).split(r'\\n'))\n",
428-
" print('\\n'.join(meta['description'].split(r'\\n')))\n",
429-
"\n"
421+
" print('\\n'.join(meta['description'].split(r'\\n')))"
430422
]
431423
},
432-
{
433-
"cell_type": "code",
434-
"execution_count": null,
435-
"id": "4898ad0c-5fbf-47a6-9298-f4f25841c25f",
436-
"metadata": {},
437-
"outputs": [],
438-
"source": []
439-
},
440424
{
441425
"cell_type": "code",
442426
"execution_count": null,

0 commit comments

Comments
 (0)