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

Deduplicate "using config from" message #10546

Merged
merged 2 commits into from
Dec 14, 2024

Conversation

philderbeast
Copy link
Collaborator

@philderbeast philderbeast commented Nov 11, 2024

Adds an Ord instance for ProjectConfigPath and fixes the duplication in the reported "Configuration is affected by the following files", fixes #10509 by using docProjectConfigFiles instead of docProjectConfigPath.

Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@philderbeast philderbeast changed the title Fix/dedup using config from Deduplicate "using config from" message Nov 12, 2024
@philderbeast philderbeast force-pushed the fix/dedup-using-config-from branch 2 times, most recently from 290bd75 to 8423986 Compare November 12, 2024 01:21
ulysses4ever
ulysses4ever previously approved these changes Nov 12, 2024
@ulysses4ever
Copy link
Collaborator

This fixes the duplication in the reported "Configuration is affected by the following files"

I think it fixes only part of the duplication problem in the snippet you reference. I.e. it dedups file names but it doesn't dedup the phrase "Configuration is affected by the following files". The latter seem to be a bug in the way that snippet is written: there shouldn't be a sequence_ at all. What it should look like is:

    notice verbosity . render . vcat $
      text "Configuration is affected by the following files:"
        : [ text "-" <+> docProjectConfigPath path
          | Explicit path <- Set.toList $ projectConfigProvenance projectConfig
          ]

@philderbeast philderbeast force-pushed the fix/dedup-using-config-from branch from 8423986 to f6a310b Compare November 12, 2024 11:59
@ulysses4ever
Copy link
Collaborator

I'm already doing dedup of the intro message as a part of #10548 btw. It'd be best if this one only handled the Ord instance.

It's also a bit more complicated than I said above: with implicit config provenance, it'll print the intro message and then nothing else, which doesn't make sense. THis is not hard to fix of course.

@philderbeast philderbeast marked this pull request as draft November 12, 2024 13:17
@philderbeast philderbeast force-pushed the fix/dedup-using-config-from branch from f6a310b to f28cb93 Compare November 12, 2024 15:07
@philderbeast
Copy link
Collaborator Author

@mpickering for these added tests do we already have a normalization of the project root directory for tests, something like <PROJECT-ROOT>, now that tests are run in temporary directories with #9717?

$ git diff 
...
--- a/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
+++ b/cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
@@ -261,6 +261,49 @@ main = cabalTest . withRepo "repo" . recordMode RecordMarked $ do
   log "checking if we detect when the same config is imported via many different paths (we don't)"
   woopping <- cabal' "v2-build" [ "--project-file=woops-0.project" ]
 
+  log "checking \"using config from message\" without URI imports"
+  withDirectory "yops" $ do
+    yopping <- fails $ cabal' "v2-build" [ "--project-file=../yops-0.project" ]
+    assertOutputContains
+      (normalizeWindowsOutput "When using configuration from: \
+      \ - /tmp/cabal-testsuite-286573/yops-0.project \
+      \ - /tmp/cabal-testsuite-286573/yops-2.config \
+      \ - /tmp/cabal-testsuite-286573/yops-4.config \
+      \ - /tmp/cabal-testsuite-286573/yops-6.config \
+      \ - /tmp/cabal-testsuite-286573/yops-8.config \
+      \ - /tmp/cabal-testsuite-286573/yops/yops-1.config \
+      \ - /tmp/cabal-testsuite-286573/yops/yops-3.config \
+      \ - /tmp/cabal-testsuite-286573/yops/yops-5.config \
+      \ - /tmp/cabal-testsuite-286573/yops/yops-7.config \
+      \ - /tmp/cabal-testsuite-286573/yops/yops-9.config \
+      \ The following errors occurred: \
+      \  - The package directory '.' does not contain any .cabal file.")
+      yopping
+
+    return ()
+
+  log "checking \"using config from message\" with URI imports"
+  withDirectory "woops" $ do
+    woopping <- fails $ cabal' "v2-build" [ "--project-file=../woops-0.project" ]
+    assertOutputContains
+      (normalizeWindowsOutput "When using configuration from: \
+      \ - /tmp/cabal-testsuite-282695/woops-0.project \
+      \ - /tmp/cabal-testsuite-282695/woops-2.config \
+      \ - /tmp/cabal-testsuite-282695/woops-4.config \
+      \ - /tmp/cabal-testsuite-282695/woops-6.config \
+      \ - /tmp/cabal-testsuite-282695/woops-8.config \
+      \ - /tmp/cabal-testsuite-282695/woops/woops-1.config \
+      \ - /tmp/cabal-testsuite-282695/woops/woops-3.config \
+      \ - /tmp/cabal-testsuite-282695/woops/woops-5.config \
+      \ - /tmp/cabal-testsuite-282695/woops/woops-7.config \
+      \ - /tmp/cabal-testsuite-282695/woops/woops-9.config \
+      \ - https://www.stackage.org/lts-21.25/cabal.config \
+      \ The following errors occurred: \
+      \  - The package directory '.' does not contain any .cabal file.")
+      woopping
+
+    return ()

@ulysses4ever
Copy link
Collaborator

something like <PROJECT-ROOT>

The previous person who bumped into this problem wasn't able to find an existing solution: #8617 (comment)

@philderbeast philderbeast force-pushed the fix/dedup-using-config-from branch 3 times, most recently from bf674e3 to 7070d18 Compare November 13, 2024 19:43
@philderbeast
Copy link
Collaborator Author

