Skip to content

Instantly share code, notes, and snippets.

@teitei-tk
Created July 13, 2016 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teitei-tk/dfe09fc0cb843d59aaf98f4a96d60009 to your computer and use it in GitHub Desktop.
Save teitei-tk/dfe09fc0cb843d59aaf98f4a96d60009 to your computer and use it in GitHub Desktop.
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
# console.log "Saved! #{editor.getPath()}"
util = require 'util'
fs = require 'fs'
class FileUtil
@isFile = (path) ->
return fs.existsSync(path) and fs.statSync(path).isFile()
@isDir = (path) ->
return fs.existsSync(path) and fs.statSync(path).isDirectory()
########################################
# autocomplete-python
########################################
# autocomplete-python setting is apply setting of each project
# TODO:
# * check anyenv is installed.
# * apply .python-version of each project.
# * apply pyenv version for .python-version of each project.
# * if .python-version does not exist, apply of global version.
# * global-version exist at $HOME/.anyenv/envs/pyenv/version
pyEnvRoot = process.env.PYENV_ROOT
if pyEnvRoot and FileUtil.isDir pyEnvRoot
localVersionPath = util.format '%s/.python-version', atom.project.getPaths()[0]
globalVersionPath = util.format '%s/version', pyEnvRoot
applyVirtualEnv = (filePath) ->
require('child_process').exec(util.format('cat %s', filePath), (err, stdout, stderr) ->
version = stdout.trim()
if not version
return
atom.config.set 'autocomplete-python.pythonPaths', util.format('%s/shims/python', pyEnvRoot)
atom.config.set 'autocomplete-python.extraPaths', util.format('%s/versions/%s/lib/python2.7/site-packages', pyEnvRoot, version)
)
if FileUtil.isFile localVersionPath
applyVirtualEnv localVersionPath
else if FileUtil.isFile globalVersionPath
applyVirtualEnv globalVersionPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment