diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4524de06..2af2c8ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -12,7 +12,7 @@ repos: - id: isort - repo: https://github.com/hakancelikdev/unimport - rev: 0.14.0 + rev: 0.14.1 hooks: - id: unimport diff --git a/action.yml b/action.yml index bfa3818a..95c1ec27 100644 --- a/action.yml +++ b/action.yml @@ -10,7 +10,7 @@ inputs: runs: using: "composite" steps: - - run: pip install --upgrade pip && python -m pip install unimport==0.14.0 + - run: pip install --upgrade pip && python -m pip install unimport==0.14.1 shell: bash - run: unimport --color auto --gitignore --ignore-init ${{ inputs.extra_args }} shell: bash diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f7921e5b..964dda92 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - YYYY-MM-DD +## [0.14.1] - 2023-02-04 + +### Fixed + +- Running without options or a config file #281. + ## [0.14.0] - 2023-02-03 ### Added diff --git a/docs/tutorial/use-with-github-action.md b/docs/tutorial/use-with-github-action.md index 03e34c88..ab002b6d 100644 --- a/docs/tutorial/use-with-github-action.md +++ b/docs/tutorial/use-with-github-action.md @@ -27,7 +27,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-python@v3 - name: Check unused imports - uses: hakancelikdev/unimport@0.14.0 + uses: hakancelikdev/unimport@0.14.1 with: extra_args: --include src/ ``` diff --git a/pyproject.toml b/pyproject.toml index 2a46862b..1c870e05 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta" # Tools [tool.pytest.ini_options] -addopts = "-v" +addopts = "--strict-markers" xfail_strict = true testpaths = ["tests"] diff --git a/src/unimport/__init__.py b/src/unimport/__init__.py index 83c3eb7d..2875c878 100644 --- a/src/unimport/__init__.py +++ b/src/unimport/__init__.py @@ -1,2 +1,2 @@ -__version__ = "0.14.0" +__version__ = "0.14.1" __description__ = "A linter, formatter for finding and removing unused import statements." diff --git a/src/unimport/config.py b/src/unimport/config.py index 953f1c1d..4df8d4ba 100644 --- a/src/unimport/config.py +++ b/src/unimport/config.py @@ -1,5 +1,6 @@ import argparse import configparser +import contextlib import dataclasses import functools import sys @@ -191,9 +192,10 @@ def parse_args(cls, args: argparse.Namespace) -> "Config": config_context = cls(args.config).parse() elif args.config is None and args.disable_auto_discovery_config is False: for path in CONFIG_FILES.keys(): - config_context = cls(Path(path)).parse() - if config_context: - break + with contextlib.suppress(FileNotFoundError): + config_context = cls(Path(path)).parse() + if config_context: + break if not config_context: config_context = None diff --git a/tests/config/test_config.py b/tests/config/test_config.py index 5c22f814..0812605d 100644 --- a/tests/config/test_config.py +++ b/tests/config/test_config.py @@ -210,3 +210,8 @@ def test_use_color_none_of_them(): Config.is_use_color("none-of-them") assert "none-of-them" in str(cm.value) + + +@pytest.mark.change_directory("tests/config") +def test_disable_auto_discovery_config_not_found_config_files(): + ParseConfig.parse_args(generate_parser().parse_args([])) diff --git a/tests/conftest.py b/tests/conftest.py index 7b1da871..4c379e05 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import pytest @@ -17,3 +18,20 @@ def logger(): logger.setLevel(level=logging.DEBUG) return logger + + +def pytest_configure(config): + config.addinivalue_line("markers", "change_directory(path:str): mark test to change working directory") + + +def pytest_runtest_setup(item): + for marker in item.iter_markers(name="change_directory"): + item.original_cwd = Path.cwd() + + directory = marker.args[0] + os.chdir(directory) + + +def pytest_runtest_teardown(item, nextitem): + for marker in item.iter_markers(name="change_directory"): + os.chdir(item.original_cwd)