@ulysses4ever and @mpickering, to get around the /tmp/cabal-testsuite-286573/yops-0.project problem I used assertRegex.

I see that cabal' "v2-build" [ "--project-file=yops-0.project" ] does not set the test environment's project.

-- | Says what cabal.project file to use (probed)
, testCabalProjectFile :: Maybe FilePath

@philderbeast philderbeast marked this pull request as ready for review November 13, 2024 19:48
@philderbeast
Copy link
Collaborator Author

This will need another review because previously I'd mucked up the Ord instance.

@philderbeast
Copy link
Collaborator Author

philderbeast commented Nov 13, 2024

I didn't add a test of an http import importing another http config file. Two possible ways of doing this are running a local server for the test or picking up the import from somewhere like https://raw.githubusercontent.com/haskell/cabal/refs/heads/master/cabal.project.

@ulysses4ever
Copy link
Collaborator

I'm traveling this week, so will only be able to get to this next week at earliest. Sorry!

@philderbeast
Copy link
Collaborator Author

I'm already doing dedup of the intro message

@ulysses4ever there are two similar messages. You've dealt with the Configuration is affected by the following files one in #10548 and I'm dealing with the other one here, with When using configuration from.

$ grep -R -E 'When using configuration from|Configuration is' ./**/*.hs --exclude='*.test.hs'
./cabal-install/src/Distribution/Client/ProjectConfig.hs:      "When using configuration from:\n"
./cabal-install/src/Distribution/Client/ProjectPlanning.hs:        text "Configuration is affected by the following files:" : configfiles

@philderbeast philderbeast force-pushed the fix/dedup-using-config-from branch from 7070d18 to 88b92e6 Compare November 14, 2024 12:37
@geekosaur
Copy link
Collaborator

I can dismiss it (click the downarrow to the right of "2 approvals", then the 3-dots to the right of his approval), but I'm not sure if that's an admin action or something you can do. Do you want me to dismiss it?

@philderbeast
Copy link
Collaborator Author

Thanks @geekosaur, I can dismiss it.

@philderbeast philderbeast dismissed ulysses4ever’s stale review December 10, 2024 02:31

This was a review of an earlier version with an incorrect Ord instance.

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.

This is quite delicate and I guess the devil might be in the details, but the tests are solid and LGTM.

@philderbeast
Copy link
Collaborator Author

@Mikolaj, I've updated the haddocks on Ord ProjectConfigPath.

@philderbeast
Copy link
Collaborator Author

Label merge+no rebase is necessary when the pull request is from an organisation.

@mergify mergify bot added the ready and waiting Mergify is waiting out the cooldown period label Dec 11, 2024
Copy link
Collaborator

@9999years 9999years left a comment

Choose a reason for hiding this comment

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

Looks reasonable. I think the release note could use a before/after example to show how this helps users. (I don't care about an Ord instance but I care a lot about error message quality!)

@Kleidukos Kleidukos added the attention: needs-manual-qa PR is destined for manual QA label Dec 11, 2024
- Consider URI in Ord instance
- Use <> in Ord instance of ProjectConfigPath
- Add unconsProjectConfigPath
- Add docProjectConfigFiles
- Remove docProjectConfigPaths
- Clarify sorting haddocks for Ord ProjectConfigPath
@philderbeast
Copy link
Collaborator Author

philderbeast commented Dec 12, 2024

@9999years I've updated the changelog entry to talk more about the "using configuration from" message changes.

@Kleidukos what is the attention: needs-manual-qa label for other than to hold off on mergify merging? If that is its purpose then I can wait until @9999years gives me the OK on the changelog, squash the recent commits and then remove this label myself.

@philderbeast philderbeast force-pushed the fix/dedup-using-config-from branch from f4d9610 to 95b78e2 Compare December 12, 2024 16:48
@Kleidukos
Copy link
Member

@philderbeast that label does not prevent merging, it's for after-merge :)

@9999years
Copy link
Collaborator

(I had also approved it beforehand so as not to block the merge)

- Add woops test
- Regen expected output without duplication
- Add "when using config from" tests
- Remove unnecessary normalizeWindowsOutput
- Change assertion message
- Match on (\n|\r\n) for line endings
- Note /tmp/cabal-testsuite-*/ not seen on Windows
- Always have the project itself sort first
- Use with-ghc.config with woops project
- Remove docProjectConfigPaths
- docProjectConfigFiles is the better name when not reporting "imported by"
- Use --dry-run for config listing tests
- Only use woops project once in tests
- Don't use same project twice in tests
- Put dedup test into its own folder
- Simplify the project file names
- Can be done now that the test is in its own folder
- Move using config dedup test to ProjectImport dir
- Remove an additional test on yops project
- checking "using config from message" without URI imports
- Add simple test for changelog
- Better explain the message changes
- Redo the test so the project doesn't sort 1st
- Don't need to specify default project explicitly
- Add a z-empty.config lexically sorted last
@philderbeast philderbeast force-pushed the fix/dedup-using-config-from branch from 95b78e2 to 73a13f1 Compare December 12, 2024 18:26
@mergify mergify bot added the merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days label Dec 14, 2024
@mergify mergify bot merged commit 33b19e4 into haskell:master Dec 14, 2024
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
attention: needs-manual-qa PR is destined for manual QA merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge+no rebase ready and waiting Mergify is waiting out the cooldown period
Projects
Status: To Test
Development

Successfully merging this pull request may close these issues.

What should we report when there are duplicate imports?
6 participants