Skip to content

Make cabal init conform with --no-comments flag for commented fields #7770

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

Merged
merged 2 commits into from
Oct 27, 2021

Conversation

ptkato
Copy link
Collaborator

@ptkato ptkato commented Oct 23, 2021

This PR fixes #7769.


Please include the following checklist in your PR:

Comment on lines 68 to 78
| fieldContents == empty && (hasNoComments || isMinimal) =
fieldSEmptyContents NoComment
| fieldContents == empty =
fieldSEmptyContents $ commentPositionFor fieldName fieldComments

-- If the "--no-comments" or "--minimal" flag is set, strip comments.
| hasNoComments || isMinimal =
fieldSWithContents NoComment

| otherwise =
-- If the "--no-comments" or "--minimal" flag is set, strip comments.
let comments
| isMinimal = []
| hasNoComments = []
| otherwise = fieldComments

-- If the "--minimal" flag is set, strip comments.
in fieldSWithContents comments
fieldSWithContents $ commentPositionFor fieldName fieldComments
Copy link
Member

Choose a reason for hiding this comment

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

Can this be written more succinctly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could you elaborate?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't propose anything, just made a gut feeling suggestion. But if you'd like my help, let me think: wouldn't the following guards suffice: hasNoComments || isMinimal, otherwise. And if so, how come so much code is unneeded? Are we missing something?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh, I just swapped things around, to make it more uniform, that's all.

Copy link
Member

@Mikolaj Mikolaj Oct 23, 2021

Choose a reason for hiding this comment

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

Actually, my bad, I didn't notice that fieldSEmptyContents and fieldSWithContents are different functions. So the only simplification could be that fieldContents == empty decides between the two functions and hasNoComments || isMinimal between their arguments. But that's not necessarily more readable than separate four cases from multiplying the pair of two cases.

Copy link
Member

Choose a reason for hiding this comment

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

Well, let's try:

(if fieldContents == empty then fieldSEmptyContents else fieldSWithContents)
$ if hasNoComments || isMinimal then NoComment else commentPositionFor fieldName fieldComments

You be the judge.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's straightforwarder, but are you sure it's more readable?

Copy link
Member

@Mikolaj Mikolaj Oct 23, 2021

Choose a reason for hiding this comment

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

No, I don't think so. It makes it harder to mix up the two functions that I mixed up and makes it clearer which bits determine which outcome. However, it's overall much harder to read and it's an eureka moment to even discover this is four-branch conditional in disguise. As I said, you be the judge --- it's your PR.

Copy link
Member

@jneira jneira Oct 25, 2021

Choose a reason for hiding this comment

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

I think using a subexpression and guards make it more readable (and continue being more succint):

fieldD fieldName fieldContents fieldComments includeField opts
    | hasNoComments || isMinimal = contents NoComment
    | otherwise                  = contents $ commentPositionFor fieldName fieldComments

    where contents | fieldContents == empty = fieldSEmptyContents 
                   | otherwise              = fieldSWithContents

But being shorter is not the main goal imo but no repeat conditions, as you will have to remember update 2 call sites if they change. Boolean blindness will make types not help with that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is a sound strategy, I'll be using that.

Copy link
Member

@Mikolaj Mikolaj left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -1,11 +1,7 @@
executable y
Copy link
Member

@jneira jneira Oct 25, 2021

Choose a reason for hiding this comment

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

I've observed comments are being removed from test cases with -no-comment suffix (so makes total sense) but also from test cases without that suffix, is that on purpose? i suppose we have still test cases with comments, should we suffix these cases with -no-comment as well to be consistent?

Copy link
Collaborator Author

@ptkato ptkato Oct 26, 2021

Choose a reason for hiding this comment

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

It is on purpose, they're set to no comments, see here:

let opts = WriteOpts False False True v pkgDir Executable pkgName defaultCabalVersion

Copy link
Member

Choose a reason for hiding this comment

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

Well i think if all cases without comments had have the -no-comment suffix maybe it would be more evident that something was wrong with the test cases themselves, as they had comments!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Here we go, now the golden files have more meaningful names.

Copy link
Member

Choose a reason for hiding this comment

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

Great, thanks for take in account our feedback 👍

@ptkato ptkato force-pushed the cabal-init-commented-comments branch 2 times, most recently from 6d1a4aa to e211005 Compare October 26, 2021 18:44
@ptkato ptkato force-pushed the cabal-init-commented-comments branch from e211005 to 96375e5 Compare October 26, 2021 20:01
Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

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

LGTM

@Mikolaj
Copy link
Member

Mikolaj commented Oct 26, 2021

