Skip to content

Commit

Permalink
WIP: Removed provisioner and verifier specific linting support
Browse files Browse the repository at this point in the history
This is not about removing linting form molecule completely, but is
about moving towards having a single 'lint' command that runs all
the linters user wants.

YEP, THIS CHANGE LOOKS INSANE.

Fixes: #2293
  • Loading branch information
ssbarnea committed Jan 26, 2020
1 parent c960afe commit 0cc5270
Show file tree
Hide file tree
Showing 53 changed files with 11 additions and 1,713 deletions.
4 changes: 0 additions & 4 deletions docs/ci.rst
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,8 @@ conflict.
command: /usr/sbin/init
provisioner:
name: ansible
lint:
name: ansible-lint
verifier:
name: testinfra
lint:
name: flake8
.. _`GitHub Actions`: https://github.com/features/actions
.. _`Factors`: http://tox.readthedocs.io/en/latest/config.html#factors-and-factor-conditional-settings
Expand Down
24 changes: 1 addition & 23 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@ Podman
Lint
----

Molecule handles project linting by invoking configurable linters.

Yaml Lint
^^^^^^^^^

.. autoclass:: molecule.lint.yamllint.Yamllint()
:undoc-members:
Molecule handles project linting by invoking and externa lint command.

.. _platforms:

Expand Down Expand Up @@ -157,25 +151,9 @@ Ansible
.. autoclass:: molecule.verifier.ansible.Ansible()
:undoc-members:

Lint
....

.. autoclass:: molecule.verifier.lint.ansible_lint.AnsibleLint()
:undoc-members:

Testinfra
^^^^^^^^^

.. autoclass:: molecule.verifier.testinfra.Testinfra()
:undoc-members:

.. _root_lint:

Lint
....

.. autoclass:: molecule.verifier.lint.flake8.Flake8()
:undoc-members:

.. autoclass:: molecule.verifier.lint.precommit.PreCommit()
:undoc-members:
2 changes: 0 additions & 2 deletions molecule/command/init/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,5 @@ def role(
'verifier_name': verifier_name,
}

command_args['verifier_lint_name'] = api.verifiers()[verifier_name].default_linter

r = Role(command_args)
r.execute()
2 changes: 0 additions & 2 deletions molecule/command/init/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ def scenario(
'verifier_name': verifier_name,
}

command_args['verifier_lint_name'] = api.verifiers()[verifier_name].default_linter

driver_template = driver_template or os.environ.get(
'MOLECULE_SCENARIO_DRIVER_TEMPLATE', None
)
Expand Down
13 changes: 1 addition & 12 deletions molecule/command/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,7 @@ def execute(self):
:return: None
"""
self.print_info()
linters = [
l
for l in [
self._config.lint,
self._config.verifier.lint,
self._config.provisioner.lint,
]
if l
]

for l in linters:
l.execute()
# TODO: run linter


@click.command()
Expand Down
9 changes: 2 additions & 7 deletions molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from molecule.dependency import ansible_galaxy
from molecule.dependency import gilt
from molecule.dependency import shell
from molecule.lint import yamllint
from molecule.model import schema_v2
from molecule.provisioner import ansible

Expand Down Expand Up @@ -181,21 +180,18 @@ def env(self):
'MOLECULE_INSTANCE_CONFIG': self.driver.instance_config,
'MOLECULE_DEPENDENCY_NAME': self.dependency.name,
'MOLECULE_DRIVER_NAME': self.driver.name,
'MOLECULE_LINT_NAME': self.lint.name,
'MOLECULE_LINT_NAME': self.lint,
'MOLECULE_PROVISIONER_NAME': self.provisioner.name,
'MOLECULE_PROVISIONER_LINT_NAME': self.provisioner.lint.name,
'MOLECULE_SCENARIO_NAME': self.scenario.name,
'MOLECULE_VERIFIER_NAME': self.verifier.name,
'MOLECULE_VERIFIER_LINT_NAME': self.verifier.lint.name,
'MOLECULE_VERIFIER_TEST_DIRECTORY': self.verifier.directory,
}

@property
@util.lru_cache()
def lint(self):
lint_name = self.config['lint']['name']
if lint_name == 'yamllint':
return yamllint.Yamllint(self)
return lint_name

@property
@util.lru_cache()
Expand Down Expand Up @@ -413,7 +409,6 @@ def _get_defaults(self):
'options': {},
'env': {},
'additional_files_or_dirs': [],
'lint': {'name': 'flake8', 'enabled': True, 'options': {}, 'env': {}},
},
}

Expand Down
3 changes: 1 addition & 2 deletions molecule/cookiecutter/molecule/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
"provisioner_lint_name": "ansible-lint",
"scenario_name": "OVERRIDDEN",
"role_name": "OVERRIDDEN",
"verifier_name": "OVERRIDDEN",
"verifier_lint_name": "flake8"
"verifier_name": "OVERRIDDEN"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,5 @@ platforms:
{%- endif %}
provisioner:
name: {{ cookiecutter.provisioner_name }}
lint:
name: {{ cookiecutter.provisioner_lint_name }}
enabled: false
verifier:
name: {{ cookiecutter.verifier_name }}
lint:
name: {{ cookiecutter.verifier_lint_name }}
16 changes: 0 additions & 16 deletions molecule/model/schema_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,22 +123,6 @@ def pre_validate_base_schema(env, keep_string):
'molecule_env_var': True,
'allowed': api.verifiers(),
},
'lint': {
'type': 'dict',
'schema': {
'name': {
'type': 'string',
'molecule_env_var': True,
'allowed': [
'flake8',
'pre-commit',
'rubocop',
'yamllint',
'ansible-lint',
],
}
},
},
},
},
}
Expand Down
10 changes: 0 additions & 10 deletions molecule/provisioner/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@

import abc

from molecule.util import lru_cache
from molecule.provisioner.lint import ansible_lint


class Base(object):
"""Provisioner Base Class."""
Expand Down Expand Up @@ -66,10 +63,3 @@ def name(self): # pragma: no cover
:returns: str
"""
pass

