Git Product home page Git Product logo

base16-builder-python's Introduction

https://travis-ci.org/InspectorMustache/base16-builder-python.svg?branch=master

Deprecated

Use base24-builder-python instead. Sorry to anyone who's been waiting for me to update this repo.

base16-builder-python

Finally, a base16 builder that doesn't require me to install anything new.

Installation

As this project uses async/await syntax, the lowest supported Python version is 3.5.

pip install pybase16-builder

If you don't want to clutter your computer with something that you're just going to use once you can also just clone this repository and use the provided pybase16.py file.

Usage

There are three modes of operation:

pybase16 update
pybase16 build
pybase16 inject

Basic Usage

If you just want to build all base16 colorschemes and then pick out the ones you need, simply run:

pybase16 update
pybase16 build

Once the process is finished, you can find all colorschemes in a folder named output located in the current working directory.

For a more detailed explanation of the individual commands, read on.

Update

Downloads all base16 schemes and templates to the current working directory. The source files, i.e. the files pointing to the scheme and template repositories (see builder.md) will also be updated by default. If you want to use your own versions of these files (to exclude specific repositories, for example), you can prevent the builder from updating the source files by using the -c/--custom option. You can use -v/--verbose for more detailed output.

Build

Builds base16 colorschemes for all schemes and templates. This requires the directory structure and files created by the update operation to be present in the working directory. This operation accepts four parameters:

  • -s/--scheme restricts building to specific schemes

    Can be specified more than once. Each argument must match a scheme. Wildcards can be used but must be escaped properly so they are not expanded by the shell.

  • -t/--template restricts building to specific templates

    Can be specified more than once. Each argument must correspond to a folder name in the templates directory.

  • -o/--output specifies a path where built colorschemes will be placed

    If this option is not specified, an "output" folder in the current working directory will be created and used.

  • -v/--verbose increases verbosity

    With this option specified the builder prints out the name of each scheme as it's built.

Example:

pybase16 build -t dunst -s atelier-heath-light -o /tmp/output

Inject

This operation provides an easier way to quickly insert a specific colorscheme into one or more config files. In order for the builder to locate the necessary files, this command relies on the folder structure created by the update command. The command accepts two parameters:

  • -s/--scheme specifies the scheme you wish to inject

    Refers to the scheme that should be inserted. You can use wildcards and the same restrictions as with update apply. A pattern that matches more than one scheme will cause an error.

  • -f/--file specifies the file(s) into which you wish the scheme to be inserted

    Can be specified more than once. Each argument must be specified as a path to a config file that features proper injection markers (see below).

You will need to prepare your configuration files so that the script knows where to insert the colorscheme. This is done by including two lines in the file

# %%base16_template: TEMPLATE_NAME##SUBTEMPLATE_NAME %%

Everything in-between these two lines will be replaced with the colorscheme.

# %%base16_template_end%%

Both lines can feature arbitrary characters before the first two percentage signs. This is so as to accomodate different commenting styles. Both lines need to end exactly as demonstrated above, however. "TEMPLATE_NAME" and "SUBTEMPLATE_NAME" are the exception to this. Replace TEMPLATE_NAME with the name of the template you wish to insert, for example "gnome-terminal". This must correspond to a folder in the templates directory. Replace SUBTEMPLATE_NAME with the name of the subtemplate as it is defined at the top level of the template's config.yaml file (see file.md for details), for example "default-256". If you omit the subtemplate name (don't omit "##" though), "default" is assumed.

An example of an i3 config file prepared in such a way can be found here.

Specify the name of the scheme you wish to inject with the -s option. Use the -f option for each file into which you want to inject the scheme.

As an example, here's the command I use to globally change the color scheme in all applications that support it:

pybase16 inject -s ocean -f ~/.gtkrc-2.0.mine -f ~/.config/dunst/dunstrc -f ~/.config/i3/config -f ~/.config/termite/config -f ~/.config/zathura/zathurarc

