From b504315ca4e306e73bb7409bb82898f5c33f8b2e Mon Sep 17 00:00:00 2001 From: Kray-G Date: Fri, 13 Aug 2021 17:51:56 +0900 Subject: [PATCH] #232: updated for Package Manager, --- ChangeLog.md | 9 ++- docs/Kip.md | 146 +++++++++++++++++++++++++++++++++++++++++ lib/exec/kip.kx | 24 ++++++- lib/std/pkg/Develop.kx | 35 ++++++++++ 4 files changed, 209 insertions(+), 5 deletions(-) create mode 100644 docs/Kip.md diff --git a/ChangeLog.md b/ChangeLog.md index 47b4ecef..d00bf610 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -7,12 +7,17 @@ * Support GUI library. * Support OpenCV library. * Support HTTP Server library. + * Enhancement Plan + * Package Maneger + * Dependency check between packages. + * Scan for the update. + * Search packages with pattern matching. ## V1.1.0 (Current Development Version) -* Planned - * #232: Support Package Manager. * New Features + * #232: Supported a Package Manager named as `Kip`. + * 1st version with no dependency check and no update check. * #275: Supported SAT solver by picosat. * Improvements/Enhancements * #261: Separated binary modules in extlib to another repository & reduced a repository size. diff --git a/docs/Kip.md b/docs/Kip.md new file mode 100644 index 00000000..25323887 --- /dev/null +++ b/docs/Kip.md @@ -0,0 +1,146 @@ +# Kip - `kip Installs Packages` + +## Introduction + +Kip is a package manager of Kinx. +You can easily use a package by Kip. + +Regarding the package of Kinx, see the [Package](Package.md) page for details. + +## Overview + +Kip has features below. + +* Kip Configuration +* Central Repository Management +* Package Control + +### Kip Configuration + +You can setup the configuration and environment in order to use Kip by `Configuration` feature. + +### Central Repository Management + +Kip system will work by connected with a central repository which has a list of packages. +There is a default central repository and you can use Kip soon. +The default central repository is below, and you can see all standard packages there. + +* https://github.com/Kray-G/kinx-package-repository + +### Package Control + +Kip can control packages like an installation, an uninstallation, or searching a package. + +## How To Use + +### Configuration + +#### `kip confg set ` + +Set the `` to the parameter specified by the `name`. + +#### `kip confg remove ` + +Remove the value which was set to the parameter specified by the `name`. + +#### `kip confg show []` + +Show the list of parameters with name and value. +If specified the ``, it shows only that parameter. + +### Available Parameters + +Currently the following settings are available. + +| Name | Meaning | Example | +| ---------------- | ---------------------------- | ------------------------------- | +| `proxy.url` | URL of Proxy Server. | `http://proxy.example.com:8080` | +| `proxy.username` | User name for the proxy. | `username` | +| `proxy.password` | Password for the proxy user. | `password` | + +### Central Repository Management + +#### `kip repo add ` + +Add the other central repository which you specified by ``. +This feature will be used if you want to use your own repository. +For example, you think it is not a standard or in the case that you do not want to register your package to the default central repository. + +#### `kip repo remove ` + +Remove the repository which you specified by ``. + +Note that you can remove also a default central repository. +If you removed it, you should add it again. + +#### `kip repo list` + +Show the list of central repositories. +Moreover, it shows also the list of packages registered to each repository. + +### Package Control + +#### `kip search []` + +Show the list of all packages. +If specified the ``, it shows the package registered as `` if exists. + +> TODO: Searching packages with pattern matching. + +#### `kip install []` + +Install the package which you specified by the ``. +If not specified the ``, it installs the latest version of the package. +If specified it, it installs the specified version of the package only. + +#### `kip uninstall |all` + +Unnstall the package which you specified by the ``. +The `` is necessary to uninstall the package, and it uninstalls the specified version of the package only. +If you want to uninstall all versions in the package, specify it as `all` instead of an actual version. + +#### `kip devinstall` + +Install a developing package which you are developing in progress. + +You must move to the package repository root and you should prepare `build/build.kx` file in advance. +`build/build.kx` is the code to install the package like the following code for example. +This code is the stuff prepared in the `typesetting` package. + +```javascript +using pkg.Develop; + +var pkgname = "typesetting"; +var version = "0.0.2"; + +new PackageUpdater($$, pkgname, version).update { &(util) + Directory.change("src") { + Directory.walk(".") { + util.dircopy(_1, util.root / _1.filename()); + }; + }; + Directory.walk("docs") { + util.dircopy(_1, util.root / _1); + }; +}; +``` + +As you see, you can use `PackageUpdater` class and use `util.dircopy()` to install your developped components into the Kinx package directory. +The package name will be `typesetting-dev` when you install it like this. +The `-dev` postfix means this package is a developing package. +Therefore you can not use a `-dev` postfix to any package name. + +By the way, you can uninstall it with normally `kip uninstall` command. +You can use just `kip uninstall typesetting-dev all` and uninstall it correctly. + +#### `kip list` + +Show the list of installed packages with installed versions. + +#### `kip update []` + +> **Not supported yet.** + +Check if there are some updates, and update to the latest version if exists. + +> TODO: Supporting this feature. diff --git a/lib/exec/kip.kx b/lib/exec/kip.kx index 38cc2681..ba61f9c6 100644 --- a/lib/exec/kip.kx +++ b/lib/exec/kip.kx @@ -25,6 +25,7 @@ */ using SemanticVersion; using DateTime; +using Process; const MAIN_PACKAGE_CENTRAL_REPO = "https://github.com/Kray-G/kinx-package-repository"; @@ -549,12 +550,13 @@ class KinxPackageLibraryManager(repoMgr_) { } private uninstallAll(name) { + var isDevelopmentMode = name.endsWith("-dev"); var exe = File.exists($kinxpath / "kxrepl.exe"); var packagebase = $pkgpath / name; Directory.walk(packagebase) { &(packagedir) Directory.walk(packagedir / "bin") { &(f) if (f.extension() == ".kx" && !f.stem().endsWith("-dev")) { - var dst = $kinxpath / f.stem() + (exe ? ".exe" : ""); + var dst = $kinxpath / f.stem() + (isDevelopmentMode ? "-dev" : "") + (exe ? ".exe" : ""); if (File.exists(dst)) { if (removeFile(dst)) { Kip.progressln("Removed an executable of %s" % dst.filename()); @@ -585,6 +587,7 @@ class KinxPackageLibraryManager(repoMgr_) { } // Remove a specific binary. + var isDevelopmentMode = name.endsWith("-dev"); var exe = File.exists($kinxpath / "kxrepl.exe"); var packagebase = $pkgpath / name; var packagedir = packagebase / version; @@ -599,7 +602,7 @@ class KinxPackageLibraryManager(repoMgr_) { if (vers.length() == 1 && vers[0] == version) { Directory.walk(packagedir / "bin") { &(f) if (f.extension() == ".kx") { - var dst = $kinxpath / f.stem() + (exe ? ".exe" : ""); + var dst = $kinxpath / f.stem() + (isDevelopmentMode ? "-dev" : "") + (exe ? ".exe" : ""); if (File.exists(dst)) { if (removeFile(dst)) { Kip.progressln("Removed an executable of %s" % dst.filename()); @@ -636,6 +639,17 @@ class KinxPackageLibraryManager(repoMgr_) { return false; } + public devinstall() { + var buildkx = $pwd / "build/build.kx"; + if (!File.exists(buildkx)) { + Kip.errorln("Not found: build/build.kx to install a developing package"); + return false; + } + var kinx = $kinxpath / "kinx"; + var p = new Process([kinx, buildkx, "--dev"], { out: $stdout, err: $stderr }).run(); + p.wait(); + return true; + } } class KinxPackageManager { @@ -702,6 +716,9 @@ class KinxPackageManager { case "search": case "s": mgr.search(args[2]); return true; + case "devinstall": + mgr.devinstall(); + return true; } return false; } @@ -724,8 +741,9 @@ class KinxPackageManager { Kip.info("Packages Control"); Kip.info(" search Searches a package."); Kip.info(" install [] Installs a specified package."); - Kip.info(" uninstall [] Uninstalls a specified package."); + Kip.info(" uninstall |all Uninstalls a specified package."); # Kip.info(" update [] Installs the latest version."); + Kip.info(" devinstall Installs a develping package."); Kip.info(" list Lists up installed packages."); } diff --git a/lib/std/pkg/Develop.kx b/lib/std/pkg/Develop.kx index f0caed59..6de3b6b8 100644 --- a/lib/std/pkg/Develop.kx +++ b/lib/std/pkg/Develop.kx @@ -144,3 +144,38 @@ class DevelopPackageUpdater(pkgname, version) { } } + +class ReleasePackageArchiver(pkgname, version) { + + var zip_ = new Zip($pwd / "package.zip", File.WRITE); + + public dircopy(file1, file2) { + if (file1 != "dev" && File.isDirectory(file1)) { + System.println("Adding a directory : ", file1); + zip_.addFile(file1); + } + } + + public update(code) { + code(this); + } + +} + +class PackageUpdater(args, pkgname, version) { + + var opt, config; + while (opt = System.getopt(args, "d", { dev: 'd' })) { + switch (opt.type) { + case 'd': + config.dev = true; + break; + } + } + + if (config.dev) { + return new DevelopPackageUpdater(pkgname, version); + } + + return new ReleasePackageArchiver(pkgname, version); +}