miki725 / importanize

Utility for organizing Python imports using PEP8 or custom rules
Other
66 stars 17 forks source link

Exclude file/dir not honored #62

Closed commentator8 closed 4 years ago

commentator8 commented 4 years ago

I tried excluding a directory and it was still processed. I then tried a specific file and the same occurred. How can i exclude an entire directory?

c:\CodeShare\dir>importanize --config=setup.cfg launcher/requirements/bcrypt/__init__.py -vv

Running importanize with RuntimeConfig(_paths=(), path_names=('launcher/requirements/bcrypt/__init__.py',), formatter_name=None, length=None, should_add_last_line=True, _config=None, root_config=[importanize] path=setup.cfg after_imports_new_lines=2 length=120 formatter=lines groups= stdlib sitepackages remainder local packages:db,gui exclude= launcher/requirements/bcrypt/*.py add_imports= allow_plugins=True plugins= unused_imports, config_path='setup.cfg', is_subconfig_allowed=True, are_plugins_allowed=None, should_deactivate_piped_plugins=None, found_configs={}, verbosity=2, is_version_mode=False, is_list_mode=False, is_ci_mode=False, show_diff=False, is_print_mode=False, show_header=True, is_in_piped=False, is_out_piped=False, stdin=<_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>, stdout=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>) Running with python c:\users\user\appdata\local\programs\python\python38-32\python.exe Installed plugins: separate_libs, unused_imports About to importanize launcher\requirements\bcrypt\__init__.py Found 15 imports in launcher\requirements\bcrypt\__init__.py Successfully importanized launcher\requirements\bcrypt\__init__.py Importanized launcher\requirements\bcrypt\__init__.py

I tried the following

launcher/requirements/*

launcher/requirements/

launcher/requirements/*.py

launcher/requirements/bcrypt/*.py

in the config file for exclude.

miki725 commented 4 years ago

your exclude pattern looks good. this sounds like a bug on windows. glob pattern specifies / to exclude but actual path has \

miki725 commented 4 years ago

https://github.com/miki725/importanize/pull/63 should fix this. let me know if this works for you now

commentator8 commented 4 years ago

Got it to work - but it wasn't intuitive. Had to use *launcher\requirements* to match launcher\requirements\bcrypt\__init__.py where for some reason launcher\requirements*wouldn't work.

Thanks for the quick work.

miki725 commented 4 years ago

hmm launcher\requirements* should of worked. where are you running importanize from relative to launcher folder?

>>> from importanize.importanize import should_skip, Config, Path
>>> should_skip(Path('launcher/requirements/bcrypt/__init__.py'), Config(exclude=['launcher\\requirements*'], path=Path('setup.ini').resolve()))
True
commentator8 commented 4 years ago

Edited - I called it from the root dir. e.g. root\launcher\requirements

miki725 commented 4 years ago

hmm. importanize recursively finds root config and relative paths are all relative to the config folder.

just did a test in importanize itself and it works:

diff --git setup.cfg setup.cfg
index afd13eb..3ea4d13 100644
--- setup.cfg
+++ setup.cfg
@@ -11,6 +11,7 @@ after_imports_new_lines=2
 length=80
 exclude=
     .tox/*
+    importanize/*.py
 add_imports=
     from __future__ import absolute_import, print_function, unicode_literals
 groups=

then

$ cd importanize && importanize main.py -vv 2>&1 | grep -i skipping
Skipping main.py as per ../setup.cfg

so far having issues reproducing it. currently dont have access to windows. Ill try to maybe reproduce in a vm one of these days or any more pointers will be appreciated to reproduce