Exit

The program exits with exit code 1 if it encountered a general error and with 2 if one or more build or update tasks produced a warning or an error.

base16-builder-python's People

Contributors

averms avatar cerebus avatar inspectormustache avatar lainproliant avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

base16-builder-python's Issues

Licensing Question

Whatever I produce with this builder, can I integrate it into my own GPL3 licensed projects?*

I thought I knew how this works, but I get very confused because this builder combines so many different repositories. Would I essentially have to look up each template/scheme?

* Apparently the MIT license requires me to add itself - but looking through a few repos, they all have different names in their copyright. Huh.

PyPI Request: Update

Hi! Just wanted to let you know that the version of pybase16-builder published to PyPI is out of date and missing some more recent commits. Would you please update it and bump the minor version? Thanks so much for making this!

Single Color Scheme

Is there a way to specify a single color scheme to clone and/or build? As a way to do color scheme development.

BTW, thank for the easy-to-use tool!

Failed to Update

I just cloned the repository (commit 00b02a8), and wanted to update/build the themes, but the python program reportedly could not connect to github.com.

Python version was 3.6, I can also ping successfully myself.

Any tips on how to resolve this issue?

C:\Users\gilj\themes
(py36) λ python base16-builder-python\pybase16.py update
Creating sources.yaml…
Cloning sources…
Start cloning from https://github.com/chriskempson/base16-schemes-source.git…
Start cloning from https://github.com/chriskempson/base16-templates-source.git…
Error cloning from https://github.com/chriskempson/base16-schemes-source.git:
Cloning into 'C:\Users\gilj\themes\sources\schemes'...
fatal: unable to access 'https://github.com/chriskempson/base16-schemes-source.git/': Could not resolve host: github.com
Error cloning from https://github.com/chriskempson/base16-templates-source.git:
Cloning into 'C:\Users\gilj\themes\sources\templates'...
fatal: unable to access 'https://github.com/chriskempson/base16-templates-source.git/': Could not resolve host: github.com


Cloning templates…
Necessary resources for updating not found in current working directory.

C:\Users\gilj\themes
(py36) λ ping github.com

Pinging github.com [192.30.253.112] with 32 bytes of data:
Reply from 192.30.253.112: bytes=32 time=88ms TTL=51
Reply from 192.30.253.112: bytes=32 time=88ms TTL=51

Ping statistics for 192.30.253.112:
    Packets: Sent = 2, Received = 2, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 88ms, Maximum = 88ms, Average = 88ms
Control-C
^C
C:\Users\gilj\themes
(py36) λ python --version
Python 3.6.5

pybase16 update prompts for Github credentials

Given: An empty current working directory and a clean pybase16-builder install (using pipx)

When: I run

$ pybase16 update

Then: I would expect no interaction is required. However, I get prompted for Github credentials:

$ pybase16 update
Creating sources.yaml…
Cloning sources…
Cloning templates…
Username for 'https://github.com':

distinguish between missing templates and schemes

When there's not template or scheme file, we get a general error saying not all resources present. Instead, it'd be nice if it reported what is missing. I suggest creating two children of LookupError and return a corresponding error. What do you think?
I'm ready to implement this.

Correct Readme

Thanks for the tool.

This one does not work for me:

pybase16 inject -s schemes/default/ocean.yaml -f ~/.gtkrc-2.0.mine -f ~/.config/dunst/dunstrc -f ~/.config/i3/config -f ~/.config/termite/config -f ~/.config/zathura/zathurarc

scheme file not found like that.

Should be like in your travis test:

cd <your_base_dir>
pybase16 inject -s ocean -f ~/.gtkrc-2.0.mine -f ~/.config/dunst/dunstrc -f ~/.config/i3/config -f ~/.config/termite/config -f ~/.config/zathura/zathurarc

and to really make it clear maybe a non default one:

pybase16 inject -s black-metal-burzum -f /home/gk/.Xresources

