Skip to content

Commit

Permalink
#232: updated for Package Manager,
Browse files Browse the repository at this point in the history
  • Loading branch information
Kray-G committed Aug 13, 2021
1 parent c46281a commit b504315
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 5 deletions.
9 changes: 7 additions & 2 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
146 changes: 146 additions & 0 deletions docs/Kip.md
Original file line number Diff line number Diff line change
@@ -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 <name> <value>`

Set the `<value>` to the parameter specified by the `name`.

#### `kip confg remove <name>`

Remove the value which was set to the parameter specified by the `name`.

#### `kip confg show [<name>]`

Show the list of parameters with name and value.
If specified the `<name>`, 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 <url>`

Add the other central repository which you specified by `<url>`.
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 <url>`

Remove the repository which you specified by `<url>`.

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 [<key>]`

Show the list of all packages.
If specified the `<key>`, it shows the package registered as `<key>` if exists.

> TODO: Searching packages with pattern matching.
#### `kip install <key> [<ver>]`

Install the package which you specified by the `<key>`.
If not specified the `<ver>`, it installs the latest version of the package.
If specified it, it installs the specified version of the package only.

#### `kip uninstall <key> <ver>|all`

Unnstall the package which you specified by the `<key>`.
The `<ver>` 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 [<key>]`

> **Not supported yet.**
Check if there are some updates, and update to the latest version if exists.

> TODO: Supporting this feature.
24 changes: 21 additions & 3 deletions lib/exec/kip.kx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
using SemanticVersion;
using DateTime;
using Process;

const MAIN_PACKAGE_CENTRAL_REPO = "https://github.com/Kray-G/kinx-package-repository";

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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;
Expand All @@ -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());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -702,6 +716,9 @@ class KinxPackageManager {
case "search": case "s":
mgr.search(args[2]);
return true;
case "devinstall":
mgr.devinstall();
return true;
}
return false;
}
Expand All @@ -724,8 +741,9 @@ class KinxPackageManager {
Kip.info("Packages Control");
Kip.info(" search <key> Searches a package.");
Kip.info(" install <key> [<ver>] Installs a specified package.");
Kip.info(" uninstall <key> [<ver>] Uninstalls a specified package.");
Kip.info(" uninstall <key> <ver>|all Uninstalls a specified package.");
# Kip.info(" update [<key>] Installs the latest version.");
Kip.info(" devinstall Installs a develping package.");
Kip.info(" list Lists up installed packages.");
}

Expand Down
35 changes: 35 additions & 0 deletions lib/std/pkg/Develop.kx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit b504315

Please sign in to comment.