Skip to content

remove toolz.concatv #11769

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

Closed
wants to merge 6 commits into from
Closed

remove toolz.concatv #11769

wants to merge 6 commits into from

Conversation

dholth
Copy link
Contributor

@dholth dholth commented Aug 29, 2022

Description

itertools.chain() is used since conda's arguments to concatv are never generators

Replace verbatim copy of toolz.unique with import.

See also #11698

@dholth dholth requested a review from a team as a code owner August 29, 2022 16:25
@conda-bot conda-bot added the cla-signed [bot] added once the contributor has signed the CLA label Aug 29, 2022
Copy link
Contributor

@kenodegard kenodegard left a comment

Choose a reason for hiding this comment

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

It appears that almost all of the concatv/chain use cases are immediately evaluated/expanded into some tuple, list, or other frozen data type. Since that's the case can we just use arg unpacking?

@@ -122,7 +118,7 @@ def get_scripts_export_unset_vars(self, **kwargs):
return script_export_vars or '', script_unset_vars or ''

def _finalize(self, commands, ext):
commands = concatv(commands, ('',)) # add terminating newline
commands = chain(commands, ('',)) # add terminating newline
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, no benefit in leaving this as a generator and the NotImplementedError seems very unnecessary:

def _finalize(self, commands, ext):
    script = self.command_join.join((*commands, "))  # add terminating newline

    if ext:
        # the default mode is 'w+b', and universal new lines don't work in that mode
        # command_join should account for that
        with Utf8NamedTemporaryFile('w+', suffix=ext, delete=False) as tf:
            tf.write(script)
        return tf.name
    else:
        return script

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Where's the NotImplementedError

Copy link
Contributor

Choose a reason for hiding this comment

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

line 135 of conda/activate.py

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 guess ext could be the empty string sometimes? However it's not related to concatv in any way

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 would rather leave it as chain() because I'm not familiar with arg unpacking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kenodegard do you need this PR to use *arg unpacking whenever it is possible?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, agreed that NotImplementedError isn't useful here, it's kind of misused for this case, since that's supposed to be an exception for base classes that require certain methods to be overridden in subclasses.

@dholth dholth requested a review from kenodegard August 31, 2022 16:55

import itertools

concat = itertools.chain.from_iterable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the indirect module from conda.tlz import x to place these two lines in one place (the indirection module), instead of everywhere that particular toolz is uzed

Copy link
Member

Choose a reason for hiding this comment

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

Let's add this to conda.common as well.

Copy link
Member

@jezdez jezdez left a comment

Choose a reason for hiding this comment

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

I guess I'm a little on the fence if we'll basically never allow generators to be used here in the future?

@dholth
Copy link
Contributor Author

dholth commented Oct 13, 2022

If I'm not mistaken this PR replaces concat / concatv (which literally contain only calls to itertools.chain or itertools.chain.from_iterable) with direct calls to chain or chain.from_iterable

@travishathaway travishathaway added the source::anaconda created by members of Anaconda, Inc. label Dec 5, 2022
@dholth
Copy link
Contributor Author

dholth commented Dec 9, 2022

Obsolete

@dholth dholth closed this Dec 9, 2022
@github-actions github-actions bot added the locked [bot] locked due to inactivity label Dec 10, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed [bot] added once the contributor has signed the CLA locked [bot] locked due to inactivity source::anaconda created by members of Anaconda, Inc.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants