{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Creating packages" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "import shutil" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "src = Path('FastaiNotebooks/Sources/FastaiNotebooks')\n", "mods = sorted(src.ls())\n", "mods" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fn = mods[0]\n", "fn" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fn.stem" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pkg_tmpl = \"\"\"// swift-tools-version:4.2\n", "import PackageDescription\n", "\n", "let package = Package(\n", " name: \"{name}\",\n", " products: [\n", " .library(name: \"{name}\", targets: [\"{name}\"]),\n", " ],\n", " dependencies: [\n", "{deps}\n", " .package(url: \"https://github.com/mxcl/Path.swift\", from: \"0.16.1\"),\n", " .package(url: \"https://github.com/JustHTTP/Just\", from: \"0.7.1\")\n", " ],\n", " targets: [\n", " .target(\n", " name: \"{name}\",\n", " dependencies: [\"Just\", \"Path\"]),\n", " ]\n", ")\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def mod_name(notebook_name):\n", " return 'FastaiNotebook_%s' % notebook_name\n", "\n", "dep_tmpl = ' .package(path: \"../{name}\"),'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print('\\n'.join(dep_tmpl.format(name=o) for o in mods[:3]))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "for i,fn in enumerate(mods):\n", " name = mod_name(fn.stem)\n", " dst = Path(name)\n", " dst.mkdir(exist_ok=True)\n", " deps = '\\n'.join(dep_tmpl.format(name=mod_name(o.stem)) for o in mods[:i])\n", " with (dst/'Package.swift').open('w') as pkg_f:\n", " pkg_f.write(pkg_tmpl.format(name=name, deps=deps))\n", " dst_p = dst/'Sources'/name\n", " dst_p.mkdir(parents=True, exist_ok=True)\n", " for fc in mods[:i+1]: shutil.copy(fc, dst_p)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 2 }