Over a million developers have joined DZone.

Using Pylint in Sublime With Docker: Virtualenv [Snippet]

DZone's Guide to

Using Pylint in Sublime With Docker: Virtualenv [Snippet]

Love Python but don't love setting up a dev environment on your machine? Let's see how Docker and Virtualenv can help solve your problem.

· Cloud Zone ·
Free Resource

Learn how to migrate and modernize stateless applications and run them in a Kubernetes cluster.

Nowadays, Docker is so popular that engineers like to use it in both development and deployment. In the development process, you don't have to config your local machine with all those complicated dev environments. But you might not want to write code inside a Docker container. A lot of people choose to write code on their local machine with their IDEs, like Sublime.

And for Python developers, code style is important for both developers and those who read their code. So plenty of Python devs use Pylint to optimize code.

Problem: Pylint relies on a Python context, including the packages used in your project, or on your machine, or it will complain. However,  you might not want to set up a dev env on your local machine. So how do you make this work?

Solution: Virtualenv solves this problem. It can help create an isolated Python environment, so we can use Virtualenv to create a Python context and use the Pylint. Once we get the Python context, we just need to let Sublime use it. For that, you can install a Sublime plugin called Pylinter, but by default, it will look for the Python context on your local machine. So, you need to configure it to use the one in Virtualenv.

Image title

Below is an example configuration:

    // 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": "/path/to/virtualenv/bin/python",
    // The following paths will be added Pylint's Python path
    "python_path": [
    // Optionally set the working directory
    "working_dir": null,
    // Full path to the lint.py module in the pylint package
    "pylint_path": "/path/to/virtualenv/lib/python3.6/site-packages/pylint/lint.py",
    // Optional full path to a Pylint configuration file
    "pylint_rc": "/path/to/your/lint/file/.pylintrc",
    // Set to true to automtically run Pylint on save
    "run_on_save": true,
    // Set to true to use graphical error icons
    "use_icons": false,
    "disable_outline": false,
    // Status messages stay as long as cursor is on an error line
    "message_stay": 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
    "ignore": [],
    // a list of strings of individual errors to disable, ex: ["C0301"]
    "disable": [],
    "plugins": []

Join us in exploring application and infrastructure changes required for running scalable, observable, and portable apps on Kubernetes.

python ,virtualenv ,sublime ,docker ,cloud

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}