apropos .Xresources - too minor for an issue imho, just a big ugly:
The tool swallows the last newline, at least in .Xresources type of target file, resulting in:

/home/gk/.Xresources:59: warning: End of input with no newline, supplemented newline

when xrdb ~./Xresources is run after injection. Not a big deal here but I think it should be corrected. Thanks again.

Update to base16 0.9.1

I've just cloned master in order to give this base16-builder business a try (it looks great) and seem to have run into a bug.

I ran these commands successfully:

$ python3 -mvenv .
$ . ./bin/activate
$ pip install
$ pybase16 update

Then I did the build, which mostly worked. It printed this part-way through its output, before hanging:

$ pybase16 build
Building colorschemes for scheme "Material Vivid"…
Building colorschemes for scheme "Tomorrow"…
Building colorschemes for scheme "Tomorrow Night"…
Building colorschemes for scheme "Mocha"…
Building colorschemes for scheme "Ocean"…
Building colorschemes for scheme "Rebecca"…
Exception in thread Thread-38:
Traceback (most recent call last):
  File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.7/threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "/home/graham/tmp/base16/base16-builder-python/lib/python3.7/site-packages/pybase16_builder/builder.py", line 161, in build_single_worker
    build_single(scheme_file, templates, base_output_dir)
  File "/home/graham/tmp/base16/base16-builder-python/lib/python3.7/site-packages/pybase16_builder/builder.py", line 126, in build_single
    format_scheme(scheme, scheme_slug)
  File "/home/graham/tmp/base16/base16-builder-python/lib/python3.7/site-packages/pybase16_builder/builder.py", line 99, in format_scheme
    int(scheme['{}-hex-r'.format(base)], 16))
ValueError: invalid literal for int() with base 16: '#2'

Built colorschemes for scheme "Summerfruit Light".
Built colorschemes for scheme "Heetch Light".
Built colorschemes for scheme "Mexico Light".
Built colorschemes for scheme "Synth Midnight Dark".
Built colorschemes for scheme "One Light".

There's one process and 39 threads, and I suspect they're all blocked because the main thread is waiting for that thread that couldn't parse its input?

Let me know if you need any more info. It doesn't look like it matters, but this is with Python 3.7.3 on Pop!_OS 19.04.

Cheers!

Python <3.6 compatibility

In my opinion, the prettiness of f-strings doesn't outweigh the ability to run this script on Debian Stable.
Here's a patch that removes f-strings, making this compatible with Python 3.5:

diff --git a/pybase16_builder/builder.py b/pybase16_builder/builder.py
index cee6ad0..9f0bf68 100644
--- a/pybase16_builder/builder.py
+++ b/pybase16_builder/builder.py
@@ -26,7 +26,7 @@ class TemplateGroup(object):
         templates = get_yaml_dict(config_path)
         for temp, sub in templates.items():
             mustache_path = os.path.join(get_parent_dir(config_path),
-                                         f'{temp}.mustache')
+                                         temp+'.mustache')
             sub['parsed'] = get_pystache_parsed(mustache_path)
         return templates
 
@@ -90,18 +90,18 @@ def format_scheme(scheme, slug):
     scheme['scheme-slug'] = slug
     bases = ['base{:02X}'.format(x) for x in range(0, 16)]
     for base in bases:
