Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[build-system]
requires = ["setuptools>=60.5", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "colint"
version = "0.1"
description = ""
authors = [
{ name = "Davide Colì", email = "davide.coli@secomind.com" },
]
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"black>=25.1.0",
"exceptiongroup>=1.2.2",
"flake8-docstrings>=1.7.0",
"GitPython>=3.1.43",
"ipykernel>=6.29.5",
"isort>=6.0.1",
"tokenize-rt>=6.0.0",
"toml>=0.10.2",
"tomli>=2.0.1",
"typing-extensions>=4.12.2",
]

[project.scripts]
colint = "colint.colinter:main"

[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools.package-data]
"colint" = ["*.toml"]
48 changes: 0 additions & 48 deletions requirements.txt

This file was deleted.

18 changes: 0 additions & 18 deletions setup.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion colint/colinter.py → src/colint/colinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .params.params import Params
from .sort_libraries.sorter import sort_imports

config_file = Path(__file__).parent / "pyproject.toml"
config_file = Path(__file__).parent / "config.toml"
params = Params.from_toml(config_file)

COMMANDS = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import io
import os
from pathlib import Path

import isort

from ..params.isort_params import IsortParams
from ..utils.jupyter_utils import JupyterNotebokParser
from ..utils.os_utils import get_valid_files
from ..utils.os_utils import get_git_repo, get_valid_files
from ..utils.text_styling_utils import TextModifiers, style_text

FILE_SORTED_MESSAGE = "! File has been sorted: "
Expand Down Expand Up @@ -89,6 +90,12 @@ def sort_imports(path: str, only_check: bool, params: IsortParams) -> bool:
bool: Boolean indicating if any imports have been sorted in any file.
"""
files = get_valid_files(path)
git_repo = get_git_repo(path)
current_directory = os.getcwd()

if git_repo is not None:
new_dir = Path(git_repo.git_dir).parent.absolute()
os.chdir(str(new_dir))

some_file_has_been_sorted = False

Expand Down Expand Up @@ -125,4 +132,7 @@ def sort_imports(path: str, only_check: bool, params: IsortParams) -> bool:
if file_not_linted:
print(__style_message(f, only_check))

if os.getcwd() != current_directory:
os.chdir(current_directory)

return some_file_has_been_sorted
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 7 additions & 3 deletions colint/utils/os_utils.py → src/colint/utils/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ def get_valid_files(path: str | Path) -> list[str]:
str(f) for f in Path(path).rglob("*") if f.is_file() and ".git" not in f.parts
]

valid_files = set(files)

if repo: # If a git repository exists, remove files in gitignore
repo_ignore = set(repo.ignored(files))
files = list(set(files).difference(repo_ignore))
batch_size = 100
for k in range(0, len(files), batch_size):
repo_ignore = set(repo.ignored(files[k : k + batch_size]))
valid_files.difference_update(repo_ignore)

return sorted(files)
return sorted(list(valid_files))