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

Expand environnement variable in option_manager_mixin #4812

Merged
merged 10 commits into from Aug 11, 2021

Conversation

PaaEl
Copy link
Contributor

@PaaEl PaaEl commented Aug 7, 2021

I added @JoshMayberry 's solution for issue 3839.
#3839

If a config file is provided that has an environment variable, such as "%AppData%", it fails.
This can be fixed by changing this line from config_file = os.path.expanduser(config_file) to config_file = os.path.expandvars(os.path.expanduser(config_file))

Type of Changes

Type
🐛 Bug fix

Description

Closes #3839

I  added @JoshMayberry 's solution for issue 3839.
pylint-dev#3839
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

Thank you, maybe could a test too ? What do you think ?

@Pierre-Sassoulas Pierre-Sassoulas added the Enhancement ✨ Improvement to a component label Aug 7, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.10.0 milestone Aug 7, 2021
@coveralls
Copy link

coveralls commented Aug 7, 2021

Pull Request Test Coverage Report for Build 1121196534

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 92.622%

Totals Coverage Status
Change from base Build 1120477236: 0.0%
Covered Lines: 13282
Relevant Lines: 14340

💛 - Coveralls

@PaaEl
Copy link
Contributor Author

PaaEl commented Aug 7, 2021

Thank you, maybe could a test too ? What do you think ?

I'm sorry, I don't understand. This is the first time I've done anything on Github.
Do you mean I should write a test and add it to the testcases?
I can do that!

@Pierre-Sassoulas
Copy link
Member

Yes, sorry I meant add an automated test to the test suite. I just realized that it would be nice to add yourself to the contributors and to add an entry to the changelog too as this change is something that benefit from being known.

PaaEl and others added 4 commits August 7, 2021 22:49
I  added a test to see if pylint handles environment variables in config file locations.
Added it to test_config because it also deals with config files.
To test I added an environment variable containing tmp_path and then unpacked it with os.path.expandvars.
@PaaEl
Copy link
Contributor Author

PaaEl commented Aug 7, 2021

Added a test to test_config, the change to the changelog and myself to the contributors.

Path(os.path.expandvars(os.path.expanduser("${tmp_path_env}"))) / ".pylintrc"
)

config_file.write_text(
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we call the function read_config_file in order to test what we want to test ?

# if it has an environment variable.
os.environ["tmp_path_env"] = str(tmp_path)
config_file = (
Path(os.path.expandvars(os.path.expanduser("${tmp_path_env}"))) / ".pylintrc"
Copy link
Member

Choose a reason for hiding this comment

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

I think we should not expand the value in the test, to be able to see that the extends is properly done inside the function ? What am I missing ?

PaaEl and others added 2 commits August 8, 2021 11:56
Tmp_path gets converted to an environment variable  which is fed to the read_config_file function to be tested.
Read_config_file succesfully reads the environment variable, if the variable is changed, the function raises an OSError.
@PaaEl
Copy link
Contributor Author

PaaEl commented Aug 8, 2021

No, you are quite right, Pierre. Thank you for your feedback.
I changed the test, it now actually tests read_config_file.
I think it's good now, but please do look over it again, it's my first time writing tests.

os.environ["tmp_path_env"] = str(tmp_path / "pylintrc")
options_manager_mix_in = OptionsManagerMixIn("", "${tmp_path_env}")
options_manager_mix_in.read_config_file("${tmp_path_env}")

Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the change :) I think we should also check that jobs = 10 or reports = yes so we make sure that the file was read correctly :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Love the dedication!
I'll see what I can do.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't figure out how to get a provider to set _all_options[opt].
Is there a UML diagram of pylint somewhere?
So I just checked through the parser in load_config_file().

Copy link
Member

Choose a reason for hiding this comment

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

Pyliny has pyreverse in it that could generate the uml diagram automatically 😄 Thank you for adding the test and the assert. Looking at the MR it seems you're testing the value in the config file and this could be merged ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know what the MR is, but yes, the class instance reads the config file and then loads it and I used the parser that is then created to check if the values are the same. So I think the test now tests what it has to.
Thanks for your feedback btw, I learned a lot.

PaaEl and others added 3 commits August 11, 2021 12:02
Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a comment

Choose a reason for hiding this comment

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

MR means "Merge request", sorry for the jargon :) Thank you for going all the way to completion,and congratulation on becoming a pylint contributor :)

@Pierre-Sassoulas Pierre-Sassoulas merged commit d53a01f into pylint-dev:main Aug 11, 2021
@Pierre-Sassoulas
Copy link
Member

One last thing, I know it comes from a good intention to credit the user but do not tag someone in a very high activity repo's commit (@PaaEl) :) Each person rebasing the commit into their branch create an email. Could make them get 10 email/day from github for weeks ;) !

@Pierre-Sassoulas Pierre-Sassoulas changed the title Update option_manager_mixin.py - issue 3839 Expand environnement variable in option_manager_mixin Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Config File Does not Expand Environment Variables
3 participants