@andreasabel: does the failure in docs/readthedocs.org:cabal job tell you anything? We are now waiting for your docs test to pass (or not) to compare...

@andreasabel
Copy link
Member

@andreasabel: does the failure in docs/readthedocs.org:cabal job tell you anything? We are now waiting for your docs test to pass (or not) to compare...

Er, no, my docs test, named "Users guide" did not run on this PR, as it is only triggered by changes under /doc/ (see below).

This is the "Read the Docs" CI that is failing. I did not contribute it.
I looked at the error it reports, but it does not ring a bell.

name: Users guide
on:
push:
branches:
- master
paths:
- 'doc/requirements.txt'
- 'doc/*.inc'
- 'doc/*.py'
- 'doc/*.rst'
- 'doc/**/*.json'
- '.github/workflows/users-guide.yml'
pull_request:
paths:
- 'doc/requirements.txt'
- 'doc/*.inc'
- 'doc/*.py'
- 'doc/*.rst'
- 'doc/**/*.json'
- '.github/workflows/users-guide.yml'

@andreasabel
Copy link
Member

andreasabel commented Oct 27, 2021

I tried to get more information on the docs/readthedocs.org:cabal workflow, but the relevant discussion ends without a resolution, see #7647 (comment).

@Mikolaj
Copy link
Member

Mikolaj commented Oct 27, 2021

@andreasabel: thank you, in that case, let me mark your test, again, as not mandatory in Settings/

@fgaz
Copy link
Member

fgaz commented Oct 27, 2021

I triggered a readthedocs build on master and it failed, so as expected the problem isn't introduced with this pr

@andreasabel
Copy link
Member

@Mikolaj

@andreasabel: thank you, in that case, let me mark your test, again, as not mandatory in Settings/

Ah, so the PR was waiting for my test, which did not run because it is not triggered?
This is not visible from my POV, the list has no entry for "Users guide", and also I have no access to the Settings.

Of course, if the semantics of "mandatory" is "needs to run, and needs to succeed" (Run & Succeed) rather than "if it runs it should succeed" (Run => Succeed), then my test should not be "mandatory".

@Mikolaj
Copy link
Member

Mikolaj commented Oct 27, 2021

Ah, so the PR was waiting for my test, which did not run because it is not triggered?

That's only because I force-added it to Settings/ after asking around on #hackage.

This is not visible from my POV, the list has no entry for "Users guide",

That's, because I've now removed it from Settings/.

Of course, if the semantics of "mandatory" is "needs to run, and needs to succeed" (Run & Succeed) rather than "if it runs it should succeed" (Run => Succeed), then my test should not be "mandatory".

Sadly, that's the semantics, so it was waiting for your test when it was marked in Settings for a moment (in a failed effort to check if it fails similarly to readthedocs test).

@andreasabel
Copy link
Member

andreasabel commented Oct 27, 2021

@fgaz wrote:

I triggered a readthedocs build on master and it failed, so as expected the problem isn't introduced with this pr

Also, locally the docs build fine with make users-guide.

A documentation concerning the offending section_self_link is here:
https://docutils.sourceforge.io/docs/user/config.html#section-self-link
It says:

New in Docutils 0.18.

Locally, I get 0.16:

docutils>=0.12 in ./.python-sphinx-virtualenv/lib/python3.9/site-packages (from sphinx==3.1.*->-r doc/requirements.txt (line 1)) (0.16)

Remotely (on rtd), 0.18 is used:

Requirement already satisfied: docutils>=0.12 in /home/docs/checkouts/readthedocs.org/user_builds/cabal/envs/7770/lib/python3.7/site-packages (from sphinx==3.1.*->-r doc/requirements.txt (line 1)) (0.18)

That can make the difference.
Likely, our requirements.txt is not watertight, so we might get packages that do not work together. (For developers of cabal, this is quite ironical, hahaha!)

@Mikolaj
Copy link
Member

Mikolaj commented Oct 27, 2021

@andreasabel: thank you for diagnosing the problem and opening a new issue.

@ptkato: in that case, we are making ourselves scarce from your PR. Given that all other jobs passed fine, let me merge manually.

@Mikolaj
Copy link
Member

Mikolaj commented Oct 27, 2021

@Mergifyio rebase

@mergify
Copy link
Contributor

mergify bot commented Oct 27, 2021

rebase

☑️ Nothing to do

  • -closed [:pushpin: rebase requirement]
  • #commits-behind>0 [:pushpin: rebase requirement]

@Mikolaj Mikolaj merged commit 41ed090 into haskell:master Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cabal init does not respect --no-comments for empty (commented out) fields
5 participants