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

Remove duplicate entries while modifying PATH-like environment variables #7891

Merged
merged 2 commits into from Oct 20, 2020

Conversation

db4
Copy link
Contributor

@db4 db4 commented Oct 16, 2020

Changelog: Fix: Remove duplicate entries while modifying PATH-like environment variables internally. Especially important for Windows where system PATH size is limited by 8192 charachers (when using cmd.exe).
Docs: omit

Partially solves #7587, especially when conan is launched from MSVC develper command prompt.

@CLAassistant
Copy link

CLAassistant commented Oct 16, 2020

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@memsharded memsharded left a comment

Choose a reason for hiding this comment

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

Could you please add a test that will cover this case? Ask for guidance if it is not evident how/where.

Thanks for the contribution!

@@ -65,6 +69,7 @@ def _environment_add(env_vars, post=False):
apply_vars[name] = old + os.pathsep + apply_vars[name]
else:
apply_vars[name] += os.pathsep + old
apply_vars[name] = os.pathsep.join(_unique(apply_vars[name].split(os.pathsep)))
Copy link
Member

Choose a reason for hiding this comment

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

It seems that it can be done in place with a more common python idiom like:

items = apply_vars[name].split(os.pathsep)
apply_vars[name] = os.pathsep.join(OrderedDict.fromkeys(items))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems that it can be done in place with a more common python idiom like:

items = apply_vars[name].split(os.pathsep)
apply_vars[name] = os.pathsep.join(OrderedDict.fromkeys(items))

Yes, indeed. I was under the impression that OrderedDict was the Python3-only thing but actually it's included in Python 2.7 as well.

Copy link
Member

Choose a reason for hiding this comment

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

Great. If you could manage to add some test (ask for help if necessary), this can be merged for next Conan 1.31.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could you please add a test that will cover this case? Ask for guidance if it is not evident how/where.

Yes, please. I'm not familiar with Conan testing framework. Is

def vcvars_env_not_duplicated_path_test(self):
the correct place for these additional tests? And how to run Conan tests locally?

Copy link
Member

Choose a reason for hiding this comment

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

It seems that the VirtualEnvGeneratorTest in conans/test/unittests/client/generators/virtualenv_test.py would be a good place, adding another variable with repeated paths.

Locally, you can run it with: nosetests conans/test/unittests/client/generators/virtualenv_test.py. You might need to pip install -r requirements_dev.txt and pip install -r requirements_server.txt if missing deps. Please let me know if this helps, otherwise I can contribute the test myself. Thanks again for the contribution!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if this helps, otherwise I can contribute the test myself.

Looks like sorting it out needs some time but right now I'm a little bit busy. If you can write tests yourself with little efforts please do!

@db4 db4 force-pushed the fix/remove-path-duplicates branch from c9700ad to 0605380 Compare October 19, 2020 07:06
@memsharded memsharded added this to the 1.31 milestone Oct 19, 2020
Copy link
Contributor

@jgsogo jgsogo left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the contribution, @db4 🎉

@jgsogo jgsogo merged commit d380f55 into conan-io:develop Oct 20, 2020
@db4 db4 deleted the fix/remove-path-duplicates branch October 11, 2022 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants