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

[WIP] Use only one NodeList definition #3992

Closed
wants to merge 6 commits into from

Conversation

mwichmann
Copy link
Collaborator

@mwichmann mwichmann commented Aug 5, 2021

The two definitions of NodeList are collapsed to one, keeping the SCons.Util version and dumping the SCons.Node one. Two unit tests that were expecting the __str__ behavior of SCons.Node.NodeList were adjusted to match the behavior of SCons.Util.NodeList.

Alias() now returns NodeList. This brings it into line with the claim "builders return a nodelist".

Some type annotation added re: NodeLists, and based on running mypy, some other adjustments made.

Edited:

The Node NodeList __str__ method produces a string which begins and ends with brackets, the Util one does not. I don't have a strong opinion which is better, but the unit tests of course expect a very specific behavior. It's unclear if the str change affects anything else (investigate).

This code changes the _execute method to return a SCons.Util.NodeList instead of an SCons.Node.NodeList. The main one is in BuilderBase, but some derived classes define their own, which are currently _PDFFileBuilder in GettextCommon.py, _POTBuilder in xgettext.py and _MDFileBuilder in msgfmt.py.

The following public methods now explcitly return a NodeList, where previously some did and some returned plain Python lists: AddPreAction, AddPostAction, Alias, AlwaysBuild, Command, Depends, NoClean, NoCache, Ignore, Precious, Pseudo, Requires, SideEffect.

These internal methods methods now return a NodeList where they previously returned a Python list: arg2nodes, _create_nodes.

Signed-off-by: Mats Wichmann mats@linux.com

Contributor Checklist:

  • I have created a new test or updated the unit tests to cover the new/changed functionality.
  • I have updated CHANGES.txt (and read the README.rst)
  • I have updated the appropriate documentation

The two definitions of NodeList are collapsed to one, keeping the
SCons.Util version and dumping the SCons.Node one.  Two unit tests that
were expecting the __str__ behavior of SCons.Node.NodeList were adjusted
to match the behavior of SCons.Util.NodeList.

Alias() now returns NodeList: the list of nodes generated by calling
Alias is converted to a NodeList before returning. This brings it
into line with the claim "builders return a nodelist".

Some type annotation added re: NodeLists, and based on running mypy,
some other adjustments made.

Signed-off-by: Mats Wichmann <mats@linux.com>
The initial commit removed NodeList's __getitem__ method, since it's
no longer needed.  Turned out the fix was only applied in cpython as
of the 3.7 release, so put it back for versions earlier than that.
Also add a __getitem__ (versioned the same way) to CLVar class,
to make sure it keeps its identity if sliced.  Added unit tests to
make sure slicing these two UserList derivatives retains the class.

Signed-off-by: Mats Wichmann <mats@linux.com>
From Mats Wichmann:
- Unify the NodeList definitions - there were two, and didn't need to be.
Two unit tests had to be updated to make sure they're expecting the
right string representation. Alias now returns a NodeList like other
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably should explain the change to str(NodeList) here in case someone is depending on it.
Also.. they could cause unnecessary rebuilds on upgrade if the str(NodeList) is used anywhere generating a sig.
Also should list all the methods/apis which now return a NodeList() when before they returned a list [].
Lastly.. any idea if this has any notable perf degradation?

Copy link
Collaborator Author

@mwichmann mwichmann Aug 5, 2021

Choose a reason for hiding this comment

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

Would have to write somethng synthetic to check the performance, nothing we have in the testsuite takes enough time in NodeLists to show any significant difference. (back-to-back test runs show the new way a few seconds faster, but that's probably just within the noise.

I'll queue up trying to list the changes. In general following the "builders return a NodeList" rule, even for things which aren't classically builders (Builder classes) but are documented as builders.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

as a first step, I've added some information in the PR description above (see Edited section).

SConscript.BuildTargets = BUILD_TARGETS
SConscript.CommandLineTargets = COMMAND_LINE_TARGETS
SConscript.DefaultTargets = DEFAULT_TARGETS
# that pychecker and mypy don't barf.
Copy link
Contributor

Choose a reason for hiding this comment

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

the checkers don't like the previous syntax?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct. They gripe that there's no such attribute. Obviously Python allows you to add them this way, but it seemed a cheap change to shut the tools up.

# Return one item of the tart
return self.data[index]
# Return one item of the tart
return self.data[index]
Copy link
Contributor

Choose a reason for hiding this comment

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

no __getitem__ needed for py >= 3.7 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The inherited implementation from UserList works correctly, as noted in the referenced issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

apparently that had been a place that wasn't fully fixed up when Py3 dropped the previously existing __slice__ method.

@bdbaddog
Copy link
Contributor

bdbaddog commented Aug 8, 2021

I'd drop the SubstitutionEnvironment. in the API list in the description. Most users won't know what that is. and the method themselves are what're user visible.

@mwichmann
Copy link
Collaborator Author

Ok. Was that kind of list useful, or were you looking for something further?

@bdbaddog
Copy link
Contributor

Ok. Was that kind of list useful, or were you looking for something further?

Yes. that's what I was looking for, but remove SubstitutionEnvironment., few users know what that is and they don't see it in their usage of those API's as they're presented as is for use in SConscripts..

Clarify some bits of Alias while adding the mention it returns a
NodeList.

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann mwichmann changed the title Use only one NodeList definition WIP: Use only one NodeList definition Aug 11, 2021
@mwichmann
Copy link
Collaborator Author

Flipped to WIP while I research some things.

@mwichmann mwichmann changed the title WIP: Use only one NodeList definition [WIP] Use only one NodeList definition Dec 4, 2021
@mwichmann
Copy link
Collaborator Author

I'm now inclined to withdraw this one, maybe come back someday with a new approach. Any objections?

@mwichmann
Copy link
Collaborator Author

I'm going to withdraw this one. I still have questions, and haven't had time to research in detail, whether this is worth doing - perhaps the irritation of two of these is just something we can live with. Will keep archived.

@mwichmann mwichmann closed this Jun 18, 2022
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

2 participants