python tool that will fix your missing imports
Project description
PyFix-Imports
WIP Python library which fixes missing imports, It automatically fixes missing imports by importing them I mostly wrote this to learn more about python, and wanted to make something with.
https://github.com/Rishabh672003/fix-imports/assets/53911515/941f0b59-a4d0-498f-89a4-0104a2eae92f
Installation
Just run pip install pyfix-imports
Usage
pyfix-imports <FILEPATH> # returns the fixed code to the stdout
pyfix-imports -f <FILEPATH> # Writes the fixed code to the file
pyfix-imports -c <CONFIGPATH> <FILEPATH> # uses the config file
I recommend after running the program use isort or ruff to sort the imports.
Configuration
The default configuration file should be placed in $XDG_CONFIG_HOME/pyfix-imports/config.toml
or you can place your config file anywhere and just provide the path to the command fix-imports -c <Path>
the structure should be like this, don't forget to include [config] on the top
[config]
"tf" = "import tensorflow as tf"
"plt" = "import matplotlib.pyplot as plt"
"isprime" = "from sympy import isprime"
How I use it
As they say necessity is the mother of invention, also python language server like, pyright and pylsp don't do that good of a job, that gave me the motivation to made this. I use this with the conjunction of black and isort within my neovim with conform.nvim you can also use it just put this in your conform setup
require("conform").setup({
formatters_by_ft = {
python = { "pyfix_imports", "ruff_fix", "ruff_organize_imports", "ruff_format", },
formatters = {
pyfix_imports = {
command = "pyfix-imports",
args = { "$FILENAME" },
cwd = require("conform.util").root_file({ "requirements.txt", "pyproject.toml" }),
},
}
})
References
I took many projects for reference/code
- autoimport I could have just used this, but I wanted to make something so took it as a reference and made this. I didn't took that much code from it, but yes as someone who has never made a decent size python project it was really helpful
- autoflake I wanted to use pyflakes to get the errors in code, and this one had great implementation of pyflake api.
- pyflakes Used this to get all the errors for undefined names.
- click Used this to make the command-line interface
- pdm Used this to structure and manage dependency for the project
- xdg-base-dirs Used this to get the config file
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfix_imports-0.7.2.tar.gz.
File metadata
- Download URL: pyfix_imports-0.7.2.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.17.1 CPython/3.12.4 Linux/6.10.3-zen1-2-zen
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a661ab2ac0157b9c9157116d958eaa9cf9266968fbbdbc55095ca8ffe78ee262
|
|
| MD5 |
cc03f00971396a5fbe4554ef93aec7c2
|
|
| BLAKE2b-256 |
0172d49eef7f6ce4236fba1aee477919130ba1e22d59bd2c2aa24f2cb6d785c2
|
File details
Details for the file pyfix_imports-0.7.2-py3-none-any.whl.
File metadata
- Download URL: pyfix_imports-0.7.2-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.17.1 CPython/3.12.4 Linux/6.10.3-zen1-2-zen
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88ca3ba2c0e996ef29e67d2600d0e5ac835543fae60d0c2c734df07ff59c6062
|
|
| MD5 |
fbb6564dd20a6efd27bc70f7c15bf04b
|
|
| BLAKE2b-256 |
fec9f86874a3373527e820cdea76dc3510707a69811864ff9a7f1e885f50b6ab
|