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

Fix #18: add support for deprecated-versions #49

Merged
merged 13 commits into from
May 15, 2023

Conversation

yvan-sraka
Copy link
Contributor

@yvan-sraka yvan-sraka commented Apr 2, 2023

This is a modest work in progress Pull-Request, I wanted to double-check with you in first place if I effectively edited the right parts of the codebase?

@yvan-sraka yvan-sraka marked this pull request as draft April 2, 2023 22:29
@andreabedini
Copy link
Member

@yvan-sraka I am aware it's a draft but I left some comments to put you in the right direction. Ping me if you have questions!

@yvan-sraka yvan-sraka force-pushed the deprecated-versions branch from 9a86e4c to 6031717 Compare April 11, 2023 07:56
@yvan-sraka yvan-sraka changed the title [WIP] Fix #18: add support for deprecated-versions Fix #18: add support for deprecated-versions Apr 11, 2023
@yvan-sraka yvan-sraka marked this pull request as ready for review April 11, 2023 07:57
@yvan-sraka
Copy link
Contributor Author

@yvan-sraka I am aware it's a draft but I left some comments to put you in the right direction. Ping me if you have questions!

Thank you for your early review and comments, it definitely helped me! I just pushed my last week's work, it seems to works as expected against my local manual experiments. Are there some test scenarios I can run this PR against to be confident it's fully working as intended, if not, I could try to add them in another PR!

I left TODO code comments about some parts I'm not fully comfortable with, thank you again for your review :)

@yvan-sraka yvan-sraka requested a review from andreabedini April 11, 2023 08:02
Copy link
Member

@andreabedini andreabedini left a comment

Choose a reason for hiding this comment

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

I reviewed the core changes, we can check the webpages when the core logic is working.

app/Foliage/Meta.hs Outdated Show resolved Hide resolved
app/Foliage/Meta.hs Outdated Show resolved Hide resolved
app/Foliage/Meta.hs Outdated Show resolved Hide resolved
app/Foliage/PreparePackageVersion.hs Show resolved Hide resolved
app/Foliage/PreparePackageVersion.hs Outdated Show resolved Hide resolved
app/Foliage/PreparePackageVersion.hs Outdated Show resolved Hide resolved
app/Foliage/CmdBuild.hs Outdated Show resolved Hide resolved
@yvan-sraka yvan-sraka force-pushed the deprecated-versions branch from 427ee3e to 5b62981 Compare April 13, 2023 08:28
app/Foliage/CmdBuild.hs Outdated Show resolved Hide resolved
@michaelpj
Copy link
Collaborator

Also perhaps this could be the PR that finally introduces some tests? :D

@yvan-sraka yvan-sraka force-pushed the deprecated-versions branch 2 times, most recently from 5ea8ae8 to 4e349c6 Compare April 15, 2023 23:20
@yvan-sraka
Copy link
Contributor Author

I reworked the core logic thanks to your feedbacks :)

@yvan-sraka
Copy link
Contributor Author

Also perhaps this could be the PR that finally introduces some tests? :D

I started something simple here #50, the idea would be to write something End-2-End by spawning some HTTP server and then run Cabal against it! Is it the kind of tests you had in mind?

@yvan-sraka yvan-sraka force-pushed the deprecated-versions branch from 4e349c6 to 4974e12 Compare April 16, 2023 10:13
@michaelpj
Copy link
Collaborator

the idea would be to write something End-2-End by spawning some HTTP server and then run Cabal against it

Cabal can run against a file repository, so no need for the server. We could do this, but we could also do simpler things like just making some assertions about the content of the index tarball. Or we could try and use some logic from cabal the library to test if the repository looks right without having to run cabal separately.

Copy link
Member

@andreabedini andreabedini left a comment

Choose a reason for hiding this comment

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

The logic is still not correct. I had a go myself and, to be fair, the end result looks a bit convoluted:

We start from packagesVersions which is roughtly [(PackageId, [(Timestamp, Bool)])]

The deprecated versions are per package so we need to group per package name:

~ [(PackageName, [(PackageVersion, [(Timestamp, Bool)])])]

Then, for each package, we need to take all version deprecation changes, sort them by the timestamp, accumulate them into version ranges:

  1. Flatten on the deprecation changes ~ [(PackageName, [(Timestamp, PackageVersion, Bool)])]
  2. Accumulate into version ranges ~ [(PackageName, [(Timestamp, VersionRange)])]

Then, we flatten on the timestamp to spit out each index entry.

  1. Flatten on timestamp ~ [(PackageName, Timestamp, VersionRange)]

I'll paste my code soon, just need to double check.

PS: There's a fair bit of whitespace change. I don't mind it di-per-se but I'd avoid changing whitespace back and forth. FWIW I use the default formatting with hls (which I think is ormolu but I am not sure).

app/Foliage/CmdBuild.hs Show resolved Hide resolved
app/Foliage/PreparePackageVersion.hs Outdated Show resolved Hide resolved
app/Foliage/Meta.hs Outdated Show resolved Hide resolved
app/Foliage/Meta.hs Outdated Show resolved Hide resolved
app/Foliage/PreparePackageVersion.hs Outdated Show resolved Hide resolved
app/Foliage/CmdBuild.hs Outdated Show resolved Hide resolved
@andreabedini
Copy link
Member

