{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "_TEMPLATE_ | MODULE",
      "provenance": [],
      "collapsed_sections": [],
      "mount_file_id": "1KoaEnA3OOEGX0wGjKs5S3crr1nCFneBO",
      "authorship_tag": "ABX9TyPAvsQDp+fTvUIsx1RQPODT",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/RecoHut-Projects/recohut/blob/master/templates/_template_module.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "x4ajUYTJZySO"
      },
      "source": [
        "### Header"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "LN9hHVN5Vdx7"
      },
      "source": [
        "!pip install nbdev\n",
        "!pip install twine"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "-A8Czlx2XXcK"
      },
      "source": [
        "import os\n",
        "project_name = \"recohut\"; branch = \"master\"; account = \"RecoHut-Projects\"\n",
        "project_path = os.path.join('/content', project_name)\n",
        "if not os.path.exists(project_path):\n",
        "    !apt-get -qq install tree\n",
        "    !cp -r /content/drive/MyDrive/git_credentials/. ~\n",
        "    !cp -r /content/drive/MyDrive/pypi_credentials/. ~\n",
        "    path = \"/content/\" + project_name; \n",
        "    !mkdir \"{path}\"\n",
        "    %cd \"{path}\"\n",
        "    !git init\n",
        "    !git remote add origin https://github.com/\"{account}\"/\"{project_name}\".git\n",
        "    !git pull origin \"{branch}\"\n",
        "    !git checkout \"{branch}\"\n",
        "else:\n",
        "    %cd \"{project_path}\""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "7kfKDggqdlZZ"
      },
      "source": [
        "!pip install -e ."
      ],
      "execution_count": 15,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VozsTTUxXtXP"
      },
      "source": [
        "!nbdev_install_git_hooks"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "p9zzF41OXXcK"
      },
      "source": [
        "!git status"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "YH70H00TYcYs"
      },
      "source": [
        "!git add .\n",
        "!git commit -m 'commit'\n",
        "!git pull --rebase origin \"{branch}\""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "TMDNLdvdXXcL"
      },
      "source": [
        "!git push origin \"{branch}\""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kpO8LH3UaJ81"
      },
      "source": [
        "---"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "78JePL5LcXIR"
      },
      "source": [
        "### Predev"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "tOKNHPSycXF3"
      },
      "source": [
        "# default_exp core"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "bW5RFfjKcp18"
      },
      "source": [
        "# Title\n",
        "> description"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vK4l_F5hcpzo"
      },
      "source": [
        "#hide\n",
        "from nbdev.showdoc import *"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "e3FaWJmGcpxK"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kpm_FFxhcXmy"
      },
      "source": [
        "---"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "jj8fwSHwa0UE"
      },
      "source": [
        "### Dev"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_Zi-6sZeVQJP"
      },
      "source": [
        "#export\n",
        "def print_to_json(data, sort_keys=True):\n",
        "    \"\"\"convert dictionary object into json string for pretty printing.\n",
        "\n",
        "    Args:\n",
        "        data (dict): dictionary that you want to be printed in json\n",
        "        sort_keys (bool, optional): sorts the dictionary keys, if true (default = True)\n",
        "    \n",
        "    Returns:\n",
        "        new_data (str): the json formatted string of the given dictionary\n",
        "    \n",
        "    Examples:\n",
        "    >>> pretty_out = print_to_json({'a':1,'b':2})\n",
        "    >>> print(pretty_out)\n",
        "    {\n",
        "        \"a\": \"1\",\n",
        "        \"b\": \"2\"\n",
        "    }\n",
        "    \"\"\"\n",
        "    new_data = dict((k, str(v)) for k, v in data.items())\n",
        "    if sort_keys:\n",
        "        new_data = OrderedDict(sorted(new_data.items(), key=lambda x: x[0]))\n",
        "    return json.dumps(new_data, indent=4)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "iD491idpbo2-"
      },
      "source": [
        "---"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HZtUYt2YbnZE"
      },
      "source": [
        "### Postdev"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "CrfviynvSq0O"
      },
      "source": [
        "Assertions"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "DRzMGuqdSses"
      },
      "source": [
        "METHOD = input('Preprocessing method (info/org/days_test/slice):') or 'slice'\n",
        "assert(METHOD in 'info/org/days_test/slice'.split('/')), 'Invalid Preprocessing method.'"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hm-0BjOkXYI_"
      },
      "source": [
        "Runs"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "GbTFeIM1W47q",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "ba42dfab-950a-4cda-c6d9-5c655db32805"
      },
      "source": [
        "print(print_to_json({'a':1,'b':2}))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "{\n",
            "    \"a\": \"1\",\n",
            "    \"b\": \"2\"\n",
            "}\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TYK31S4jXKvb"
      },
      "source": [
        "Doctest"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "2A47SCPTXgc1"
      },
      "source": [
        "import doctest"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "OiPlWdGUXMKk"
      },
      "source": [
        "doctest.run_docstring_examples(print_to_json, globals())"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AVs5Qzc9iS_I"
      },
      "source": [
        "Unit Test"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "aANOhgBbO3z0"
      },
      "source": [
        "import unittest"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "_Kgd6cGpdm7K"
      },
      "source": [
        "class TestConfigurator(unittest.TestCase):\n",
        "    def setUp(self):\n",
        "        pass\n",
        "            \n",
        "    def testListValue(self):\n",
        "        self.assertEqual(self.conf_mlp[\"layers\"], [32, 64, 1])"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "u5GqvhVSfft8"
      },
      "source": [
        "unittest.main(argv=[''], verbosity=2, exit=False)"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "AYgTvULQZ9EJ"
      },
      "source": [
        "---"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cnfOT39pZvlI"
      },
      "source": [
        "### Footer"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "V2w4XrB5ahHu"
      },
      "source": [
        "!nbdev_build_lib && nbdev_clean_nbs && nbdev_build_docs"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "CfntIajqiab9"
      },
      "source": [
        "# !make pypi\n",
        "# !make release"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "mgj9m4kMZ9EK"
      },
      "source": [
        "!tree -h --du ."
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "VE1SQdzxZ9EK"
      },
      "source": [
        "!pip install -q watermark\n",
        "%reload_ext watermark\n",
        "%watermark -a \"Sparsh A.\" -m -iv -u -t -d"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YE2WsooxZ9EL"
      },
      "source": [
        "---"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nruM7u76Z9EL"
      },
      "source": [
        "**END**"
      ]
    }
  ]
}