From 72b7ed6553c148ad60b2150f61980a5234fcff3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20S=2E=20Dokken?= Date: Tue, 14 Nov 2023 10:13:36 +0100 Subject: [PATCH] Fix tail of factorial file and update output to be that of a system using conda. Also make sure tree is showing the package pre-installation --- lectures/python/packages_and_testing.ipynb | 352 ++++++++++----------- 1 file changed, 175 insertions(+), 177 deletions(-) diff --git a/lectures/python/packages_and_testing.ipynb b/lectures/python/packages_and_testing.ipynb index a943195..5913fcb 100644 --- a/lectures/python/packages_and_testing.ipynb +++ b/lectures/python/packages_and_testing.ipynb @@ -83,7 +83,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 57, "id": "ff72d629", "metadata": {}, "outputs": [ @@ -128,7 +128,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 58, "id": "6b14e491", "metadata": {}, "outputs": [ @@ -138,7 +138,7 @@ "3628800" ] }, - "execution_count": 2, + "execution_count": 58, "metadata": {}, "output_type": "execute_result" } @@ -166,24 +166,25 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 59, "id": "df01bd49", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "['/home/dokken/Documents/UiO-IN3110.github.io/lectures/python',\n", - " '/usr/lib/python38.zip',\n", - " '/usr/lib/python3.8',\n", - " '/usr/lib/python3.8/lib-dynload',\n", + "['/home/dokken/Documents/src/UiO/UiO-IN3110.github.io/lectures/python',\n", + " '/home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python310.zip',\n", + " '/home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10',\n", + " '/home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10/lib-dynload',\n", " '',\n", - " '/home/dokken/.local/lib/python3.8/site-packages',\n", - " '/usr/local/lib/python3.8/dist-packages',\n", - " '/usr/lib/python3/dist-packages']" + " '/home/dokken/.local/lib/python3.10/site-packages',\n", + " '/home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10/site-packages',\n", + " '/home/dokken/Documents/src/UiO/UiO-IN3110.github.io/lectures/python/data/my-package',\n", + " '/home/dokken/Documents/src/UiO/UiO-IN3110.github.io/lectures/python/data/my-package']" ] }, - "execution_count": 3, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -212,7 +213,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 60, "id": "39323d65", "metadata": {}, "outputs": [ @@ -220,6 +221,10 @@ "name": "stdout", "output_type": "stream", "text": [ + "if __name__ == \"__main__\":\n", + " import math\n", + " import sys\n", + "\n", " N = int(sys.argv[1])\n", " print(f\"Testing user defined factorial function for {N=}\")\n", " user_n = factorial(N)\n", @@ -231,12 +236,12 @@ } ], "source": [ - "!tail -n 7 user_factorial.py" + "!tail -n 11 user_factorial.py" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 61, "id": "ca6ba9df", "metadata": {}, "outputs": [ @@ -309,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 62, "id": "ed8c503b", "metadata": {}, "outputs": [ @@ -317,46 +322,22 @@ "name": "stdout", "output_type": "stream", "text": [ - "\u001b[01;34mexamples/my-package\u001b[00m\n", - "├── \u001b[01;34mbuild\u001b[00m\n", - "│   ├── \u001b[01;34mbdist.linux-x86_64\u001b[00m\n", - "│   └── \u001b[01;34mlib\u001b[00m\n", - "│   └── \u001b[01;34mpkg\u001b[00m\n", - "│   ├── analysis.py\n", - "│   ├── __init__.py\n", - "│   └── \u001b[01;34mprinting\u001b[00m\n", - "│   ├── __init__.py\n", - "│   └── printing.py\n", - "├── LICENSE\n", - "├── pyproject.toml\n", - "├── README.md\n", - "├── \u001b[01;34msrc\u001b[00m\n", - "│   ├── \u001b[01;34mpkg\u001b[00m\n", - "│   │   ├── analysis.py\n", - "│   │   ├── __init__.py\n", - "│   │   ├── \u001b[01;34mprinting\u001b[00m\n", - "│   │   │   ├── __init__.py\n", - "│   │   │   ├── printing.py\n", - "│   │   │   └── \u001b[01;34m__pycache__\u001b[00m\n", - "│   │   │   ├── __init__.cpython-38.pyc\n", - "│   │   │   └── printing.cpython-38.pyc\n", - "│   │   └── \u001b[01;34m__pycache__\u001b[00m\n", - "│   │   ├── analysis.cpython-38.pyc\n", - "│   │   └── __init__.cpython-38.pyc\n", - "│   └── \u001b[01;34mpkg.egg-info\u001b[00m\n", - "│   ├── dependency_links.txt\n", - "│   ├── PKG-INFO\n", - "│   ├── requires.txt\n", - "│   ├── SOURCES.txt\n", - "│   └── top_level.txt\n", - "└── \u001b[01;34mtest\u001b[00m\n", - " ├── \u001b[01;34m__pycache__\u001b[00m\n", - " │   ├── test_analysis.cpython-38-pytest-7.1.3.pyc\n", - " │   └── test_printing.cpython-38-pytest-7.1.3.pyc\n", - " ├── test_analysis.py\n", - " └── test_printing.py\n", + "\u001b[01;34mexamples/my-package\u001b[0m\n", + "├── \u001b[00mLICENSE\u001b[0m\n", + "├── \u001b[00mpyproject.toml\u001b[0m\n", + "├── \u001b[00mREADME.md\u001b[0m\n", + "├── \u001b[01;34msrc\u001b[0m\n", + "│   └── \u001b[01;34mpkg\u001b[0m\n", + "│   ├── \u001b[00manalysis.py\u001b[0m\n", + "│   ├── \u001b[00m__init__.py\u001b[0m\n", + "│   └── \u001b[01;34mprinting\u001b[0m\n", + "│   ├── \u001b[00m__init__.py\u001b[0m\n", + "│   └── \u001b[00mprinting.py\u001b[0m\n", + "└── \u001b[01;34mtest\u001b[0m\n", + " ├── \u001b[00mtest_analysis.py\u001b[0m\n", + " └── \u001b[00mtest_printing.py\u001b[0m\n", "\n", - "13 directories, 24 files\n" + "4 directories, 9 files\n" ] } ], @@ -372,7 +353,7 @@ "## Installing a Python package\n", "\n", "One could in theory append the path to a package to the environment variable `PYTHONPATH`.\n", - "However, this is not recommened, as it does not check dependencies and is not portable across systems." + "However, this is not recommened, as it does not check dependencies and is not portable across systems.\n" ] }, { @@ -381,12 +362,12 @@ "metadata": {}, "source": [ "A better option is to reate a `pyproject.toml` file in your package root directory.\n", - "We start by expecting this file" + "We start by expecting this file\n" ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 63, "id": "f3d1a708", "metadata": {}, "outputs": [ @@ -415,7 +396,7 @@ "]\n", "dev = [\n", " \"pdbpp\", \"ipython\"\n", - "]" + "]\n" ] } ], @@ -435,18 +416,19 @@ "### build-system\n", "\n", "Installing a package in Python means taking a set of files, and do some or all of the following options\n", + "\n", "- Compile files from foreign languages (such as C/C++)\n", "- Move files from the current root directory to an appropriate path for the current installation of Python\n", - "We will use [setuptools](https://setuptools.pypa.io/) for this, a common Python packager.\n", + " We will use [setuptools](https://setuptools.pypa.io/) for this, a common Python packager.\n", "\n", "With the file above, we can now call the following.\n", "Pip will always install in the _current Python environment_,\n", - "which may be system-wide (usually requires root permissions), per-user, or in a virtual environment." + "which may be system-wide (usually requires root permissions), per-user, or in a virtual environment.\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "id": "3c31b9e7", "metadata": {}, "outputs": [ @@ -454,19 +436,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "Defaulting to user installation because normal site-packages is not writeable\n", "Processing ./examples/my-package\n", " Installing build dependencies ... \u001b[?25ldone\n", "\u001b[?25h Getting requirements to build wheel ... \u001b[?25ldone\n", "\u001b[?25h Preparing metadata (pyproject.toml) ... \u001b[?25ldone\n", - "\u001b[?25hRequirement already satisfied: numpy>=1.20.0 in /home/dokken/.local/lib/python3.8/site-packages (from pkg==0.1.0) (1.20.1)\n", + "\u001b[?25hRequirement already satisfied: numpy>=1.20.0 in /home/dokken/.local/lib/python3.10/site-packages (from pkg==0.1.0) (1.26.1)\n", "Building wheels for collected packages: pkg\n", " Building wheel for pkg (pyproject.toml) ... \u001b[?25ldone\n", - "\u001b[?25h Created wheel for pkg: filename=pkg-0.1.0-py3-none-any.whl size=3855 sha256=ec8b61658e3c132a99fdce2c5617543f8e8fdb7f9d7f65c5cc4f1e85dae45c7b\n", - " Stored in directory: /home/dokken/.cache/pip/wheels/55/cc/57/3120b08927ab03809b28e441ce1800d832c33b007a8f3fccf4\n", + "\u001b[?25h Created wheel for pkg: filename=pkg-0.1.0-py3-none-any.whl size=3881 sha256=4a38e99084fdf3ea23d9d46ff357efe2aca6ec3d08a63c29f3ce6131fdaa89da\n", + " Stored in directory: /home/dokken/.cache/pip/wheels/e7/be/ae/c7a1fe811e9515c9b17aa8a901178b4faa716117ff2d3aab87\n", "Successfully built pkg\n", "Installing collected packages: pkg\n", - "Successfully installed pkg-0.1.0\n" + "Successfully installed pkg-0.1.0\n", + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.1\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" ] } ], @@ -479,12 +463,12 @@ "id": "34c1dcf4", "metadata": {}, "source": [ - "We can check where the package now is located by calling" + "We can check where the package now is located by calling\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "id": "b43920e8", "metadata": {}, "outputs": [ @@ -492,7 +476,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['/home/dokken/.local/lib/python3.8/site-packages/pkg']\n" + "['/home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10/site-packages/pkg']\n" ] } ], @@ -506,12 +490,13 @@ "metadata": {}, "source": [ "## Editable installation\n", - "As we have seen in the scripts above, the files are copied from the current location to the another place on disk specific to the Python installation. With rapid development, this would be a time-consuming and annoying task. Therefore, one can use [editable installations](https://setuptools.pypa.io/en/latest/userguide/development_mode.html) that creates special `.pth` file in the Python-installations site package, that extends the Python-path to the package directory. This means that one do not have to re-install the package to reflect changes" + "\n", + "As we have seen in the scripts above, the files are copied from the current location to the another place on disk specific to the Python installation. With rapid development, this would be a time-consuming and annoying task. Therefore, one can use [editable installations](https://setuptools.pypa.io/en/latest/userguide/development_mode.html) that creates special `.pth` file in the Python-installations site package, that extends the Python-path to the package directory. This means that one do not have to re-install the package to reflect changes\n" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 66, "id": "aa29027d", "metadata": {}, "outputs": [ @@ -522,23 +507,25 @@ "Found existing installation: pkg 0.1.0\n", "Uninstalling pkg-0.1.0:\n", " Successfully uninstalled pkg-0.1.0\n", - "Using pip 23.3.1 from /home/dokken/.local/lib/python3.8/site-packages/pip (python 3.8)\n", - "Defaulting to user installation because normal site-packages is not writeable\n", - "Obtaining file:///home/dokken/Documents/UiO-IN3110.github.io/lectures/python/examples/my-package\n", + "Using pip 23.1.2 from /home/dokken/.local/lib/python3.10/site-packages/pip (python 3.10)\n", + "Obtaining file:///home/dokken/Documents/src/UiO/UiO-IN3110.github.io/lectures/python/examples/my-package\n", " Installing build dependencies ... \u001b[?25l Running command pip subprocess to install build dependencies\n", " Collecting setuptools>=64.4.0\n", - " Using cached setuptools-68.2.2-py3-none-any.whl.metadata (6.3 kB)\n", + " Using cached setuptools-68.2.2-py3-none-any.whl (807 kB)\n", " Collecting wheel\n", - " Using cached wheel-0.41.3-py3-none-any.whl.metadata (2.2 kB)\n", + " Using cached wheel-0.41.3-py3-none-any.whl (65 kB)\n", " Collecting pip>=22.3\n", - " Using cached pip-23.3.1-py3-none-any.whl.metadata (3.5 kB)\n", - " Using cached setuptools-68.2.2-py3-none-any.whl (807 kB)\n", - " Using cached wheel-0.41.3-py3-none-any.whl (65 kB)\n", - " Using cached pip-23.3.1-py3-none-any.whl (2.1 MB)\n", + " Using cached pip-23.3.1-py3-none-any.whl (2.1 MB)\n", " Installing collected packages: wheel, setuptools, pip\n", " ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n", - " launchpadlib 1.10.13 requires testresources, which is not installed.\n", + " tensorboard 2.11.1 requires markdown>=2.6.8, which is not installed.\n", + " tensorboard 2.11.1 requires protobuf<4,>=3.9.2, which is not installed.\n", + " tensorflow 2.11.0 requires protobuf<3.20,>=3.9.2, which is not installed.\n", + " numba 0.56.4 requires numpy<1.24,>=1.18, but you have numpy 1.26.1 which is incompatible.\n", " Successfully installed pip-23.3.1 setuptools-68.2.2 wheel-0.41.3\n", + "\n", + " [notice] A new release of pip is available: 23.1.2 -> 23.3.1\n", + " [notice] To update, run: pip install --upgrade pip\n", "\u001b[?25hdone\n", " Checking if build backend supports build_editable ... \u001b[?25l Running command Checking if build backend supports build_editable\n", "\u001b[?25hdone\n", @@ -554,43 +541,43 @@ "\u001b[?25hdone\n", " Preparing editable metadata (pyproject.toml) ... \u001b[?25l Running command Preparing editable metadata (pyproject.toml)\n", " running dist_info\n", - " creating /tmp/pip-modern-metadata-wural_uh/pkg.egg-info\n", - " writing /tmp/pip-modern-metadata-wural_uh/pkg.egg-info/PKG-INFO\n", - " writing dependency_links to /tmp/pip-modern-metadata-wural_uh/pkg.egg-info/dependency_links.txt\n", - " writing requirements to /tmp/pip-modern-metadata-wural_uh/pkg.egg-info/requires.txt\n", - " writing top-level names to /tmp/pip-modern-metadata-wural_uh/pkg.egg-info/top_level.txt\n", - " writing manifest file '/tmp/pip-modern-metadata-wural_uh/pkg.egg-info/SOURCES.txt'\n", - " reading manifest file '/tmp/pip-modern-metadata-wural_uh/pkg.egg-info/SOURCES.txt'\n", + " creating /tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info\n", + " writing /tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info/PKG-INFO\n", + " writing dependency_links to /tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info/dependency_links.txt\n", + " writing requirements to /tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info/requires.txt\n", + " writing top-level names to /tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info/top_level.txt\n", + " writing manifest file '/tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info/SOURCES.txt'\n", + " reading manifest file '/tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info/SOURCES.txt'\n", " adding license file 'LICENSE'\n", - " writing manifest file '/tmp/pip-modern-metadata-wural_uh/pkg.egg-info/SOURCES.txt'\n", - " creating '/tmp/pip-modern-metadata-wural_uh/pkg-0.1.0.dist-info'\n", + " writing manifest file '/tmp/pip-modern-metadata-ckzb6ip2/pkg.egg-info/SOURCES.txt'\n", + " creating '/tmp/pip-modern-metadata-ckzb6ip2/pkg-0.1.0.dist-info'\n", "\u001b[?25hdone\n", - "Requirement already satisfied: numpy>=1.20.0 in /home/dokken/.local/lib/python3.8/site-packages (from pkg==0.1.0) (1.20.1)\n", + "Requirement already satisfied: numpy>=1.20.0 in /home/dokken/.local/lib/python3.10/site-packages (from pkg==0.1.0) (1.26.1)\n", "Building wheels for collected packages: pkg\n", " Building editable for pkg (pyproject.toml) ... \u001b[?25l Running command Building editable for pkg (pyproject.toml)\n", " running editable_wheel\n", - " creating /tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info\n", - " writing /tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info/PKG-INFO\n", - " writing dependency_links to /tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info/dependency_links.txt\n", - " writing requirements to /tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info/requires.txt\n", - " writing top-level names to /tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info/top_level.txt\n", - " writing manifest file '/tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info/SOURCES.txt'\n", - " reading manifest file '/tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info/SOURCES.txt'\n", + " creating /tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info\n", + " writing /tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info/PKG-INFO\n", + " writing dependency_links to /tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info/dependency_links.txt\n", + " writing requirements to /tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info/requires.txt\n", + " writing top-level names to /tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info/top_level.txt\n", + " writing manifest file '/tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info/SOURCES.txt'\n", + " reading manifest file '/tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info/SOURCES.txt'\n", " adding license file 'LICENSE'\n", - " writing manifest file '/tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg.egg-info/SOURCES.txt'\n", - " creating '/tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg-0.1.0.dist-info'\n", - " creating /tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg-0.1.0.dist-info/WHEEL\n", + " writing manifest file '/tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg.egg-info/SOURCES.txt'\n", + " creating '/tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg-0.1.0.dist-info'\n", + " creating /tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg-0.1.0.dist-info/WHEEL\n", " running build_py\n", " running egg_info\n", - " creating /tmp/tmpdtdwdg4k.build-temp/pkg.egg-info\n", - " writing /tmp/tmpdtdwdg4k.build-temp/pkg.egg-info/PKG-INFO\n", - " writing dependency_links to /tmp/tmpdtdwdg4k.build-temp/pkg.egg-info/dependency_links.txt\n", - " writing requirements to /tmp/tmpdtdwdg4k.build-temp/pkg.egg-info/requires.txt\n", - " writing top-level names to /tmp/tmpdtdwdg4k.build-temp/pkg.egg-info/top_level.txt\n", - " writing manifest file '/tmp/tmpdtdwdg4k.build-temp/pkg.egg-info/SOURCES.txt'\n", - " reading manifest file '/tmp/tmpdtdwdg4k.build-temp/pkg.egg-info/SOURCES.txt'\n", + " creating /tmp/tmpxgpioiwc.build-temp/pkg.egg-info\n", + " writing /tmp/tmpxgpioiwc.build-temp/pkg.egg-info/PKG-INFO\n", + " writing dependency_links to /tmp/tmpxgpioiwc.build-temp/pkg.egg-info/dependency_links.txt\n", + " writing requirements to /tmp/tmpxgpioiwc.build-temp/pkg.egg-info/requires.txt\n", + " writing top-level names to /tmp/tmpxgpioiwc.build-temp/pkg.egg-info/top_level.txt\n", + " writing manifest file '/tmp/tmpxgpioiwc.build-temp/pkg.egg-info/SOURCES.txt'\n", + " reading manifest file '/tmp/tmpxgpioiwc.build-temp/pkg.egg-info/SOURCES.txt'\n", " adding license file 'LICENSE'\n", - " writing manifest file '/tmp/tmpdtdwdg4k.build-temp/pkg.egg-info/SOURCES.txt'\n", + " writing manifest file '/tmp/tmpxgpioiwc.build-temp/pkg.egg-info/SOURCES.txt'\n", "\n", " Editable install will be performed using .pth file to extend `sys.path` with:\n", " ['src']\n", @@ -599,18 +586,21 @@ " `packages.find.exclude/include` may have no effect.\n", "\n", " adding '__editable__.pkg-0.1.0.pth'\n", - " creating '/tmp/pip-wheel-dmzh2cwp/.tmp-zhoqa4rs/pkg-0.1.0-0.editable-py3-none-any.whl' and adding '/tmp/tmpey6_0u3npkg-0.1.0-0.editable-py3-none-any.whl' to it\n", + " creating '/tmp/pip-wheel-d2tjy3ki/.tmp-9syep96b/pkg-0.1.0-0.editable-py3-none-any.whl' and adding '/tmp/tmpl7nuej9ppkg-0.1.0-0.editable-py3-none-any.whl' to it\n", " adding 'pkg-0.1.0.dist-info/LICENSE'\n", " adding 'pkg-0.1.0.dist-info/METADATA'\n", " adding 'pkg-0.1.0.dist-info/WHEEL'\n", " adding 'pkg-0.1.0.dist-info/top_level.txt'\n", " adding 'pkg-0.1.0.dist-info/RECORD'\n", "\u001b[?25hdone\n", - " Created wheel for pkg: filename=pkg-0.1.0-0.editable-py3-none-any.whl size=2827 sha256=bd04f696dbc3665fddf202128263cd9782f4472fb2f97cdcf061e6b8e78c5b1e\n", - " Stored in directory: /tmp/pip-ephem-wheel-cache-hvb7ac6k/wheels/55/cc/57/3120b08927ab03809b28e441ce1800d832c33b007a8f3fccf4\n", + " Created wheel for pkg: filename=pkg-0.1.0-0.editable-py3-none-any.whl size=2854 sha256=369cc98d72e82f2aa28a6bed58a6836e4f47328788679836e8c916cfd51ea238\n", + " Stored in directory: /tmp/pip-ephem-wheel-cache-2456l8n7/wheels/e7/be/ae/c7a1fe811e9515c9b17aa8a901178b4faa716117ff2d3aab87\n", "Successfully built pkg\n", "Installing collected packages: pkg\n", - "Successfully installed pkg-0.1.0\n" + "Successfully installed pkg-0.1.0\n", + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.1\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" ] } ], @@ -621,7 +611,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 67, "id": "8affa78c", "metadata": {}, "outputs": [ @@ -629,7 +619,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "['/home/dokken/Documents/UiO-IN3110.github.io/lectures/python/examples/my-package/src/pkg']\n" + "['/home/dokken/Documents/src/UiO/UiO-IN3110.github.io/lectures/python/examples/my-package/src/pkg']\n" ] } ], @@ -642,12 +632,12 @@ "id": "5ead5f4a", "metadata": {}, "source": [ - "# Project specification" + "# Project specification\n" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 68, "id": "d6b90116", "metadata": {}, "outputs": [ @@ -679,11 +669,13 @@ "metadata": {}, "source": [ "### Package name\n", + "\n", "As seen in the file above, we observe that we do not need to specify alot in the project description.\n", "We give the package a name, which should be reflected in `/src/pkg`. We use the source layout as it avoids some issues with a flat package structure, see [Python packaging guide](https://packaging.python.org/en/latest/discussions/src-layout-vs-flat-layout/) for more details.\n", "\n", "### Author list\n", - "We create a list of authors with their name and email." + "\n", + "We create a list of authors with their name and email.\n" ] }, { @@ -702,7 +694,7 @@ "source": [ "### README\n", "\n", - "A package should have a description. This should be placed in a README file. The string should contain the local path (relative to the `pyproject.toml` file) to the description file." + "A package should have a description. This should be placed in a README file. The string should contain the local path (relative to the `pyproject.toml` file) to the description file.\n" ] }, { @@ -711,8 +703,10 @@ "metadata": {}, "source": [ "### Licensing\n", - "It is very important to have a license for your published code. This is how you instruct anyone that wants to use it on the terms and conditions of copying or modifying the code. [ChooseYourLicense](https://choosealicense.com/) is a good source of information.\n", + "\n", + "It is very important to have a license for your published code. This is how you instruct anyone that wants to use it on the terms and conditions of copying or modifying the code. [ChooseYourLicense](https://choosealicense.com/) is a good source of information.\n", "A summary of recommened licenses:\n", + "\n", "- **MIT**: Permissive - Others can use your code in any way, and you will not be sued if the software doesn't work (recommended in most cases)\n", "- **GPL**: Copyleft - derivative work must use the same license - good way to embrace open source but often problematic for commercial companies\n", "- **LGPL**: Similar to GPL but software can be used under different license\n", @@ -725,13 +719,14 @@ "metadata": {}, "source": [ "### Version\n", + "\n", "Given a version number `MAJOR.MINOR.PATCH`, increment the:\n", "\n", "1. `MAJOR` version when you make incompatible API changes\n", "2. `MINOR` version when you add functionality in a backward compatible manner\n", "3. `PATCH` version when you make backward compatible bug fixes\n", "\n", - "This is called semantic versioning, see [semver.org](https://semver.org/) for details." + "This is called semantic versioning, see [semver.org](https://semver.org/) for details.\n" ] }, { @@ -740,7 +735,8 @@ "metadata": {}, "source": [ "### Python versioning\n", - "As Python evolves and introduces new features and deprecates versions, your software should do the same. Decide on a minimal requirement for Python (and in some cases a maximum version if a package you are using is not supporting the latest Python version)." + "\n", + "As Python evolves and introduces new features and deprecates versions, your software should do the same. Decide on a minimal requirement for Python (and in some cases a maximum version if a package you are using is not supporting the latest Python version).\n" ] }, { @@ -749,8 +745,9 @@ "metadata": {}, "source": [ "### Dependencies\n", + "\n", "As our package might depend on external software, we create a list of packages such as `[\"numpy>=1.21\", \"sklearn==1.3.0\"]` etc.\n", - "These will be installed if not found on the system at the time of installation." + "These will be installed if not found on the system at the time of installation.\n" ] }, { @@ -759,12 +756,13 @@ "metadata": {}, "source": [ "### Optional dependencies\n", - "Sometimes, we require dependencies for testing or development that are not requirements of the source code. We call these optional dependencies and list them as below" + "\n", + "Sometimes, we require dependencies for testing or development that are not requirements of the source code. We call these optional dependencies and list them as below\n" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 69, "id": "f46d6861", "metadata": {}, "outputs": [ @@ -779,7 +777,7 @@ "]\n", "dev = [\n", " \"pdbpp\", \"ipython\"\n", - "]" + "]\n" ] } ], @@ -793,22 +791,27 @@ "metadata": {}, "source": [ "We install these by calling\n", + "\n", "```\n", "python3 -m pip install .... path/to/package[dev]\n", "```\n", + "\n", "or\n", + "\n", "```\n", "python3 -m pip install .... path/to/package[test]\n", "```\n", + "\n", "or\n", + "\n", "```\n", "python3 -m pip install .... path/to/package[dev,test]\n", - "```" + "```\n" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 70, "id": "a1e516d3", "metadata": {}, "outputs": [ @@ -816,64 +819,59 @@ "name": "stdout", "output_type": "stream", "text": [ - "Defaulting to user installation because normal site-packages is not writeable\n", - "Obtaining file:///home/dokken/Documents/UiO-IN3110.github.io/lectures/python/examples/my-package\n", + "Obtaining file:///home/dokken/Documents/src/UiO/UiO-IN3110.github.io/lectures/python/examples/my-package\n", " Installing build dependencies ... \u001b[?25ldone\n", "\u001b[?25h Checking if build backend supports build_editable ... \u001b[?25ldone\n", "\u001b[?25h Getting requirements to build editable ... \u001b[?25ldone\n", "\u001b[?25h Preparing editable metadata (pyproject.toml) ... \u001b[?25ldone\n", - "\u001b[?25hRequirement already satisfied: numpy>=1.20.0 in /home/dokken/.local/lib/python3.8/site-packages (1.20.1)\n", - "Requirement already satisfied: pytest in /home/dokken/.local/lib/python3.8/site-packages (7.1.3)\n", - "Collecting pdbpp\n", - " Downloading pdbpp-0.10.3-py2.py3-none-any.whl (23 kB)\n", - "Requirement already satisfied: ipython in /home/dokken/.local/lib/python3.8/site-packages (8.5.0)\n", - "Requirement already satisfied: backcall in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (0.2.0)\n", - "Requirement already satisfied: decorator in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (4.4.2)\n", - "Requirement already satisfied: jedi>=0.16 in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (0.18.0)\n", - "Requirement already satisfied: matplotlib-inline in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (0.1.6)\n", - "Requirement already satisfied: pickleshare in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (0.7.5)\n", - "Requirement already satisfied: prompt-toolkit<3.1.0,>3.0.1 in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (3.0.16)\n", - "Requirement already satisfied: pygments>=2.4.0 in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (2.8.1)\n", - "Requirement already satisfied: stack-data in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (0.5.0)\n", - "Requirement already satisfied: traitlets>=5 in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (5.9.0)\n", - "Requirement already satisfied: pexpect>4.3 in /home/dokken/.local/lib/python3.8/site-packages (from ipython) (4.8.0)\n", - "Collecting fancycompleter>=0.8 (from pdbpp)\n", - " Downloading fancycompleter-0.9.1-py3-none-any.whl (9.7 kB)\n", - "Collecting wmctrl (from pdbpp)\n", - " Downloading wmctrl-0.5-py2.py3-none-any.whl.metadata (943 bytes)\n", - "Requirement already satisfied: attrs>=19.2.0 in /home/dokken/.local/lib/python3.8/site-packages (from pytest) (20.3.0)\n", - "Requirement already satisfied: iniconfig in /home/dokken/.local/lib/python3.8/site-packages (from pytest) (1.1.1)\n", - "Requirement already satisfied: packaging in /home/dokken/.local/lib/python3.8/site-packages (from pytest) (23.0)\n", - "Requirement already satisfied: pluggy<2.0,>=0.12 in /home/dokken/.local/lib/python3.8/site-packages (from pytest) (1.0.0)\n", - "Requirement already satisfied: py>=1.8.2 in /home/dokken/.local/lib/python3.8/site-packages (from pytest) (1.11.0)\n", - "Requirement already satisfied: tomli>=1.0.0 in /home/dokken/.local/lib/python3.8/site-packages (from pytest) (2.0.1)\n", - "Collecting pyrepl>=0.8.2 (from fancycompleter>=0.8->pdbpp)\n", - " Downloading pyrepl-0.9.0.tar.gz (48 kB)\n", - "\u001b[2K \u001b[38;2;114;156;31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m48.7/48.7 kB\u001b[0m \u001b[31m3.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", - "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25ldone\n", - "\u001b[?25hRequirement already satisfied: parso<0.9.0,>=0.8.0 in /home/dokken/.local/lib/python3.8/site-packages (from jedi>=0.16->ipython) (0.8.1)\n", - "Requirement already satisfied: ptyprocess>=0.5 in /home/dokken/.local/lib/python3.8/site-packages (from pexpect>4.3->ipython) (0.7.0)\n", - "Requirement already satisfied: wcwidth in /home/dokken/.local/lib/python3.8/site-packages (from prompt-toolkit<3.1.0,>3.0.1->ipython) (0.2.5)\n", - "Requirement already satisfied: executing in /home/dokken/.local/lib/python3.8/site-packages (from stack-data->ipython) (1.0.0)\n", - "Requirement already satisfied: asttokens in /home/dokken/.local/lib/python3.8/site-packages (from stack-data->ipython) (2.0.8)\n", - "Requirement already satisfied: pure-eval in /home/dokken/.local/lib/python3.8/site-packages (from stack-data->ipython) (0.2.2)\n", - "Requirement already satisfied: six in /usr/lib/python3/dist-packages (from asttokens->stack-data->ipython) (1.14.0)\n", - "Downloading wmctrl-0.5-py2.py3-none-any.whl (4.3 kB)\n", - "Checking if build backend supports build_editable ... \u001b[?25ldone\n", - "\u001b[?25hBuilding wheels for collected packages: pkg, pyrepl\n", + "\u001b[?25hRequirement already satisfied: numpy>=1.20.0 in /home/dokken/.local/lib/python3.10/site-packages (from pkg==0.1.0) (1.26.1)\n", + "Requirement already satisfied: pytest in /home/dokken/.local/lib/python3.10/site-packages (from pkg==0.1.0) (7.3.1)\n", + "Collecting pdbpp (from pkg==0.1.0)\n", + " Using cached pdbpp-0.10.3-py2.py3-none-any.whl (23 kB)\n", + "Requirement already satisfied: ipython in /home/dokken/.local/lib/python3.10/site-packages (from pkg==0.1.0) (8.6.0)\n", + "Requirement already satisfied: backcall in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (0.2.0)\n", + "Requirement already satisfied: decorator in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (5.1.1)\n", + "Requirement already satisfied: jedi>=0.16 in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (0.18.2)\n", + "Requirement already satisfied: matplotlib-inline in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (0.1.6)\n", + "Requirement already satisfied: pickleshare in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (0.7.5)\n", + "Requirement already satisfied: prompt-toolkit<3.1.0,>3.0.1 in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (3.0.39)\n", + "Requirement already satisfied: pygments>=2.4.0 in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (2.15.1)\n", + "Requirement already satisfied: stack-data in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (0.6.1)\n", + "Requirement already satisfied: traitlets>=5 in /home/dokken/.local/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (5.8.0)\n", + "Requirement already satisfied: pexpect>4.3 in /home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10/site-packages (from ipython->pkg==0.1.0) (4.8.0)\n", + "Collecting fancycompleter>=0.8 (from pdbpp->pkg==0.1.0)\n", + " Using cached fancycompleter-0.9.1-py3-none-any.whl (9.7 kB)\n", + "Collecting wmctrl (from pdbpp->pkg==0.1.0)\n", + " Downloading wmctrl-0.5-py2.py3-none-any.whl (4.3 kB)\n", + "Requirement already satisfied: iniconfig in /home/dokken/.local/lib/python3.10/site-packages (from pytest->pkg==0.1.0) (2.0.0)\n", + "Requirement already satisfied: packaging in /home/dokken/.local/lib/python3.10/site-packages (from pytest->pkg==0.1.0) (23.1)\n", + "Requirement already satisfied: pluggy<2.0,>=0.12 in /home/dokken/.local/lib/python3.10/site-packages (from pytest->pkg==0.1.0) (1.0.0)\n", + "Requirement already satisfied: exceptiongroup>=1.0.0rc8 in /home/dokken/.local/lib/python3.10/site-packages (from pytest->pkg==0.1.0) (1.0.4)\n", + "Requirement already satisfied: tomli>=1.0.0 in /home/dokken/.local/lib/python3.10/site-packages (from pytest->pkg==0.1.0) (2.0.1)\n", + "Collecting pyrepl>=0.8.2 (from fancycompleter>=0.8->pdbpp->pkg==0.1.0)\n", + " Using cached pyrepl-0.9.0-py3-none-any.whl\n", + "Requirement already satisfied: parso<0.9.0,>=0.8.0 in /home/dokken/.local/lib/python3.10/site-packages (from jedi>=0.16->ipython->pkg==0.1.0) (0.8.3)\n", + "Requirement already satisfied: ptyprocess>=0.5 in /home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10/site-packages (from pexpect>4.3->ipython->pkg==0.1.0) (0.7.0)\n", + "Requirement already satisfied: wcwidth in /home/dokken/.local/lib/python3.10/site-packages (from prompt-toolkit<3.1.0,>3.0.1->ipython->pkg==0.1.0) (0.2.5)\n", + "Requirement already satisfied: executing>=1.2.0 in /home/dokken/.local/lib/python3.10/site-packages (from stack-data->ipython->pkg==0.1.0) (1.2.0)\n", + "Requirement already satisfied: asttokens>=2.1.0 in /home/dokken/.local/lib/python3.10/site-packages (from stack-data->ipython->pkg==0.1.0) (2.1.0)\n", + "Requirement already satisfied: pure-eval in /home/dokken/.local/lib/python3.10/site-packages (from stack-data->ipython->pkg==0.1.0) (0.2.2)\n", + "Requirement already satisfied: attrs in /home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10/site-packages (from wmctrl->pdbpp->pkg==0.1.0) (23.1.0)\n", + "Requirement already satisfied: six in /home/dokken/src/mambaforge/envs/UIO-IN3110/lib/python3.10/site-packages (from asttokens>=2.1.0->stack-data->ipython->pkg==0.1.0) (1.16.0)\n", + "Building wheels for collected packages: pkg\n", " Building editable for pkg (pyproject.toml) ... \u001b[?25ldone\n", - "\u001b[?25h Created wheel for pkg: filename=pkg-0.1.0-0.editable-py3-none-any.whl size=2852 sha256=491be2407bad595377c19684c078526df2d05b5e501b46fd80907b67ea69d84e\n", - " Stored in directory: /tmp/pip-ephem-wheel-cache-7oud3mqv/wheels/55/cc/57/3120b08927ab03809b28e441ce1800d832c33b007a8f3fccf4\n", - " Building wheel for pyrepl (setup.py) ... \u001b[?25ldone\n", - "\u001b[?25h Created wheel for pyrepl: filename=pyrepl-0.9.0-py3-none-any.whl size=59907 sha256=6caad23ca7fe0129ee5803f7ef26ede82d3ba966439d8e91956c897c19355476\n", - " Stored in directory: /home/dokken/.cache/pip/wheels/b4/a5/d0/14169e64d73c6da225a09c696273a24c57e28826c2a795ea53\n", - "Successfully built pkg pyrepl\n", + "\u001b[?25h Created wheel for pkg: filename=pkg-0.1.0-0.editable-py3-none-any.whl size=2854 sha256=efbde18e0330484f94cd6f9cad380eb1166038c8641ccb2376635597a4fdb116\n", + " Stored in directory: /tmp/pip-ephem-wheel-cache-tu8kamji/wheels/e7/be/ae/c7a1fe811e9515c9b17aa8a901178b4faa716117ff2d3aab87\n", + "Successfully built pkg\n", "Installing collected packages: pyrepl, wmctrl, pkg, fancycompleter, pdbpp\n", " Attempting uninstall: pkg\n", " Found existing installation: pkg 0.1.0\n", " Uninstalling pkg-0.1.0:\n", " Successfully uninstalled pkg-0.1.0\n", - "Successfully installed fancycompleter-0.9.1 pdbpp-0.10.3 pkg-0.1.0 pyrepl-0.9.0 wmctrl-0.5\n" + "Successfully installed fancycompleter-0.9.1 pdbpp-0.10.3 pkg-0.1.0 pyrepl-0.9.0 wmctrl-0.5\n", + "\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.3.1\u001b[0m\n", + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n" ] } ],