Skip to content

Do not duplicate Tool class creation#4838

Open
mwichmann wants to merge 4 commits intoSCons:masterfrom
mwichmann:tool-init
Open

Do not duplicate Tool class creation#4838
mwichmann wants to merge 4 commits intoSCons:masterfrom
mwichmann:tool-init

Conversation

@mwichmann
Copy link
Copy Markdown
Collaborator

@mwichmann mwichmann commented Mar 11, 2026

If "default" is part of the tool list, the default.py tool will be run. This calls a function to generate the default tool list, which as a side effect creates a Tool instance for each tool examined. The tool then loops through the returned list, creating a Tool instance for each tool. To alleviate this duplication, the Tool instances are returned in the default list, and if an attempt is made to instantiate a Tool with the name argument being an instance already, it is returned as-is.

In the default tool - use the routine the SCons.Platform module provides for getting the default tool list (DefaultToolList). It does the same thing as default.generate did directly, but this way "we're using the API".

This is pushed as a draft for a chance to review the basic code setup. There is further pending work on SCons/Tool/__init__.py consisting of more docstring, typing annotations and a few very small cleanups, wanted to avoid those obscuring the main point. These can be added when taking this PR out of draft mode, or submitted as a separate PR.

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 RELEASE.txt (and read the README.rst).
  • I have updated the appropriate documentation

@mwichmann mwichmann added the Tools Issues related to tools subsystem label Mar 11, 2026
@mwichmann
Copy link
Copy Markdown
Collaborator Author

Well, it's Python... but I don't see how, no.

@bdbaddog
Copy link
Copy Markdown
Contributor

Any work outstanding to take the "Draft" label off this one?

@mwichmann mwichmann marked this pull request as ready for review April 12, 2026 12:39
@mwichmann mwichmann moved this to In review in Next Release Apr 12, 2026
@mwichmann mwichmann added this to the NextRelease milestone Apr 12, 2026
@mwichmann
Copy link
Copy Markdown
Collaborator Author

No. I've made the change and added the changelog snip.

If "default" is part of the tool list, the default.py tool will be run.
This calls a function to generate the default tool list, which as
a side effect creates a Tool instance for each tool examined. The
tool then loops through the returned list, creating a Tool instance
for each tool.  To alleviate this duplication, the Tool instances
are returned in the default list, and if an attempt is made to instantiate
a Tool with the "name" argument being an instance already, it is
returned as-is.

In the default tool - use the routine the SCons.Platform module
provides for getting the default tool list.  It does the same thing as
default.generate did directly, but this way "we're using the API".

Signed-off-by: Mats Wichmann <mats@linux.com>
just an import and a precautionary "str" conversion

Signed-off-by: Mats Wichmann <mats@linux.com>
@mwichmann
Copy link
Copy Markdown
Collaborator Author

oops, had to force-push a rebase as the just-added CHANGES and RELEASE things conflicted - master had moved on.

else:
kw = self.init_kw
env.AppendUnique(TOOLS=[self.name])
env.AppendUnique(TOOLS=[str(self.name)])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this needed? isn't .name already a string?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

hmm, probably you're right. I'll check eventually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tools Issues related to tools subsystem

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

2 participants