Closed hakancelikdev closed 1 year ago
@mxr
Unimport works as you say, it doesn't need to be a config file.
If you want, you can manage your conf from a config file, you can give this config file with the --config flag and configure unimport in this way, or you can manage both via the console or via the config file if you want, the conf will be merged and determined accordingly.
If you want, you don't give the configuration file with the --config flag, unimport will find it for you in the root directory, if you don't want it to be found automatically, you can prevent it with the --disable-auto-discovery-config flag.
Unimport is flexible enough in these matters, you are free to do what you want!
I appreciate the flexibility but I'm referring to default options. For example, if I have no config at all, then running the following linters...
$ flake8 example.py
$ ruff example.py
$ mypy example.py
$ pyupgrade example.py
$ black example.py
... all provide some fixes/checks out of the box. However, with unimport
, the "no option" behavior is an error:
$ unimport example.py
Traceback (most recent call last):
File "/Users/mxr/tmp/venv3.7/bin/unimport", line 8, in <module>
sys.exit(main())
File "/Users/mxr/tmp/venv3.7/lib/python3.7/site-packages/unimport/__main__.py", line 6, in main
main = Main.run()
File "/Users/mxr/tmp/venv3.7/lib/python3.7/site-packages/unimport/main.py", line 107, in run
self = cls(argv)
File "<string>", line 4, in __init__
File "/Users/mxr/tmp/venv3.7/lib/python3.7/site-packages/unimport/main.py", line 39, in __post_init__
self.config = self.argv_to_config()
File "/Users/mxr/tmp/venv3.7/lib/python3.7/site-packages/unimport/main.py", line 47, in argv_to_config
commands.generate_parser().parse_args(self.argv if self.argv is not None else sys.argv[1:])
File "/Users/mxr/tmp/venv3.7/lib/python3.7/site-packages/unimport/config.py", line 194, in parse_args
config_context = cls(Path(path)).parse()
File "<string>", line 4, in __init__
File "/Users/mxr/tmp/venv3.7/lib/python3.7/site-packages/unimport/config.py", line 127, in __post_init__
raise FileNotFoundError(f"Config file not found: {self.config_file}")
FileNotFoundError: Config file not found: setup.cfg
I'm asking if unimport
could have some default useful/silent behavior in the presence of no options and no config?
@mxr This is an unexpected issue, I will fix it, thank you for letting me know
I missed up this case, can you open new issue I will fix it as soon as posible
Sure thing
This behavior is different from many other tools such as
ruff
,mypy
,black
,flake8
, and so on, where a configuration file is not required, and the tool silently works without one. IMO it's more ergonomic to haveunimport
work silently in the absence of a config file, but still use a config file when it exists.