Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds experimental stdin support #1355

Merged
merged 1 commit into from Feb 16, 2021
Merged

Adds experimental stdin support #1355

merged 1 commit into from Feb 16, 2021

Conversation

ssbarnea
Copy link
Member

@ssbarnea ssbarnea commented Feb 15, 2021

Allow ansible-lint to perform linting from stdin when filename arguments as /dev/stdin or - are given.

Keep in mind:

  • no argument still means auto-detect as I found no reliable way to identify that the tool was used with shell pipes
  • filename reported is 'stdin', same as flake8 does
  • received content is assumed to be a playbook, you cannot lint a task file this way. Others are welcomed to propose improvements for detecting the file type based on its content, because we do not have any filename available.

Fixes: #790

Allow ansible-lint to perform linting from stdin when filename
argument '/dev/stdin' or '-' are given.

Keep in mind:
- no argument still means auto-detect as I found no reliable way
  to identify that the tool was used with shell pipes
- filename reported is 'stdin', same as flake8 does
- received content is assumed to be a playbook, you cannot lint
  a task file this way. Others are welcomed to propose improvements
  for detecting the file type based on its content, because we do
  not have any `filename` available.
Comment on lines +194 to +195
for match in matches:
for lintable in lintables:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using an itertools.product() here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really as I do also have the break.

if self.kind == "role":
self.dir = str(self.path.resolve())
if str(self.path) in ['/dev/stdin', '-']:
self.file = NamedTemporaryFile(mode="w+", suffix="playbook.yml")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it be kept in-memory instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope because I do need to feed ansible-playbook --syntax-check a file. The rest of the linter code could work fine with in-memory files, but not ansible itself.

@ssbarnea ssbarnea merged commit 3100caf into master Feb 16, 2021
@ssbarnea ssbarnea deleted the 0/5.0.1 branch February 16, 2021 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pipes: stdin incorrectly triggers detection mode
2 participants