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

Improve support for keyword-positional arguments #254

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

myxie
Copy link
Collaborator

@myxie myxie commented May 20, 2024

Issue

Previously, we addressed the issue that the positional parameter option currently does not work for Docker and Bash applications; a temporary fix was introduced in #248.

Unfortunately, that solution did not allow for the potential Keyword-and-Positional argument combination, which is used in the PyFunc DROP classes. By commenting out the addition to portargs to fix positional arguments for Docker and Bash apps, I inadvertently broke the PyFunc apps.

Solution

I have added a flag to the identify_named_ports methods that allows for the addition of positional arguments to the keyword argument dictionary, which required for the PyFunc drops to work.

I have also added some support functions to reduce the incidence of duplicated coded in replace_named_ports, to improve readability and make a bit more explicit that we are doing a lot of in-place manipulation of dictionaries (as opposed to modifying and returning them).

- Split up repeated code to improve readability
- Add flag to identify_named_ports to allow for the addition of positional arguments to keyword argument dicionaries (required for the PyFunc drops to work).
@coveralls
Copy link

coveralls commented May 20, 2024

Coverage Status

coverage: 79.657% (-0.07%) from 79.725%
when pulling a3e225f on fix_positional_arguments
into bf3a8fc on master.

@myxie myxie marked this pull request as ready for review May 20, 2024 08:02
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @myxie - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 6 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

daliuge-engine/dlg/named_port_utils.py Outdated Show resolved Hide resolved
daliuge-engine/dlg/named_port_utils.py Show resolved Hide resolved
logger.debug("Checking against keyargs: %s", keyargs)
portargs = {}
posargs = list(posargs)
logger.debug("Checking against keyargs: %s", keywordArgs)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider using f-strings for logging

Using f-strings for logging can improve readability and performance. For example: logger.debug(f"Checking against keyargs: {keywordArgs}").

Suggested change
logger.debug("Checking against keyargs: %s", keywordArgs)
logger.debug(f"Checking against keyargs: {keywordArgs}")

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This suggestion is incorrect and conflicts with pylint and the Python documentation.

daliuge-engine/dlg/named_port_utils.py Show resolved Hide resolved
Comment on lines +235 to +236
positionalArgs = _get_args(appArgs, positional=True)
keywordArgs = _get_args(appArgs, positional=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Combine _get_args calls

Consider combining the two _get_args calls into a single line for better readability: positionalArgs, keywordArgs = _get_args(appArgs, positional=True), _get_args(appArgs, positional=False).

Suggested change
positionalArgs = _get_args(appArgs, positional=True)
keywordArgs = _get_args(appArgs, positional=False)
positionalArgs, keywordArgs = _get_args(appArgs, positional=True), _get_args(appArgs, positional=False)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I do not agree that this adds readability.

daliuge-engine/dlg/named_port_utils.py Outdated Show resolved Hide resolved
daliuge-engine/dlg/named_port_utils.py Outdated Show resolved Hide resolved
daliuge-engine/dlg/named_port_utils.py Show resolved Hide resolved
daliuge-engine/dlg/named_port_utils.py Outdated Show resolved Hide resolved
@myxie
Copy link
Collaborator Author

myxie commented May 27, 2024

@awicenec This is the work I've done to give us (optional) positional-and-keyword arguments. Would you mind providing a review?

@myxie
Copy link
Collaborator Author

myxie commented Jun 6, 2024

@awicenec just a 'bump' to confirm you're happy with these changes?

@awicenec
Copy link
Contributor

awicenec commented Jun 6, 2024 via email

@myxie myxie merged commit c0522c0 into master Jun 6, 2024
21 checks passed
awicenec pushed a commit that referenced this pull request Oct 10, 2024
Improve support for keyword-positional arguments
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.

3 participants