Skip to main content

A language server / linter for the Tryton framework

Project description

Tryton Analyzer

What's this

tryton-analyzer is a dedicated Language Server / Linter to assist developers using the tryton framework.

Due to how the framework operates (most notably the runtime inheritance), the standard Python tooling is not as useful as it can / should be. This means that most errors that could be detected by a linter (unknown attributes, etc.) are not, which leads to runtime / production errors.

Disclaimer

This is just a hobby project for now, and though it is already useful, it requires a patched trytond (on version 6.8).

It is only tested on Neovim, though it should work on other editors supporting the Language Server Protocol.

How does it work

It uses pygls to handle the language server protocol, libcst to parse the sources, and a patched trytond to be able to load modules without any database whatsoever.

The language server itself spawns and requests informations from separate trytond processes to be able to survive Syntax Errors in the source code.

What can it do

Focus so far has been on basic things:

  • Detecting unkown attributes (python / xml)
  • Completion
  • Support of extras_depend to distinguish available models / fields even in a given module

Model detection is done through parsing of the syntax tree using libsct. It relies on:

  • self / cls for obvious reasons
  • Special function parameters (for instance, the second argument of validate will always be a list of records)
  • Parsing of Pool().get calls
  • Custom type annotations: def my_function(self, invoices: Records["account.invoice"]), though this does not play well with other linters who interpret "account.invoice" as a type that obviously does not exist

There are a few very specific checks that are implemented because of past trauma :)

  • Do not call super on a function without a parent
  • Forgetting a super call

What will it do

I have a lot of things I would like to do next:

  • Global ignore list via tox.ini
  • Return type annotations
  • Extract more informations from the tryton pool (identify getters & co to automatically assign types to parameters, identify from super calls)
  • Domain / state parsing
  • Jump to definition
  • Better information for fields during completion
  • Find usages of fields / methods (though this one will probably be difficult and need some sort of persistent caching)
  • Detect register / depends missing a extras_depend

Give it a try

pip install tryton-analyzer, and setup your development environment to use the patched trytond rather than the default one.

On the client side, use lspconfig for Neovim:

  local lspconfig = require("lspconfig")
  local configs = require'lspconfig.configs'
  if not configs.tryton_analyzer then
    configs.tryton_analyzer = {
      default_config = {
        cmd = { 'tryton-ls' },
        filetypes = {'python', 'xml'},
        root_dir = lspconfig.util.root_pattern(".git"),
        settings = {},
      };
    }
  end
  lspconfig.tryton_analyzer.setup{}

You should be good to go.

The tryton-lint script allows to lint a tryton module as a whole.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tryton_analyzer-0.1.0.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tryton_analyzer-0.1.0-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file tryton_analyzer-0.1.0.tar.gz.

File metadata

  • Download URL: tryton_analyzer-0.1.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.1 Linux/6.2.0-39-generic

File hashes

Hashes for tryton_analyzer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 829fbd178a9a5ccaa0413ce376e058d19b3c91b788e9376d8cedd7818cbc0a58
MD5 626484435eede4d6fcf7f851697abb2c
BLAKE2b-256 a98b5f38ef6bdc9e705a72a6bf2f0660e4b7320ff798c6936fffab4a43dda089

See more details on using hashes here.

File details

Details for the file tryton_analyzer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tryton_analyzer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.1 Linux/6.2.0-39-generic

File hashes

Hashes for tryton_analyzer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd6893ad15abdf6f39098b8d2913bf0342fdcd678cfcd6f5e06a4bce772a6d08
MD5 6d3dc34ff121e393ff1f7a916190c7c1
BLAKE2b-256 48b3797f7000214200015e17c3e6683a60fc7770593fe46a7f265b9ac7cb1dae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page