-        scheme[f'{base}-hex'] = scheme.pop(base)
-        scheme[f'{base}-hex-r'] = scheme[f'{base}-hex'][0:2]
-        scheme[f'{base}-hex-g'] = scheme[f'{base}-hex'][2:4]
-        scheme[f'{base}-hex-b'] = scheme[f'{base}-hex'][4:6]
-
-        scheme[f'{base}-rgb-r'] = str(int(scheme[f'{base}-hex-r'], 16))
-        scheme[f'{base}-rgb-g'] = str(int(scheme[f'{base}-hex-g'], 16))
-        scheme[f'{base}-rgb-b'] = str(int(scheme[f'{base}-hex-b'], 16))
-
-        scheme[f'{base}-dec-r'] = str(int(scheme[f'{base}-rgb-r']) / 255)
-        scheme[f'{base}-dec-g'] = str(int(scheme[f'{base}-rgb-g']) / 255)
-        scheme[f'{base}-dec-b'] = str(int(scheme[f'{base}-rgb-b']) / 255)
+        scheme[base+'-hex'] = scheme.pop(base)
+        scheme[base+'-hex-r'] = scheme[base+'-hex'][0:2]
+        scheme[base+'-hex-g'] = scheme[base+'-hex'][2:4]
+        scheme[base+'-hex-b'] = scheme[base+'-hex'][4:6]
+
+        scheme[base+'-rgb-r'] = str(int(scheme[base+'-hex-r'], 16))
+        scheme[base+'-rgb-g'] = str(int(scheme[base+'-hex-g'], 16))
+        scheme[base+'-rgb-b'] = str(int(scheme[base+'-hex-b'], 16))
+
+        scheme[base+'-dec-r'] = str(int(scheme[base+'-rgb-r']) / 255)
+        scheme[base+'-dec-g'] = str(int(scheme[base+'-rgb-g']) / 255)
+        scheme[base+'-dec-b'] = str(int(scheme[base+'-rgb-b']) / 255)
 
 
 def slugify(scheme_file):

Update doesn't find git executable

From windows cmd, I run pybase16 update, and get Git executable not found in $PATH. Git is in my path. Typing git into cmd, I get the help text. If I open python and run

import subprocess
subprocess.Popen('git')

I get the git help text. However, if I run:

import shutil
if not shutil.which('git'):
    print('No git!')

I get 'No git!'

I'm not sure why shutil can't find my git executable yet subprocess can. Either way, it's causing the script to fail

Return non-zero code on an error

The program at the moment returns 0 even if an error has occurred. It would be useful to return a non-zero code on an error so it is possible to take any action in case of a failure.

For example, I have a script that uses inject to update configs and then reloads all corresponding programs. I would like to avoid reloading if the injection wasn't successful. At the moment, I'm just checking the output, which clearly isn't a good solution.

It also would be more correct if all error messages were written to stderr, not stdout.

Workflow: How to ?

Hello!

Thank your work on this builder. It's amazing to produce so many themes with your tool 👍

I'm mainting base16-qutebrowser and would like to ask you about a good workflow with base16-builder-python.

My folder structure

  • base16-qutebrowser
    • templates
      • config.yaml
      • default.mustache
    • themes
      • base16-3024.config.py
      • ...
      • base16-zenburn.config.py

Desired workflow

  • use pybase16 to update all schemes from https://github.com/chriskempson/base16-schemes-source.
  • use pybase build [options] to generate all themes by reading base16-qutebrowser/templates/config.yaml and base16-qutebrowsertemplates/default.mustache and storing them in base16-qutebrowser/themes.

Current workflow

I use the following Makefile:

BUILD=pybase16
TEMPLATE=qutebrowser
THEME_FOLDER=themes
OUTPUT=output

all: update build

update: 
	$(BUILD) update
build:
	$(BUILD) build -t ${TEMPLATE} -o ${OUTPUT}
	rm -r ${THEME_FOLDER}
	mv ${OUTPUT}/${TEMPLATE}/themes/ ${THEME_FOLDER}/
	rm -r ${OUTPUT}

Problem:

pybase update downloads all templates to base16-qutebrowser/templates/, e.g. base16-qutebrowser/templates/qutebrowser/ as well. Beside the fact, that I don't need all templates, it clones my own repo with the (old) default.mustache as well. This is rather confusing and the old cloned default.mustache is used to generate all templates.

So I would like to be able to only update the schemes (not the templates) sources and/or specify which default.mustache it has to use.

Is this already possible? Otherwise it would be a very cool feature!

Thank you very much!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.