Skip to content

Commit

Permalink
Set global cache_dir_lock (#4055)
Browse files Browse the repository at this point in the history
Co-authored-by: Ajinkya Udgirkar <[email protected]>
  • Loading branch information
guppy0130 and audgirka authored Mar 8, 2024
1 parent 6d247c1 commit 36e2674
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ ignore = [
"RUF012", # Mutable class attributes should be annotated with `typing.ClassVar`
"TRY",
"PERF203",
"PD011" # We are not using pandas, any .values attributes are unrelated
"PD011", # We are not using pandas, any .values attributes are unrelated
"PLW0603" # global lock file in cache dir
]
select = ["ALL"]
target-version = "py310"
Expand Down
10 changes: 6 additions & 4 deletions src/ansiblelint/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@


_logger = logging.getLogger(__name__)
cache_dir_lock: None | FileLock = None


class LintLogHandler(logging.Handler):
Expand Down Expand Up @@ -120,8 +119,9 @@ def initialize_logger(level: int = 0) -> None:
_logger.debug("Logging initialized to level %s", logging_level)


def initialize_options(arguments: list[str] | None = None) -> None:
def initialize_options(arguments: list[str] | None = None) -> None | FileLock:
"""Load config options and store them inside options module."""
cache_dir_lock = None
new_options = cli.get_config(arguments or [])
new_options.cwd = pathlib.Path.cwd()

Expand All @@ -145,7 +145,7 @@ def initialize_options(arguments: list[str] | None = None) -> None:
options.cache_dir.mkdir(parents=True, exist_ok=True)

if not options.offline: # pragma: no cover
cache_dir_lock = FileLock( # pylint: disable=redefined-outer-name
cache_dir_lock = FileLock(
f"{options.cache_dir}/.lock",
)
try:
Expand All @@ -160,6 +160,8 @@ def initialize_options(arguments: list[str] | None = None) -> None:
if "ANSIBLE_DEVEL_WARNING" not in os.environ: # pragma: no branch
os.environ["ANSIBLE_DEVEL_WARNING"] = "false"

return cache_dir_lock


def _do_list(rules: RulesCollection) -> int:
# On purpose lazy-imports to avoid pre-loading Ansible
Expand Down Expand Up @@ -285,7 +287,7 @@ def main(argv: list[str] | None = None) -> int:

if argv is None: # pragma: no cover
argv = sys.argv
initialize_options(argv[1:])
cache_dir_lock = initialize_options(argv[1:])

console_options["force_terminal"] = options.colored
reconfigure(console_options)
Expand Down
2 changes: 1 addition & 1 deletion src/ansiblelint/schemas/__store__.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/inventory.json"
},
"meta": {
"etag": "fb58deb0f5f2a3b77ba298764f74bc6e3bd38a761f368a50bb285042f6260354",
"etag": "e04a9e9c210c666c744dfe9ebf1ca1f4e95e71bd16995514b9c3a56186e66c98",
"url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/meta.json"
},
"meta-runtime": {
Expand Down

0 comments on commit 36e2674

Please sign in to comment.