@property
@lru_cache()
def lint(self):
lint_name = self._config.config['provisioner']['lint']['name']
if lint_name == 'ansible-lint':
return ansible_lint.AnsibleLint(self._config)
Empty file.
4 changes: 0 additions & 4 deletions molecule/test/resources/molecule_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ platforms:
image: ${TEST_BASE_IMAGE}
provisioner:
name: ansible
lint:
name: ansible-lint
scenario:
name: ansible-galaxy
verifier:
name: testinfra
lint:
name: flake8
6 changes: 0 additions & 6 deletions molecule/test/scenarios/cleanup/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: docker
lint:
name: yamllint
options:
config-file: ../../resources/.yamllint
platforms:
- name: instance
image: ${TEST_BASE_IMAGE}
Expand All @@ -21,11 +19,7 @@ provisioner:
create: ../../../../resources/playbooks/docker/create.yml
destroy: ../../../../resources/playbooks/docker/destroy.yml
cleanup: cleanup.yml
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: docker
lint:
name: yamllint
options:
config-file: ../../resources/.yamllint
platforms:
- name: instance
image: ${TEST_BASE_IMAGE}
Expand All @@ -20,11 +18,7 @@ provisioner:
playbooks:
create: ../../../../resources/playbooks/docker/create.yml
destroy: ../../../../resources/playbooks/docker/destroy.yml
lint:
name: ansible-lint
scenario:
name: ansible-galaxy
verifier:
name: testinfra
lint:
name: flake8
6 changes: 0 additions & 6 deletions molecule/test/scenarios/dependency/molecule/gilt/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: docker
lint:
name: yamllint
options:
config-file: ../../resources/.yamllint
platforms:
- name: instance
image: ${TEST_BASE_IMAGE}
Expand All @@ -20,11 +18,7 @@ provisioner:
playbooks:
create: ../../../../resources/playbooks/docker/create.yml
destroy: ../../../../resources/playbooks/docker/destroy.yml
lint:
name: ansible-lint
scenario:
name: gilt
verifier:
name: testinfra
lint:
name: flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ driver:
name: docker
lint:
name: yamllint
options:
config-file: ../../resources/.yamllint
platforms:
- name: instance
image: ${TEST_BASE_IMAGE}
Expand All @@ -21,11 +19,7 @@ provisioner:
playbooks:
create: ../../../../resources/playbooks/docker/create.yml
destroy: ../../../../resources/playbooks/docker/destroy.yml
lint:
name: ansible-lint
scenario:
name: shell
verifier:
name: testinfra
lint:
name: flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: docker
lint:
name: yamllint
options:
config-file: ../../../resources/.yamllint
platforms:
- name: instance
image: ${TEST_BASE_IMAGE}
Expand All @@ -21,11 +19,7 @@ provisioner:
destroy: ../../../../../resources/playbooks/docker/destroy.yml
env:
ANSIBLE_ROLES_PATH: ../../../../../resources/roles/
lint:
name: ansible-lint
scenario:
name: ansible-verifier
verifier:
name: ansible
lint:
name: ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: docker
lint:
name: yamllint
options:
config-file: ../../../resources/.yamllint
platforms:
- name: instance
image: ${TEST_BASE_IMAGE}
Expand All @@ -26,11 +24,7 @@ provisioner:
ANSIBLE_ROLES_PATH: ../../../../../resources/roles/
# keep this here to test that we convert integers to strings:
SOME_VALUE_AS_INFO: 1
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: docker
lint:
name: yamllint
options:
config-file: ../../../resources/.yamllint
platforms:
- name: instance-1
image: ${TEST_BASE_IMAGE}
Expand All @@ -30,11 +28,7 @@ provisioner:
destroy: ../../../../../resources/playbooks/docker/destroy.yml
env:
ANSIBLE_ROLES_PATH: ../../../../../resources/roles/
lint:
name: ansible-lint
scenario:
name: multi-node
verifier:
name: testinfra
lint:
name: flake8
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: podman
lint:
name: yamllint
options:
config-file: ../../../resources/.yamllint
platforms:
- name: instance
image: centos:latest
Expand All @@ -24,11 +22,7 @@ provisioner:
destroy: ../../../../../resources/playbooks/podman/destroy.yml
env:
ANSIBLE_ROLES_PATH: ../../../../../resources/roles/
lint:
name: ansible-lint
scenario:
name: ansible-verifier
verifier:
name: ansible
lint:
name: ansible-lint
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ driver:
name: podman
lint:
name: yamllint
options:
config-file: ../../../resources/.yamllint
platforms:
- name: instance
image: centos:latest
Expand All @@ -26,11 +24,7 @@ provisioner:
ANSIBLE_ROLES_PATH: ../../../../../resources/roles/
# keep this here to test that we convert integers to strings:
SOME_VALUE_AS_INFO: 1
lint:
name: ansible-lint
scenario:
name: default
verifier:
name: testinfra
lint:
name: flake8

0 comments on commit 0cc5270

Please sign in to comment.