All Projects → MarcoGorelli → Absolufy Imports

MarcoGorelli / Absolufy Imports

Licence: mit
Automatically convert between relative and absolute imports

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Absolufy Imports

eslint-plugin-import
ESLint plugin with rules that help validate proper imports.
Stars: ✭ 4,290 (+12900%)
Mutual labels:  lint, import
lint-deps
Lint for unused or missing dependencies in your node.js projects. Customize with plugins or configuration.
Stars: ✭ 48 (+45.45%)
Mutual labels:  lint, import
Eslint Plugin Import
ESLint plugin with rules that help validate proper imports.
Stars: ✭ 3,722 (+11178.79%)
Mutual labels:  lint, import
Vint
Fast and Highly Extensible Vim script Language Lint implemented in Python.
Stars: ✭ 596 (+1706.06%)
Mutual labels:  lint
Elasticsearch Dump
Import and export tools for elasticsearch
Stars: ✭ 5,977 (+18012.12%)
Mutual labels:  import
Cfn nag
Linting tool for CloudFormation templates
Stars: ✭ 808 (+2348.48%)
Mutual labels:  lint
Trakt Letterboxd Import
Import Letterboxd movie list (diary) into trakt.tv
Stars: ✭ 29 (-12.12%)
Mutual labels:  import
Lazy importer
library for importing functions from dlls in a hidden, reverse engineer unfriendly way
Stars: ✭ 544 (+1548.48%)
Mutual labels:  import
Httpolice
Validator for HTTP
Stars: ✭ 948 (+2772.73%)
Mutual labels:  lint
Remark Lint
Markdown code style linter
Stars: ✭ 718 (+2075.76%)
Mutual labels:  lint
Ethlint
(Formerly Solium) Code quality & Security Linter for Solidity
Stars: ✭ 698 (+2015.15%)
Mutual labels:  lint
Php Parallel Lint
This tool check syntax of PHP files faster than serial check with fancier output.
Stars: ✭ 646 (+1857.58%)
Mutual labels:  lint
Feflow
🚀 A command line tool aims to improve front-end engineer workflow and standard, powered by TypeScript.
Stars: ✭ 942 (+2754.55%)
Mutual labels:  lint
Rubocop Rspec
Code style checking for RSpec files
Stars: ✭ 603 (+1727.27%)
Mutual labels:  lint
Eslint Import Resolver Jest
🃏 Jest import resolution plugin for eslint-plugin-import
Stars: ✭ 29 (-12.12%)
Mutual labels:  import
Blender Osm
One click download and import of OpenStreetMap and terrain for Blender! Global coverage! Source code is in the branch 'release'.
Stars: ✭ 588 (+1681.82%)
Mutual labels:  import
Eslint Plugin React
React specific linting rules for ESLint
Stars: ✭ 7,472 (+22542.42%)
Mutual labels:  lint
Rust Clippy
A bunch of lints to catch common mistakes and improve your Rust code
Stars: ✭ 6,720 (+20263.64%)
Mutual labels:  lint
Lint Md
📚 检查中文 markdown 编写格式规范的命令行工具,基于 AST,方便集成 ci,写博客 / 文档必备。支持 API 调用!
Stars: ✭ 662 (+1906.06%)
Mutual labels:  lint
Tslib
Runtime library for TypeScript helpers.
Stars: ✭ 762 (+2209.09%)
Mutual labels:  import

Build Status Coverage pre-commit.ci status

absolufy-imports

A tool and pre-commit hook to automatically convert relative imports to absolute.

demo

Installation

$ pip install absolufy-imports

Usage as a pre-commit hook (recommended)

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/MarcoGorelli/absolufy-imports
    rev: v0.3.0
    hooks:
    -   id: absolufy-imports

Command-line example

$ cat mypackage/myfile.py
from . import __version__
$ absolufy-imports mypackage/myfile.py
$ cat mypackage/myfile.py
from mypackage import __version__

Configuration

Application directories

If your package follows the popular ./src layout, you can pass your application directories via --application-directories, e.g.

$ cat src/mypackage/myfile.py
from . import __version__
$ absolufy-imports src/mypackage/myfile.py --application-directories src
$ cat src/mypackage/myfile.py
from mypackage import __version__

Multiple application directories should be comma-separated, e.g. --application-directories .:src. This is the same as in reorder-python-imports.

Only use relative imports

Use the --never flag, e.g.

$ cat mypackage/myfile.py
from mypackage import __version__
$ absolufy-imports mypackage/myfile.py --never
$ cat mypackage/myfile.py
from . import __version__

Keep submodules relative

Use the --keep-submodules-relative flag. By default, submodules are considered to be the first level of the directory. E.g. if you have

├── mypackage
│   ├── library1
│   │   ├── foo.py
│   │   └── subdirectory
│   │       ├── bar.py
│   │       └── baz.py
│   └── library2
│       └── qux.py

and

$ cat mypackage/library1/subdirectory/bar.py
from mypackage.library1.subdirectory import baz
from mypackage.library1 import foo
from mypackage.library2 import qux

then you will get

$ absolufy-imports mypackage/library1/subdirectory/bar.py --keep-submodules-relative
$ cat mypackage/library1/subdirectory/bar.py
from . import baz
from .. import foo
from mypackage.library2 import qux

To specify a custom list of submodules, you can use the --submodules flag, e.g.

$ absolufy-imports mypackage/library1/subdirectory/bar.py \
  --keep-submodules-relative \
  --submodules '{".": ["mypackage.library1", "mypackage.library2"]}'

Note that they need to be in json format, and the keys should be the application directories.

See also

Check out pyupgrade, which I learned a lot from when writing this.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].