-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import shared code from ansiblelint (#5)
This change should move all the shared code from ansiblelint and allow removed of molecule on ansible-lint. Both with import the code from us.
- Loading branch information
Showing
14 changed files
with
897 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
[flake8] | ||
|
||
# Don't even try to analyze these: | ||
exclude = | ||
# No need to traverse egg files | ||
*.egg, | ||
# No need to traverse egg info dir | ||
*.egg-info, | ||
# No need to traverse eggs directory | ||
.eggs, | ||
# No need to traverse our git directory | ||
.git, | ||
# GitHub configs | ||
.github, | ||
# Cache files of MyPy | ||
.mypy_cache, | ||
# Cache files of pytest | ||
.pytest_cache, | ||
# Temp dir of pytest-testmon | ||
.tmontmp, | ||
# Countless third-party libs in venvs | ||
.tox, | ||
# Occasional virtualenv dir | ||
.venv | ||
# VS Code | ||
.vscode, | ||
# There's no value in checking cache directories | ||
__pycache__, | ||
# Temporary build dir | ||
build, | ||
# This contains sdists and wheels of ansible-lint that we don't want to check | ||
dist, | ||
# Occasional virtualenv dir | ||
env, | ||
# Metadata of `pip wheel` cmd is autogenerated | ||
pip-wheel-metadata, | ||
|
||
# Let's not overcomplicate the code: | ||
max-complexity = 10 | ||
|
||
# Accessibility/large fonts and PEP8 friendly: | ||
#max-line-length = 79 | ||
# Accessibility/large fonts and PEP8 unfriendly: | ||
max-line-length = 100 | ||
|
||
# The only allowed ignores are related to black and isort | ||
# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length | ||
# "H" are generated by hacking plugin, which is not black compatible | ||
ignore = E203,E501,W503,H | ||
|
||
# Allow certain violations in certain files: | ||
# per-file-ignores = | ||
|
||
# flake8-pytest-style | ||
# PT001: | ||
pytest-fixture-no-parentheses = true | ||
# PT006: | ||
pytest-parametrize-names-type = tuple | ||
# PT007: | ||
pytest-parametrize-values-type = tuple | ||
pytest-parametrize-values-row-type = tuple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# v1 requirements test file | ||
- src: geerlingguy.mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
roles: | ||
- name: geerlingguy.mysql | ||
collections: | ||
- name: ssbarnea.molecule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
"""Store configuration options as a singleton.""" | ||
import os | ||
import re | ||
import subprocess | ||
import sys | ||
from functools import lru_cache | ||
from typing import List, Optional, Tuple | ||
|
||
from packaging.version import Version | ||
|
||
from ansible_compat.constants import ANSIBLE_MISSING_RC | ||
|
||
# Used to store collection list paths (with mock paths if needed) | ||
collection_list: List[str] = [] | ||
|
||
|
||
@lru_cache() | ||
def ansible_collections_path() -> str: | ||
"""Return collection path variable for current version of Ansible.""" | ||
# respect Ansible behavior, which is to load old name if present | ||
for env_var in ["ANSIBLE_COLLECTIONS_PATHS", "ANSIBLE_COLLECTIONS_PATH"]: | ||
if env_var in os.environ: | ||
return env_var | ||
|
||
# https://github.com/ansible/ansible/pull/70007 | ||
if ansible_version() >= ansible_version("2.10.0.dev0"): | ||
return "ANSIBLE_COLLECTIONS_PATH" | ||
return "ANSIBLE_COLLECTIONS_PATHS" | ||
|
||
|
||
def parse_ansible_version(stdout: str) -> Tuple[str, Optional[str]]: | ||
"""Parse output of 'ansible --version'.""" | ||
# Ansible can produce extra output before displaying version in debug mode. | ||
|
||
# ansible-core 2.11+: 'ansible [core 2.11.3]' | ||
match = re.search( | ||
r"^ansible \[(?:core|base) (?P<version>[^\]]+)\]", stdout, re.MULTILINE | ||
) | ||
if match: | ||
return match.group("version"), None | ||
# ansible-base 2.10 and Ansible 2.9: 'ansible 2.x.y' | ||
match = re.search(r"^ansible (?P<version>[^\s]+)", stdout, re.MULTILINE) | ||
if match: | ||
return match.group("version"), None | ||
return "", "FATAL: Unable parse ansible cli version: %s" % stdout | ||
|
||
|
||
@lru_cache() | ||
def ansible_version(version: str = "") -> Version: | ||
"""Return current Version object for Ansible. | ||
If version is not mentioned, it returns current version as detected. | ||
When version argument is mentioned, it return converts the version string | ||
to Version object in order to make it usable in comparisons. | ||
""" | ||
if version: | ||
return Version(version) | ||
|
||
proc = subprocess.run( | ||
["ansible", "--version"], | ||
universal_newlines=True, | ||
check=False, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
) | ||
if proc.returncode == 0: | ||
version, error = parse_ansible_version(proc.stdout) | ||
if error is not None: | ||
print(error) | ||
sys.exit(ANSIBLE_MISSING_RC) | ||
else: | ||
print( | ||
"Unable to find a working copy of ansible executable.", | ||
proc, | ||
) | ||
sys.exit(ANSIBLE_MISSING_RC) | ||
return Version(version) | ||
|
||
|
||
if ansible_collections_path() in os.environ: | ||
collection_list = os.environ[ansible_collections_path()].split(':') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Constants used by ansible_compat.""" | ||
|
||
|
||
# Minimal version of Ansible we support for runtime | ||
ANSIBLE_MIN_VERSION = "2.9" | ||
|
||
# Based on https://docs.ansible.com/ansible/latest/reference_appendices/config.html | ||
ANSIBLE_DEFAULT_ROLES_PATH = ( | ||
"~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles" | ||
) | ||
|
||
INVALID_CONFIG_RC = 2 | ||
ANSIBLE_MISSING_RC = 4 | ||
INVALID_PREREQUISITES_RC = 10 | ||
|
||
MSG_INVALID_FQRL = """\ | ||
Computed fully qualified role name of %s does not follow current galaxy requirements. | ||
Please edit meta/main.yml and assure we can correctly determine full role name: | ||
galaxy_info: | ||
role_name: my_name # if absent directory name hosting role is used instead | ||
namespace: my_galaxy_namespace # if absent, author is used instead | ||
Namespace: https://galaxy.ansible.com/docs/contributing/namespaces.html#galaxy-namespace-limitations | ||
Role: https://galaxy.ansible.com/docs/contributing/creating_role.html#role-names | ||
As an alternative, you can add 'role-name' to either skip_list or warn_list. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Utilities for loading various files.""" | ||
from typing import Any | ||
|
||
import yaml | ||
|
||
|
||
def yaml_from_file(filepath: str) -> Any: | ||
"""Return a loaded YAML file.""" | ||
with open(filepath) as content: | ||
return yaml.load(content, Loader=yaml.FullLoader) |
Oops, something went wrong.