Skip to content

Commit

Permalink
fixed description
Browse files Browse the repository at this point in the history
  • Loading branch information
kaliv0 committed May 16, 2024
1 parent fff63c8 commit b32bd06
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 26 additions & 10 deletions clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from enum import Enum, auto
from typing import TextIO


__version__ = "0.0.3"
__version__ = "0.0.4"


# ### constants ###
Expand Down Expand Up @@ -126,7 +125,9 @@ def set_up(self, file: str) -> None:
self.import_lines = []

# ### main logic ###
def process_paths(self, path_list: list[str], dir_level: str, verbose: bool) -> None:
def process_paths(
self, path_list: list[str], dir_level: str, verbose: bool
) -> None:
for path in path_list:
if path != Tokens.CWD:
path = os.path.join(dir_level, path)
Expand Down Expand Up @@ -207,7 +208,9 @@ def _get_multiline_imports(self, i: int) -> tuple[int, list[str]]:
i += 1
return i, imported

def _handle_non_analysed_imports(self, line_literal: str, line_type: ImportLineType) -> None:
def _handle_non_analysed_imports(
self, line_literal: str, line_type: ImportLineType
) -> None:
self.import_lines.append(
ImportLine(
literal=line_literal,
Expand Down Expand Up @@ -241,7 +244,11 @@ def _handle_import_line(self, line_literal: str, import_list: list[str]) -> None
literal=line_literal,
import_data=[],
import_list=[],
type=ImportLineType.MULTI_IMPORT if len(import_list) > 1 else ImportLineType.REGULAR,
type=(
ImportLineType.MULTI_IMPORT
if len(import_list) > 1
else ImportLineType.REGULAR
),
)
for import_literal in import_list:
import_data = ImportData(name=import_literal.strip(), count=0)
Expand Down Expand Up @@ -292,14 +299,17 @@ def _write_import_line(self, file_writer: TextIO, line: ImportLine) -> int:
if line.type in (ImportLineType.ALIAS, ImportLineType.COMMENT):
file_writer.write(line.literal)
else:
file_writer.write(self._prepare_import_line(line.literal, line.import_list))
file_writer.write(
self._prepare_import_line(line.literal, line.import_list)
)
return 1 # returns number of written lines
return 0

@staticmethod
def _should_write_import_line(line: ImportLine) -> bool:
return line.type == ImportLineType.COMMENT or not (
line.type == ImportLineType.MULTI_IMPORT or line.type == ImportLineType.NEW_LINE
line.type == ImportLineType.MULTI_IMPORT
or line.type == ImportLineType.NEW_LINE
)

@staticmethod
Expand All @@ -321,11 +331,17 @@ def read_input() -> tuple[list[str], list[str], bool]:
parser.add_argument(
"target", nargs="+", help="path or list of paths to file or directory to parse"
)
parser.add_argument("--skip", nargs="*", default=(), help="target path or paths to skip")
parser.add_argument(
"--verbose", action="store_true", help="verbose output that includes skipping paths"
"--skip", nargs="*", default=(), help="target path or paths to skip"
)
parser.add_argument(
"--verbose",
action="store_true",
help="verbose output that includes skipping paths",
)
parser.add_argument(
"-v", "--version", action="version", version=f"%(prog)s {__version__}"
)
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}")

args = parser.parse_args()
path_list = args.target
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ requires = ["setuptools>=68.2.0", "wheel"]

[project]
authors = [{name = "kaliv0"}]
description = "Import cleaner"
description = "Unused imports cleaner"
name = "iclean"
readme = "README.md"
license = {file = "LICENSE"}
Expand All @@ -16,4 +16,4 @@ requires-python = ">=3.10"
version = {attr = "clean.__version__"}

[project.scripts]
iclean = "clean:main"
iclean = "clean:main"

0 comments on commit b32bd06

Please sign in to comment.