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

Options: avoid code duplication #890

Merged
merged 4 commits into from
Sep 12, 2024
Merged

Conversation

smelc
Copy link
Contributor

@smelc smelc commented Sep 11, 2024

Changelog

- description: |
    Share code in parsers, by using cardano-api's [parseFilePath](https://github.com/IntersectMBO/cardano-api/blob/bf84187ae986f9a2621c55b690638fe8bb2cb156/cardano-api/internal/Cardano/Api/Utils.hs#L97) instead of duplicating its implementation in 50+ places.
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  - refactoring    # QoL changes
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Improvement found when starting to write https://github.com/input-output-hk/cardano-node-wiki/pull/52/files

How to trust this PR

You can review the diff in Haskell files manually.

This question is more tricky for the 700+ golden files that have changed 😄 What I did is that I ran the golden tests against a modified version of cardano-api, at revision https://github.com/IntersectMBO/cardano-api/tree/bf84187ae986f9a2621c55b690638fe8bb2cb156. I changed this line of parseFilePath so that it used FILE as the metavariable name. This way the diff is greatly reduced, because FILE was the existing metavariable used so far most of the time. I then reviewed the golden files changes manually and everything was good.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • Self-reviewed the diff

@smelc smelc marked this pull request as ready for review September 11, 2024 15:44
Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

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

Nice work! There are some HLint warnings though.

<$> File
<$> parseFilePath
"calculate-plutus-script-cost"
"(File () Out) filepath of the script cost information."
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that it was copied from before, but I'm not sure about this haskell bit in the documentation: (File () Out). Seems odd, and not really informative for people not familiar with cardano-cli codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I changed the message 👍

, Opt.help help'
, Opt.completer (Opt.bashCompleter "file")
]
fmap File $ parseFilePath name help'
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I didn't know we had this function. I guess we should move it from cardano-api to cardano-cli and don't depend on optparse-applicative in cardano-api.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'm looking whether we can do that easily 👍

Copy link
Contributor Author

@smelc smelc Sep 12, 2024

Choose a reason for hiding this comment

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

Follow-up PRs: IntersectMBO/cardano-api#635 and #894

@smelc smelc force-pushed the smelc/share-code-in-filepaths-parsers branch from dad25dc to 108c1c2 Compare September 12, 2024 08:42
@smelc smelc added this pull request to the merge queue Sep 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 12, 2024
@smelc smelc added this pull request to the merge queue Sep 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Sep 12, 2024
@smelc smelc merged commit 39af17e into main Sep 12, 2024
27 checks passed
@smelc smelc deleted the smelc/share-code-in-filepaths-parsers branch September 12, 2024 15:21
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.

2 participants