Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #54 from ESSS/fb-52-fix-isort-settings-from-path
Browse files Browse the repository at this point in the history
  • Loading branch information
gcardozo123 authored Aug 14, 2020
2 parents 0a450db + b8f6d07 commit e948d04
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[settings]
known_standard_library=Bastion,CGIHTTPServer,DocXMLRPCServer,HTMLParser,MimeWriter,SimpleHTTPServer,UserDict,UserList,UserString,aifc,antigravity,ast,audiodev,bdb,binhex,cgi,chunk,code,codeop,colorsys,cookielib,copy_reg,dummy_thread,dummy_threading,formatter,fpformat,ftplib,genericpath,htmlentitydefs,htmllib,httplib,ihooks,imghdr,imputil,keyword,macpath,macurl2path,mailcap,markupbase,md5,mimetools,mimetypes,mimify,modulefinder,multifile,mutex,netrc,new,nntplib,ntpath,nturl2path,numbers,opcode,os2emxpath,pickletools,popen2,poplib,posixfile,posixpath,pty,py_compile,quopri,repr,rexec,rfc822,runpy,sets,sgmllib,sha,sndhdr,sre,sre_compile,sre_constants,sre_parse,ssl,stat,statvfs,stringold,stringprep,sunau,sunaudio,symbol,symtable,telnetlib,this,toaiff,token,tokenize,tty,types,user,uu,wave,xdrlib,xmllib
extra_standard_library=Bastion,CGIHTTPServer,DocXMLRPCServer,HTMLParser,MimeWriter,SimpleHTTPServer,UserDict,UserList,UserString,aifc,antigravity,ast,audiodev,bdb,binhex,cgi,chunk,code,codeop,colorsys,cookielib,copy_reg,dummy_thread,dummy_threading,formatter,fpformat,ftplib,genericpath,htmlentitydefs,htmllib,httplib,ihooks,imghdr,imputil,keyword,macpath,macurl2path,mailcap,markupbase,md5,mimetools,mimetypes,mimify,modulefinder,multifile,mutex,netrc,new,nntplib,ntpath,nturl2path,numbers,opcode,os2emxpath,pickletools,popen2,poplib,posixfile,posixpath,pty,py_compile,quopri,repr,rexec,rfc822,runpy,sets,sgmllib,sha,sndhdr,sre,sre_compile,sre_constants,sre_parse,ssl,stat,statvfs,stringold,stringprep,sunau,sunaudio,symbol,symtable,telnetlib,this,toaiff,token,tokenize,tty,types,user,uu,wave,xdrlib,xmllib
known_third_party=six,six.moves,sip
line_length=100
multi_line_output=4
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

3.0.0 (2020-08-14)
------------------

* Upgrade to ``isort 5``.

2.1.2 (2019-08-26)
------------------

Expand Down
2 changes: 1 addition & 1 deletion environment.devenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies:
- boltons
- clangdev>=6.0.1
- click>=6.0
- isort>=4.3.4
- isort>=5.0
- python={{ '.'.join(CONDA_PY) }}
- pydevf==0.1.5
- toml>=0.8.0
Expand Down
15 changes: 7 additions & 8 deletions src/esss_fix_format/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import boltons.iterutils
import click
import pydevf
from isort.exceptions import FileSkipComment

CPP_PATTERNS = {
'*.cpp',
Expand Down Expand Up @@ -313,21 +314,19 @@ def _process_file(filename, check, format_code, *, verbose):

if extension == '.py':
settings_path = os.path.abspath(os.path.dirname(filename))
settings_loaded = isort.settings.from_path(settings_path)
if settings_loaded['line_length'] < 80:
isort_config = isort.Config(settings_path=settings_path)
if isort_config.line_length < 80:
# The default isort configuration has 79 chars, so, if the passed
# does not have more than that, complain that .isort.cfg is not configured.
msg = ': ERROR .isort.cfg not available in repository (or line_length config < 80).'
error_msg = click.format_filename(filename) + msg
click.secho(error_msg, fg='red')
errors.append(error_msg)

sorter = isort.SortImports(file_contents=new_contents, settings_path=settings_path)
# On older versions if the entire file is skipped (eg.: by an "isort:skip_file")
# instruction in the docstring, SortImports doesn't even contain an "output" attribute.
# In some recent versions it is `None`.
new_contents = getattr(sorter, 'output', None)
if new_contents is None:
try:
new_contents = isort.code(new_contents, extension, config=isort_config)
except FileSkipComment:
# The entire file was skipped by an "isort:skip_file"
new_contents = original_contents

if format_code is not None:
Expand Down
6 changes: 3 additions & 3 deletions src/esss_fix_format/hook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def add_hook(parts_dir, git_hook):
:param GitHook|unicode git_hook: A git hook or its name. Name notation can only be used
by hooks available by default though (see `hooks` to learn more).
"""
from esss_fix_format.hooks import GitHook
from esss_fix_format.hooks import get_default_hook
import glob
import stat

from esss_fix_format.hooks import GitHook, get_default_hook

if not isinstance(git_hook, GitHook):
git_hook = get_default_hook(git_hook)

Expand All @@ -76,8 +76,8 @@ def install_pre_commit_hook(git_dir=None):
Install Git hooks in a project.
"""
import stat
import textwrap
import sys
import textwrap

# Creates a pre-commit file that runs other scripts located in `_pre-commit-parts` folder.
# This folder is (re)created every time hooks are installed. It runs all parts, even if one
Expand Down

0 comments on commit e948d04

Please sign in to comment.