{ "cells": [ { "cell_type": "markdown", "id": "a4c363ab-22a7-4d1f-b9a5-549fe9005b0f", "metadata": {}, "source": [ "This notebook documents the preparation of making a package." ] }, { "cell_type": "markdown", "id": "b634eb7c-0370-4c7d-b7cb-3b0eaf810633", "metadata": {}, "source": [ "# 1. Collect the Modules" ] }, { "cell_type": "markdown", "id": "1fed1cd6-8e91-4ff0-97f5-7b0be16ab848", "metadata": {}, "source": [ "A package is a collection of modules. As an example, consider the computer literacy automated quiz of last lecture." ] }, { "cell_type": "markdown", "id": "d7c2f983-129a-4a0b-9a35-a191bcea8c66", "metadata": {}, "source": [ "There are two important first steps:\n", "\n", "1. Define a name for the package, here we call it `autoquiz` and then\n", "\n", " 1. make a folder with the name `autoquiz`\n", " \n", " 2. copy all modules for the package into that folder.\n", " \n", "2. Write the initializer module `__init__.py`. This script defines what happens when we do `import autoquiz`." ] }, { "cell_type": "markdown", "id": "59da8f2d-08fd-4e13-90ad-0c88bac2e226", "metadata": {}, "source": [ "We insert the name of the folder `autoquiz` in front of the `path` of the `sys` module so the `import autoquiz` will work." ] }, { "cell_type": "code", "execution_count": 1, "id": "fa37b18b-6cc9-456d-b8e4-8c949d9d1065", "metadata": {}, "outputs": [], "source": [ "from sys import path" ] }, { "cell_type": "code", "execution_count": 2, "id": "c85a1ce1-2f9f-42c9-946a-0818c91c2778", "metadata": {}, "outputs": [], "source": [ "path.insert(0, 'C:\\\\Users\\\\jan\\\\Courses\\\\MCS260\\\\Summer23\\\\Lec25\\\\autoquiz')" ] }, { "cell_type": "code", "execution_count": 3, "id": "0dc15d14-ebb1-49aa-b21f-67c8335ec9c0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['C:\\\\Users\\\\jan\\\\Courses\\\\MCS260\\\\Summer23\\\\Lec25\\\\autoquiz',\n", " 'C:\\\\Users\\\\jan\\\\Courses\\\\MCS260\\\\Summer23\\\\Lec25',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3\\\\python310.zip',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3\\\\DLLs',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3\\\\lib',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3',\n", " '',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3\\\\lib\\\\site-packages',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3\\\\lib\\\\site-packages\\\\win32',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3\\\\lib\\\\site-packages\\\\win32\\\\lib',\n", " 'C:\\\\Users\\\\jan\\\\miniconda3\\\\lib\\\\site-packages\\\\Pythonwin']" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "path" ] }, { "cell_type": "code", "execution_count": 4, "id": "631cef8e-7196-4fcf-a5de-bbbb41157c72", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "welcome to our quiz\n" ] } ], "source": [ "import autoquiz" ] }, { "cell_type": "code", "execution_count": 5, "id": "08724e8d-87dd-4d0d-8c98-987b10f348ae", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Help on package autoquiz:\n", "\n", "NAME\n", " autoquiz - # initialization of autoquiz\n", "\n", "PACKAGE CONTENTS\n", " dialogue\n", " quand\n", " questions\n", " quiz\n", "\n", "FILE\n", " c:\\users\\jan\\courses\\mcs260\\summer23\\lec25\\autoquiz\\__init__.py\n", "\n", "\n" ] } ], "source": [ "help(autoquiz)" ] }, { "cell_type": "markdown", "id": "896f062c-0fab-4700-a6ce-10a0454ce1dc", "metadata": {}, "source": [ "# 2. Write `setup.py` and build." ] }, { "cell_type": "markdown", "id": "2614742c-8cca-43b2-aca7-e9802407829e", "metadata": {}, "source": [ "The next stage consists again in two steps:\n", "\n", "1. Define the script `setup.py`.\n", "\n", "2. Test the script by running `python setup.py build`" ] }, { "cell_type": "markdown", "id": "71629037-e0a0-499c-b9ed-e5fa13d0318f", "metadata": {}, "source": [ "The arguments of the `setup` are\n", "\n", "1. the name and author of the package\n", "\n", "2. a short description\n", "\n", "3. version number\n", "\n", "4. packages and collections of modules\n", "\n", "5. license\n", "\n", "6. platform information" ] }, { "cell_type": "markdown", "id": "455eb11b-206b-4339-a647-dba314d7197b", "metadata": {}, "source": [ "To get information for what to provide as platform information, look at what is in `os.name`." ] }, { "cell_type": "code", "execution_count": 7, "id": "0e139a8c-8a94-4dd6-bd41-30aa45be24d0", "metadata": {}, "outputs": [], "source": [ "import os" ] }, { "cell_type": "code", "execution_count": 8, "id": "a151e679-fb4e-4423-9be4-785cc6a25f76", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'nt'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "os.name" ] }, { "cell_type": "markdown", "id": "2be31b4c-8398-4756-9808-29a8854a2555", "metadata": {}, "source": [ "On Linux and Mac OS X, the `os.name` will return `posix`." ] }, { "cell_type": "markdown", "id": "1bd164aa-8c3c-4e97-b99c-a9c6a35b5f05", "metadata": {}, "source": [ "# 3. Package Folder" ] }, { "cell_type": "markdown", "id": "61caa20b-d3f9-497f-aac2-6e589becacd3", "metadata": {}, "source": [ "The package folder is what will be distributed. This folder contains the followwing:\n", "\n", "1. `src` is the source code\n", "\n", "2. `doc` is the documentation\n", "\n", "3. `setup.py` defines the build instructions\n", "\n", "4. `README` file with information about the software\n", "\n", "5. `lICENSE` contains the original copy of the license." ] }, { "cell_type": "markdown", "id": "e4437ccf-d2bf-4d6f-a158-33a5b9481e49", "metadata": {}, "source": [ "The distribution should be as self contained as possible." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.10" } }, "nbformat": 4, "nbformat_minor": 5 }