HLab

Julien Hautefeuille

Sublime Text 2 et Python

Cet article est un pense-bête de ma configuration.

J’utilise la version Sublime Text 2.0.1 Build 2217.

J’ai installé les plugins Sublime Text 2 suivants propres à mes besoins en Python :

  • Package Control, le premier paquet à installer, car il vous permet d’installer les suivants,
  • Pylinter,
  • PySide,
  • Python Test Runner,
  • Sublime REPL,
  • Sublime ROPE.

Lancer un script Python avec argument

L’argument est ici “update”. Il suffit de créer un “Build” customisé.

pythoncustom.sublime-build :

{
"cmd": ["python", "-u", "$file", "update"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}

Aider Pylint à trouver le path de votre script

Ajoutez le path menant à votre script ou à vos éventuelles bibliothèques.

Ici il s’agit d’ajouter le chemin au path Python : /home/julien/projectfolder.

Pylinter.sublime-setting :

{
// When versbose is 'true', various messages will be written to the console.
// values: true or false
"verbose": false,
// The full path to the Python executable you want to
// run Pylint with or simply use 'python'.
"python_bin": "python",
// The following paths will be added Pylint's Python path
"python_path": [ "/home/julien/projectfolder"],
// Optionally set the working directory
"working_dir": null,
// Full path to the lint.py module in the pylint package
"pylint_path": null,
// Optional full path to a Pylint configuration file
"pylint_rc": null,
// Set to true to automtically run Pylint on save
"run_on_save": true,
// Set to true to use graphical error icons
"use_icons": false,
// Ignore Pylint error types. Possible values:
// "R" : Refactor for a "good practice" metric violation
// "C" : Convention for coding standard violation
// "W" : Warning for stylistic problems, or minor programming issues
// "E" : Error for important programming issues (i.e. most probably bug)
// "F" : Fatal for errors which prevented further processing
s"ignore": []
}

Ajouter un snippet Bottle Python

bottle.sublime-snippet :

<snippet>
<content><![CDATA[
import bottle

@bottle.route('/')
def index():
    return "hello"

if "__main__" == __name__:
    bottle.debug(True)
    bottle.run(host=${1:host}, port=${2:port})

]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>bottle</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> -->