From 445579942c9232f30de8caba61f02efb834f92c5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 9 Jan 2017 10:37:10 +0530 Subject: [PATCH] Make creating a linux package even easier --- README.asciidoc | 26 +++++++++++--------------- setup.py | 35 ++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/README.asciidoc b/README.asciidoc index 213a56042..b7ee1dc7f 100644 --- a/README.asciidoc +++ b/README.asciidoc @@ -261,22 +261,18 @@ Instead run, python3 setup.py linux-package ``` -This will create the directory `linux-package` containing all the files need to run kitty. kitty can be run using +This will install kitty into the directory `linux-package`. You can run kitty +with `linux-package/bin/kitty`. All the files needed to run kitty will be in +`linux-package/lib/kitty`. The terminfo file will be installed into +`linux-package/share/terminfo`. Simply copy these files into `/usr` to install +kitty. In other words, `linux-package` is the staging area into which kitty is +installed. You can choose a different staging area, by passing the `--prefix` +argument to `setup.py`. -``` -python3 linux-package -``` - -The `linux-package` directory can be renamed and moved anywhere on the -filesystem, it is self contained. So simply create a launcher script named -`/usr/bin/kitty` that calls `python3 /path/to/the/installed/linux-package/directory`. - -You should also create a second package named kitty-terminfo that installs the -file `linux-package/terminfo/x/xterm-kitty` into `/usr/share/terminfo` (or -whatever location your distribution uses for terminfo files). Make the main -kitty package depend on `kitty-terminfo`. This allows users to install the -terminfo file on servers into which they ssh, without needing to install all of -kitty. +You should probably split kitty into two packages, `kitty-terminfo` that +installs the terminfo file and `kitty` that installs the main program. +This allows users to install the terminfo file on servers into which they ssh, +without needing to install all of kitty. == Resources on terminal behavior diff --git a/setup.py b/setup.py index a112037c9..afa50d65b 100755 --- a/setup.py +++ b/setup.py @@ -146,6 +146,7 @@ def option_parser(): p.add_argument('--asan', default=False, action='store_true', help='Turn on address sanitization to detect memory access errors. Note that if you do turn it on,' ' you have to run kitty with the environment variable LD_PRELOAD=/usr/lib/libasan.so') + p.add_argument('--prefix', default='./linux-package', help='Where to create the linux package') return p @@ -165,26 +166,46 @@ def build(args): compile_c_extension('kitty/fast_data_types', *find_c_files()) +def safe_makedirs(path): + try: + os.makedirs(path) + except FileExistsError: + pass + + def package(args): - ddir = 'linux-package' - if os.path.exists(ddir): - shutil.rmtree(ddir) - os.makedirs(ddir + '/terminfo/x') - shutil.copy2('__main__.py', ddir) - shutil.copy2('terminfo/x/xterm-kitty', ddir + '/terminfo/x') + ddir = args.prefix + libdir = os.path.join(ddir, 'lib', 'kitty') + terminfo_dir = os.path.join(ddir, 'share/terminfo/x') + if os.path.exists(libdir): + shutil.rmtree(libdir) + os.makedirs(os.path.join(libdir, 'terminfo/x')) + safe_makedirs(terminfo_dir) + shutil.copy2('__main__.py', libdir) + shutil.copy2('terminfo/x/xterm-kitty', terminfo_dir) + shutil.copy2('terminfo/x/xterm-kitty', os.path.join(libdir, 'terminfo/x')) def src_ignore(parent, entries): return [x for x in entries if '.' in x and x.rpartition('.')[2] not in ('py', 'so', 'conf')] - shutil.copytree('kitty', ddir + '/kitty', ignore=src_ignore) + shutil.copytree('kitty', os.path.join(libdir, 'kitty'), ignore=src_ignore) import compileall compileall.compile_dir(ddir, quiet=1, workers=4) + for root, dirs, files in os.walk(ddir): + for f in files: + path = os.path.join(root, f) + os.chmod(path, 0o755 if f.endswith('.so') else 0o644) + launcher_dir = os.path.join(ddir, 'bin') + safe_makedirs(launcher_dir) + run_tool([cc, '-ggdb', 'linux-launcher.c', '-o', os.path.join(launcher_dir, 'kitty')]) def main(): if sys.version_info < (3, 5): raise SystemExit('python >= 3.5 required') args = option_parser().parse_args() + args.prefix = os.path.abspath(args.prefix) + os.chdir(os.path.dirname(os.path.abspath(__file__))) if args.action == 'build': build(args) elif args.action == 'test':