Skip to content

Instantly share code, notes, and snippets.

@bollwyvl
Forked from tonyfast/requirements-df.ipynb
Last active December 26, 2020 18:53
Show Gist options
  • Save bollwyvl/49908a428b4fee21bcf591bc86aa81a1 to your computer and use it in GitHub Desktop.
Save bollwyvl/49908a428b4fee21bcf591bc86aa81a1 to your computer and use it in GitHub Desktop.
.ipynb_checkpoints
__pycache__
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
name: reqs
channels:
- conda-forge
- nodefaults
dependencies:
- importlib_metadata
- importnb
- ipyelk
- ipywidgets
- jupyterlab =1
- nodejs >=14,<15
- nomkl
- packaging
- pandas
- python >=3.8,<3.9
- toolz
@jupyrdf/jupyter-elk
@jupyter-widgets/jupyterlab-manager
#!/usr/bin/env bash
set -eux
jupyter labextension install --debug --no-build $(cat labex.txt)
jupyter labextension list
jupyter lab build --debug --dev-build=False --minimize=False
jupyter labextension list
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [],
"source": [
"import importlib_metadata, packaging.requirements, pandas\n",
"from toolz.curried import *"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [],
"source": [
"s = pandas.Series(importlib_metadata.distributions())"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"d =s.iloc[0]"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"six 21\n",
"requests 19\n",
"numpy 17\n",
"attrs 15\n",
"setuptools 15\n",
" ..\n",
"pickleshare 1\n",
"argcomplete 1\n",
"sphinx-panels 1\n",
"sphinxcontrib-jsmath 1\n",
"yarl 1\n",
"Name: requirement, Length: 233, dtype: int64"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reqs = s.apply(\n",
" compose_left(\n",
" operator.attrgetter(\"name\",\"requires\"), \n",
" pandas.Series\n",
" )\n",
").rename(\n",
" columns=dict(\n",
" zip(range(2), \"name requires\".split())\n",
" )\n",
").set_index(\"name\").requires.apply(\n",
" pandas.Series\n",
").stack().apply(\n",
" packaging.requirements.Requirement\n",
").reset_index(-1, drop=True).apply(\n",
" compose_left(vars, pandas.Series)\n",
").rename(columns=dict(name=\"requirement\"))\n",
"\n",
"df = reqs[reqs.marker.isna()]\n",
"\n",
"df[['requirement']].reset_index().drop_duplicates()['requirement'].value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>requirement</th>\n",
" <th>url</th>\n",
" <th>extras</th>\n",
" <th>specifier</th>\n",
" <th>marker</th>\n",
" </tr>\n",
" <tr>\n",
" <th>name</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>ruamel.yaml</th>\n",
" <td>ruamel.yaml.clib</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>(&gt;=0.1.2)</td>\n",
" <td>platform_python_implementation == \"CPython\" an...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ruamel.yaml</th>\n",
" <td>ruamel.ordereddict</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>()</td>\n",
" <td>platform_python_implementation == \"CPython\" an...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ruamel.yaml</th>\n",
" <td>ryd</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>()</td>\n",
" <td>extra == \"docs\"</td>\n",
" </tr>\n",
" <tr>\n",
" <th>ruamel.yaml</th>\n",
" <td>ruamel.yaml.jinja2</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>(&gt;=0.2)</td>\n",
" <td>extra == \"jinja2\"</td>\n",
" </tr>\n",
" <tr>\n",
" <th>graphviz</th>\n",
" <td>tox</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>(&gt;=3)</td>\n",
" <td>extra == \"dev\"</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>libcst</th>\n",
" <td>tox</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>(&gt;=3.18.1)</td>\n",
" <td>extra == \"dev\"</td>\n",
" </tr>\n",
" <tr>\n",
" <th>typing-inspect</th>\n",
" <td>mypy-extensions</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>(&gt;=0.3.0)</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>typing-inspect</th>\n",
" <td>typing-extensions</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>(&gt;=3.7.4)</td>\n",
" <td>None</td>\n",
" </tr>\n",
" <tr>\n",
" <th>typing-inspect</th>\n",
" <td>typing</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>(&gt;=3.7.4)</td>\n",
" <td>python_version &lt; \"3.5\"</td>\n",
" </tr>\n",
" <tr>\n",
" <th>importnb</th>\n",
" <td>importlib_resources</td>\n",
" <td>None</td>\n",
" <td>{}</td>\n",
" <td>()</td>\n",
" <td>python_version &lt; \"3.7\"</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>2384 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" requirement url extras specifier \\\n",
"name \n",
"ruamel.yaml ruamel.yaml.clib None {} (>=0.1.2) \n",
"ruamel.yaml ruamel.ordereddict None {} () \n",
"ruamel.yaml ryd None {} () \n",
"ruamel.yaml ruamel.yaml.jinja2 None {} (>=0.2) \n",
"graphviz tox None {} (>=3) \n",
"... ... ... ... ... \n",
"libcst tox None {} (>=3.18.1) \n",
"typing-inspect mypy-extensions None {} (>=0.3.0) \n",
"typing-inspect typing-extensions None {} (>=3.7.4) \n",
"typing-inspect typing None {} (>=3.7.4) \n",
"importnb importlib_resources None {} () \n",
"\n",
" marker \n",
"name \n",
"ruamel.yaml platform_python_implementation == \"CPython\" an... \n",
"ruamel.yaml platform_python_implementation == \"CPython\" an... \n",
"ruamel.yaml extra == \"docs\" \n",
"ruamel.yaml extra == \"jinja2\" \n",
"graphviz extra == \"dev\" \n",
"... ... \n",
"libcst extra == \"dev\" \n",
"typing-inspect None \n",
"typing-inspect None \n",
"typing-inspect python_version < \"3.5\" \n",
"importnb python_version < \"3.7\" \n",
"\n",
"[2384 rows x 5 columns]"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"reqs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" !gh gist create "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment