Skip to content

Keyword visibility modifiers for resource files (#430) - #4345

Merged
pekkaklarck merged 11 commits into
robotframework:masterfrom
robinmatz:issue-430
Jul 4, 2022
Merged

pekkaklarck merged 11 commits into
robotframework:masterfrom
robinmatz:issue-430

Conversation

@robinmatz

@robinmatz robinmatz commented May 18, 2022 •

Copy link
Copy Markdown
Contributor

Resolves #430.

  • User keywords can now be marked as private by tagging them robot:private.
  • Using them in resources within the same file is fine and intended
  • Using them in a test case in the same file or in a user keyword in another file will cause a warning
  • Keywords tagged as robot:private are removed from libdoc's html output
  • They are, however, still included in libdoc's spec files, for other tools to pick up on them
  • If there is both a public and a private User Keyword with the same name in the current scope, Robot Framework will execute the public one

@robinmatz
robinmatz marked this pull request as ready for review May 18, 2022 15:41
@robinmatz

Copy link
Copy Markdown
Contributor Author

Hi @pekkaklarck , just a quick reminder that this PR is ready for code review

@pekkaklarck pekkaklarck left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! Implementation is good, there are comprehensive tests, and also documentation has been updated. I had some somewhat nitpickey comments about the code style but I can change the code myself after merging this.


def _handle_private_runners(self, runners):
sum_public = sum("robot:private" not in runner.tags for runner in runners)
sum_private = sum("robot:private" in runner.tags for runner in runners)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's a bit questionable to use sum() with Boolean values but I guess it's ok here. The latter line could be simplified to:

sum_private = len(runners) - sum_public

sum_public = sum("robot:private" not in runner.tags for runner in runners)
sum_private = sum("robot:private" in runner.tags for runner in runners)

if sum_public == len(runners) or sum_private == len(runners) or sum_public > 1:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The first condition doesn't seem to be necessary. We only get to this function if there were multiple matches, so just having sum_public > 1 ought to be enough to cover also the sum_public == len(runners) case.

We generally haven't used empty lines between functions. If there's a need to use them for grouping code, we have typically created helper functions instead. That could be considered hare as well or possibly the empty lines could just be removed.

public_runner = runner
private_runners = runners.copy()
private_runners.remove(public_runner)
break

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably we could initially filter runners so that we have list of public and private runners instead of sum_xxx containing just their counts. Then this loop wouldn't needed at all.

if runner != private_runners[-1]:
private_runners_str += f"'{runner.longname}' / "
else:
private_runners_str += f"'{runner.longname}'"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks a bit complicated way to concatenate names with / . Just using something like

private_runner_str = ' / '.join(r.longname for r in private_runners)

ought to handler it as a one-liner. I'm also not certain is using / as a separator between private keywords here that good in general. Just listing all runners like 'First', 'Second' or 'Third would be simpler to implement and would look, in my opinion, clearer. I can test that in practice myself.

@pekkaklarck

Copy link
Copy Markdown
Member

One thing I'm slightly concerned with this change is performance. Checking for private tags with all user keywords (i.e. if 'robot:private' in handler.tags) can add measurable performance penalty. Need to test that in practice and see could we make that particular check faster. I have some ideas related to that, but need to first see is there any real difference.

@pekkaklarck
pekkaklarck merged commit 10fabf4 into robotframework:master Jul 4, 2022
pekkaklarck added a commit that referenced this pull request Jul 4, 2022
Checking do user keywords have special `robot:private` tag introduced
by PR #4345 and issue #430 is a bit slow. This change avoids it in the
common case where keywords doesn't have tags at all. Need to stil
later check could checking for special tags made faster in general.
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.

Keyword visibility modifiers for resource files

2 participants