Skip to main content

Import refactoring package and pylsp plugin

Project description

Starkiller

CI status

Work in progress

An import refactoring package and python-lsp-server plugin. Starkiller aims to be static, i.e. to analyse source code without actually executing it, and fast, thanks to built-in ast module.

The initial goal was to create a simple linter to get rid of star imports, hence the choice of the package name.

Using as a package

Starkiller can be used as a package for import refactoring. Each public method and class has a docstring explaining what it does and how to use it.

Python LSP Server plugin

The pylsp plugin provides the following code actions to refactor import statements:

  • Replace * with explicit names - suggested for from ... import * statements.
  • Replace * import with module import - suggested for from ... import * statements.
  • Replace from import with module import - suggested for from ... import ... statements.
  • Replace module import with from import - suggested for import ... statements.
  • Remove unnecessary import - suggested for import statements with unused names.

To enable the plugin install Starkiller in the same virtual environment as python-lsp-server with [pylsp] optional dependency. E.g., with pipx:

pipx inject python-lsp-server starkiller[pylsp]

The plugin is enabled just the same way as any other pylsp plugin. E.g., in Neovim via lspconfig:

require("lspconfig").pylsp.setup {
    settings = {
        pylsp = {
            plugins = {
                starkiller = { enabled = true },
                aliases = {
                    numpy = "np",
                    [ "matplotlib.pyplot" ] = "plt",
                }
            }
        }
    }
}

Comma separated package imports

Multiple package imports like in the following example do not trigger any Code Actions right now:

import os, sys

This is hard to understand which import the user wants to fix here: os, sys or both. Splitting imports to different lines would help, but the user has to do it manually or with some other tool like Ruff. Starkiller is not a code formatter and should not handle import splitting.

At some point this might change. For example, a separate Code Action for each package could be suggested.

Alternatives and inspiration

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

starkiller-0.1.2.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

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

starkiller-0.1.2-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file starkiller-0.1.2.tar.gz.

File metadata

  • Download URL: starkiller-0.1.2.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for starkiller-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e508635cbf54a88eda5bad89e7f86471268cd1135eaa5f76eabac594368a45dd
MD5 89d6fb4620afbed763864dbeb2917411
BLAKE2b-256 7c5947faa4c991a4e828e397e219e0e0abc61ca916a7637b34c982d40ef2f789

See more details on using hashes here.

File details

Details for the file starkiller-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: starkiller-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for starkiller-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 88d70a2b3e6f50ca040ed5bcdf7733cc6c43ea8fe6a93f297b37b7480c60e48a
MD5 129b5d24ea19078a39251e8e0e9f0112
BLAKE2b-256 8ae9710de332022b3cf59dc7f27a64f59899582b2e2cfb4880b70b2f82697980

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