Setting up your local environment is one of the first things to do to maximize your productivity and unlock your full magical power. As a Python developer, there are several tools and configurations that you can use in your daily life to enhance your developer experience at Sourcery.
Keep in mind that this is a living document, don't refrain to propose changes to it - and to the way we do things at Sourcery.
Sourcery uses Pylint for Python code linting. We have pre-commit hooks that ensures compliance to Pylint when committing or pushing changes to the remote repository, and we also employ GitHub Actions to check for Pylint-correctness in our CI pipeline.
We use MyPy as our type-checker. Type correctness is also ensured when git-committing, git-pushing or running the CI.
To catch errors and get improved code autocompletion, we also recommend you to use MyPy as a Python linter in your editor or IDE: VS Code (there is also a plugin that you can install to get full workspace type analysis), PyCharm and Vim.
EditorConfig is a file specification and a collection of extensions/plugins that enable consistent coding styles for all developers working on a same project regardless of their editor or IDE of choice. Check out their docs - they have support for all major code editors, including, but not limited to, VS Code, PyCharm (built-in), Sublime Text and Vim.
Sourcery already has EditorConfig files in the core repositories - make sure to include one for any new repositories that you create. Also, feel free to submit pull requests to change this config file if you find room for improvements.
We use isort to automatically sort our import statements, and to check correct sorting in the CI and pre-commit hooks.
We employ Black to ensure that all code follows a standard formatting. Black is used for both autoformatting and checking.
To automatically fix code formatting as you write your code, we recommend you to use format-on-save, a feature present in many code editors and IDE such as VS Code (you can set Black as the default formatter for easier integration), PyCharm and Vim.
Extensions or plugins can be installed to make your code editor or IDE even more powerful. Some of the useful extensions we use at Sourcery are:
- Error Lens: extension for highlighting errors, warnings and language diagnostics inline with your code.
- Git Lens: improved Git integration, including inline git blame and special commands for committing, checking the repo status, and more.
- Python Docstring Generator: extension for easily generating docstrings. Additionally, take a look at their issue #121 for a discussion on how to generate docstrings for PEP 484 type-annotated functions.
TODO: write a template based on their template, but excluding type annotations.
Generally, you're encouraged to use any other tools that enhance developer happiness, experience, and velocity. :-) Info about these tools here or in one of the Slack channels is very welcome.
General guideline: It's OK to use tools that analyze the code in your local environment. Do not use any tools that send our code to the cloud (e.g. GitHub bots) without approval.