Configure IPython from jupyter_client.manager - ipython

How can i add configurations to start a kernel via jupyter_client.manager.start_new_kernel() without setting up a default configuration file in .ipython directory? I want to set shell colors to 'NoColor' without setting up a config file and initialize specific formatters.
This is equivalent to the following config file:
c = get_config()
c.InteractiveShell.colors = 'NoColor'

This worked: manager.start_new_kernel(extra_arguments=["--colors='NoColor'"])

Related

How can I use a system environment variable inside a pyramid ini file?

I exported a variable called DBURL='postgresql://string'and I want to use it in my configuration ini file, e.g::
[app:kotti]
sqlalchemy.url = %(DBURL)s
That's not working.
Put this in your __init__.py:
def expandvars_dict(settings):
"""Expands all environment variables in a settings dictionary."""
return dict((key, os.path.expandvars(value)) for
key, value in settings.items())
Then when you export an environment variable to your shell, the proper syntax is this:
sqlalchemy.url = ${DBURL}
Once you have that environment variable set within your .ini, then you can use the configparser syntax:
sqlalchemy.connection = %(sqlalchemy.url)s%(user:pass and other stuff)s
Idea stolen from https://stackoverflow.com/a/16446566/2214933
PasteDeploy (the ini format pyramid is using here) does not support reading directly from environment variables. A couple common options are:
1) Set that option yourself in your main.
import os
def main(global_config, **settings):
settings['sqlalchemy.url'] = os.environ['DBURL']
config = Configurator(settings=settings)
...
2) Define your ini file as a jinja2 template and have a command to render it out to ini format, and just run that as part of your deploy process.

How to save ipython alias forever?

I am a bit confused on how to save ipython alias so that everytime i open a ipython session(after saving alias firstly ) and use the alias command directly(at the point,you should not input the alias again ).
For example,when use ipython in linux(or windows) ,i would use vi rather than !vi a file .
vi fileneme
!vi filename
To generate the default configuration files ipython_config.py in your IPython directory under profile_default :
$ ipython profile create
Find ipython_config.py in linux/windows
#use find command in linux
find / -name ipython_config.py
#in window,you can use all kinds of tools to search .
#in commands line,you can use
ipython locate profile.
#in the directory,you can get it
Edit the ipython_config.py file to add the fellowing content
c = get_config()
c.TerminalIPythonApp.display_banner = True
c.InteractiveShellApp.log_level = 20
c.InteractiveShellApp.extensions = []
c.InteractiveShellApp.exec_lines = []
c.InteractiveShellApp.exec_files = ['mycode.py']#load Module when open ipython
c.InteractiveShell.autoindent = True
c.InteractiveShell.colors = 'LightBG'#ipython console color
c.InteractiveShell.confirm_exit = False
c.InteractiveShell.editor = 'vim'#you can change your favorite editor
c.InteractiveShell.xmode = 'Context'
c.PrefilterManager.multi_line_specials = True
#you can add your alias in the fellowing list
c.AliasManager.user_aliases = [('vi','vim'),('py','python'),('git','git'),]#i add git ,vim python .i really dislike "!"
Save the file and exit and get it
thx#jack yang
1.
emacs ~/.ipython/profile_default/python_config.py
2.in the end wirte down
c.AliasManager.user_aliases = [('e', 'emacsclient -t')]
3.exit and restart ipython

Scala Config: Include another file.conf

Currently, I have a resources/application.conf file which has the following keys:
development {
server = www.myapp.com
aws_key = my_aws_key
aws_secret = my_aws_secret
}
I would like to remove my aws_key and aws_secret from the file.
I was thinking of creating another file called resources/credentials.conf and storing my personal authentications there.
credentials {
aws_key = my_aws_key
aws_secret = my_aws_secret
}
and then include it some way in my application.conf or merge that config to the Config object in addition to application.conf.
credentials.conf would be git ignored. A sample file would be checked in credentials-sample.conf which each developer would change according to his own credentials and rename the sample file to credentials.conf
I tried different variation of include like
include "credentials"
include "credentials.conf"
include "./credentials.conf"
include file("./credentials.conf")
and so on.
I know I can pass it via system variables but I would like to try it like mentioned above. If you know of a better way, please let me know.
Typesafe Config provide the way to fallback from one configuration to another. You can try the ConfigFactory.Load() to load different config and use withFallback to line them up in your designated order. Such as:
ConfigFactory.Load("credentials.conf") withFallback ConfigFactory.Load("application.conf")
Inside your conf file, add
include "another_file.conf"
ie: https://github.com/cicco94/scala-akka-slick-demo/blob/master/src/main/resources/application.conf

IPYTHON: adding a new folder to searchable template locations for `nbconvert`

The IPYTHON documentation implies there is a way to modify the config file to include an additional path for templates.
Please advise. I have a template file which I want to use, with extension *.tpl which I do not want to have to move around to the local directory of where I do my work.
Any tips? I've searched everywhere and can't find this. It seems to only search the local directory where I am running the ipython nbconvert test.ipynb --to slides --template output_toggle_html.
Thanks.
In the ipython_nbconvert_config.py file located , you can enter the line c.TemplateExporter.template_path = ['.'] which will do the same as the default behavior, however you can add to this list. For example, the code below adds $IPYTHONDIR/nbextensions/templates and will search for *.tpl files in those locations, in the order in which they are provided in the list.
from os import environ
IPYTHONDIR = environ["IPYTHONDIR"]
template_rel_path = '/nbextensions/templates'
template_path = IPYTHONDIR + template_rel_path
c.TemplateExporter.template_path = [
'.',
template_path
]

Setting output_style for SCSS using Compass in Sinatra app

I'm looking at the Compass-Sinatra starter file on GitHub. Is there a way to set the output_style for an scss file in Sinatra? Ideally I would like to set the style to :expanded when in development.
I think I'm having trouble understanding how sass(:"stylesheets/#{params[:name]}", Compass.sass_engine_options ) works and where I can set those options.
I found that adding the output_style setting to the compass.config file works for changing the output_style. It can either go in the if defined?(Sinatra) block or in the configuration block at the bottom of the compass.config file.
# compass-sinatra-starter/config/compass.config
if defined?(Sinatra)
# This is the configuration to use when running within sinatra
project_path = Sinatra::Application.root
environment = :development
output_style = :expanded # This is where you can set the output_style
else
# this is the configuration to use when running within the compass command line tool.
css_dir = File.join 'static', 'stylesheets'
relative_assets = true
environment = :production
end
# Or if you wanted to have the output_style set for all environments(?)
# This is common configuration
output_style = :compressed
sass_dir = File.join 'views', 'stylesheets'
images_dir = File.join 'static', 'images'
http_path = "/"
http_images_path = "/images"
http_stylesheets_path = "/stylesheets"
Note: stop/start the server if you change the settings if you don't see the change.
For example, I have a styles.scss file in views/stylesheets/styles.scss then if I go to http://localhost:4567/stylesheets/styles.css I'll get the .scss file compiled in the browser to .css. Changing the output_style, start/stop the server the .css output_style changes. I don't know if using reloader would work, but it might avoid the stop/start?
I found a couple of other good resources.
Andrew Stewart has a blog post and a GitHub template
Originally I was trying to learn about media queries in Sass(scss) with Sinatra and found a great video Ben Schwarz posted, but it doesn't go into the nitty gritty of setting up. It's more about the media query. Ben also has the source on GitHub.
But it seems like AssetPack is the best way to go for serving assets.