Something like this

    let extraEntries =
          foldMap
            ( \packageGroup ->
                let pn = pkgName $ pkgId $ NE.head packageGroup
                    deprecationChanges =
                      sortOn fst $
                        foldMap
                          ( \PreparedPackageVersion {pkgId = PackageIdentifier {pkgVersion}, pkgVersionDeprecationChanges} ->
                              map
                                ( second $
                                    \deprecated ->
                                      if deprecated
                                        then intersectVersionRanges (notThisVersion pkgVersion)
                                        else unionVersionRanges (thisVersion pkgVersion)
                                )
                                pkgVersionDeprecationChanges
                          )
                          packageGroup
                    effectiveRanges =
                      NE.tail $
                        NE.scanl
                          (\(_, range) (ts, change) -> (ts, simplifyVersionRange $ change range))
                          (0, anyVersion)
                          deprecationChanges
                 in map
                      ( \(ts, effectiveRange) ->
                          mkTarEntry (BL.pack $ show effectiveRange) (IndexPkgPrefs pn) ts
                      )
                      effectiveRanges
            )
            (NE.groupWith (pkgName . pkgId) packageVersions)

It's only left ot make it readable (and to test it) 😂

@yvan-sraka yvan-sraka force-pushed the deprecated-versions branch from 2e27d6b to 7da6927 Compare April 20, 2023 14:45
@yvan-sraka
Copy link
Contributor Author

PS: There's a fair bit of whitespace change. I don't mind it di-per-se but I'd avoid changing whitespace back and forth. FWIW I use the default formatting with hls (which I think is ormolu but I am not sure).

Weird, I use ormolu, but I can revert the whitespace changes :)

@yvan-sraka yvan-sraka requested a review from andreabedini April 20, 2023 14:48
@andreabedini andreabedini requested review from andreabedini and removed request for andreabedini May 3, 2023 07:35
@andreabedini
Copy link
Member

@michaelpj I think this is now in a decent shape. Would you have time to give it another look and a test?

getExtraEntries :: [PreparedPackageVersion] -> [Tar.Entry]
getExtraEntries packageVersions =
let groupedPackageVersions = NE.groupWith (pkgName . pkgId) packageVersions
generateEntriesForGroup packageGroup = map createTarEntry effectiveRanges
Copy link
Collaborator

Choose a reason for hiding this comment

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

I generally appreciate type signatures for more complex functions like this!

Copy link
Member

Choose a reason for hiding this comment

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

I added the signatures and more comments.

app/Foliage/CmdBuild.hs Show resolved Hide resolved

-- Apply a given change (`VersionRange -> VersionRange`) to a `VersionRange` and
-- return the simplified the result with a new timestamp.
applyChangeToRange :: (UTCTime, VersionRange) -> (UTCTime, VersionRange -> VersionRange) -> (UTCTime, VersionRange)
Copy link
Collaborator

Choose a reason for hiding this comment

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

almost the applicative instance for Timestamped 😂

Copy link
Member

@andreabedini andreabedini May 15, 2023

Choose a reason for hiding this comment

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

I guess it's

newtype Timestamped a = Timestamped (Maybe (Last UTCTime), a)
  deriving (Show, Eq, Ord)
  deriving (Functor, Applicative) via Ap ((,) (Maybe (Last UTCTime)))

app/Foliage/CmdBuild.hs Show resolved Hide resolved
app/Foliage/Meta.hs Show resolved Hide resolved
-- original cabal file
AllPackageVersionsPageEntryPackage
{ allPackageVersionsPageEntryPkgId = pkgId,
allPackageVersionsPageEntryTimestamp = fromMaybe currentTime pkgTimestamp,
allPackageVersionsPageEntryTimestampPosix = utcTimeToPOSIXSeconds (fromMaybe currentTime pkgTimestamp),
allPackageVersionsPageEntrySource = pkgVersionSource
allPackageVersionsPageEntrySource = pkgVersionSource,
-- FIXME: this weirdly seems to not work (display a `Deprecated` badge on all package version page) ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

going to fix it now or not? It potentially suggests a bug in how we're deciding if things are deprecated or not, which seems serious...

Copy link
Collaborator

Choose a reason for hiding this comment

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

if only we had tests :)

Copy link
Member

Choose a reason for hiding this comment

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

Right, I forgot about that note. It was put there before lots of changes so I wonder it's still true.

Copy link
Member

Choose a reason for hiding this comment

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

There was a missing </td>, it's fixed now.

app/Foliage/PreparePackageVersion.hs Show resolved Hide resolved
app/Foliage/PreparePackageVersion.hs Show resolved Hide resolved
app/Foliage/PreparePackageVersion.hs Outdated Show resolved Hide resolved
@yvan-sraka yvan-sraka self-assigned this May 3, 2023
@yvan-sraka
Copy link
Contributor Author

Should I perhaps rebase this PR on top of #51?

@andreabedini
Copy link
Member

Should I perhaps rebase this PR on top of #51?

I should keep them separate, there should not be a big overlap. Also #51 doesn't seem to be working at the moment.

@andreabedini
Copy link
Member

@yvan-sraka @michaelpj I want to merge this soon. Please have a last look.

Copy link
Collaborator

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

Haven't tested (I assume you have), but looks fine!

@andreabedini
Copy link
Member

I tested what I could. I guess we should just press this green button and see what happens 😂

@andreabedini andreabedini merged commit 6c39112 into input-output-hk:main May 15, 2023
@yvan-sraka yvan-sraka deleted the deprecated-versions branch June 9, 2023 11:48
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.

Add support for deprecated-versions Add support for preferred-versions
3 participants