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

Feature: Allow yml extension #169

Merged
merged 9 commits into from
Jan 24, 2022
Merged

Feature: Allow yml extension #169

merged 9 commits into from
Jan 24, 2022

Conversation

tbrlpld
Copy link
Collaborator

@tbrlpld tbrlpld commented Dec 23, 2021

Description

So far, the context YAML files had to have the .yaml extension. YAML files often also use the .yml extension. This PR adds a second attempt at finding the YAML file with the .yml extension after the .yaml extension has failed to produce a result.

The second attempt is simply enabled by adding a second nested try-except-block. I am not sure this is the most elegant solution, but it works and seems easy to understand.

Fixes #161

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas -> No hard to understand areas.
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added an appropriate CHANGELOG entry

@tbrlpld tbrlpld marked this pull request as draft December 23, 2021 01:42
@tbrlpld tbrlpld self-assigned this Dec 23, 2021
Copy link
Member

@thibaudcolas thibaudcolas left a comment

Choose a reason for hiding this comment

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

@tbrlpld this seems spot on to me – we have to attempt to read both paths either way, so I don’t think there would be much of a better way. I have a feeling this is overkill but we could cache whichever file extension was loaded successfully last for a given pattern to avoid the extra IO when a site consistently uses .yml?

To finish the PR, I’d additionally want to see:

@thibaudcolas thibaudcolas added this to the Nice to have milestone Dec 23, 2021
@tbrlpld
Copy link
Collaborator Author

tbrlpld commented Dec 24, 2021

@thibaudcolas I have pushed changes according to your review.

Regarding the caching: I also think that would be overkill. Especially in larger projects I can imagine that both extensions could occur when no linter or CI checks preventing it from happening. In that case it would be particularly confusing why the files are not recognized while they would work in another project which is consistent.

If we wanted to allow projects to be consistent, we could add a setting, but I am afraid that could also cause confusion because you would need to know how it project is configured.

I am not sure, but would using glob to check for file existence save the additional IO?

@tbrlpld tbrlpld marked this pull request as ready for review December 24, 2021 01:06
@thibaudcolas
Copy link
Member

@tbrlpld thank you, I’ll try to review this once I get the chance. Re glob – I doubt it’s worth it. We’d have to do 1 scandir with glob, then the 1 file read, so it’d be two IO calls for all cases rather than the "1 or 2" situation we’d be in here.

Copy link
Collaborator

@bcdickinson bcdickinson left a comment

Choose a reason for hiding this comment

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

Thanks Tibor, this is great.

CHANGELOG.md Outdated Show resolved Hide resolved
@tbrlpld
Copy link
Collaborator Author

tbrlpld commented Jan 24, 2022

Thanks for reviewing @bcdickinson

@bcdickinson bcdickinson merged commit e128f89 into main Jan 24, 2022
@bcdickinson bcdickinson deleted the feature/allow-yml-extension branch January 24, 2022 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Allow .yml as YAML file extension
3 participants