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

Uniform version style for root package #51

Merged
merged 3 commits into from
Nov 24, 2017

Conversation

Jean85
Copy link
Contributor

@Jean85 Jean85 commented Nov 22, 2017

In Jean85/pretty-package-versions#3 I was made aware of the fact that the root package version is dumped in a different, normalized style; this is due to the fact that the root package version is not retrieved from the lock file like the other deps, and in the lock file the versions are not normalized.

This PR uses the PackageInterface::getPrettyVersion() from Composer to obtain the not-normalized version for the root package, obtaining a more uniform result.

This is needed since my wrapper is used as a way to output the current version in PHARs (i.e. PHPStan), where the subject is the root package by design.

@@ -3,27 +3,80 @@
namespace PackageVersions;

/**
* This is a stub class: it is in place only for scenarios where PackageVersions
Copy link
Owner

Choose a reason for hiding this comment

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

This file should not have been committed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Damn, my bad! That's also probably the cause behind the current CI failure...

'symfony/process' => 'v3.3.13@a56a3989fb762d7b19a0cf8e7693ee99a6ffb78d',
'theseer/tokenizer' => '1.1.0@cb2f008f3f05af2893a87208fe6a6c4985483f8b',
'webmozart/assert' => '1.2.0@2db61e59ff05fe5126d152bd0655c9ea113e550f',
'ocramius/package-versions' => '2.0.x-dev',
Copy link
Owner

Choose a reason for hiding this comment

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

Uhm... This doesn't look right to me. The hash should be there anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hash is there, that output was due to a previous iteration during my development where operator precedence tricked me. In fact I hadn't touched any other test apart from adding mine, so nothing has changed in expected behavior.

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 22, 2017

I've forced push the fix to avoid garbage in the Git history of the project. Now it should be good to go.

PS: I was thinking about adding a self key to the versions array as an alias for the root package, what do you think? Obviously I would do it in a separate PR...

@@ -177,6 +177,6 @@ private static function getVersions(Locker $locker, RootPackageInterface $rootPa
);
}

yield $rootPackage->getName() => $rootPackage->getVersion() . '@' . $rootPackage->getSourceReference();
yield $rootPackage->getName() => ($rootPackage->getPrettyVersion() ?? $rootPackage->getVersion()) . '@' . $rootPackage->getSourceReference();
Copy link
Owner

Choose a reason for hiding this comment

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

Which composer API introduced getPrettyVersion? Can you please make sure the constraints are correct for that to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I didn't check that because I thought that the --prefer-lowest of the CI covered that. I've tracked down the addition of that method to this commit from 2011: composer/composer@8e6f8ae#diff-d65a9c0319702b1659e4d5adce449e79

But I cannot find a source for the versioning of the API... where is it stored?

Copy link
Owner

@Ocramius Ocramius Nov 22, 2017

Choose a reason for hiding this comment

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

Should be

"composer-plugin-api": "^1.0"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I didn't explain me well... I don't know where I can find some docs or reference for that API so I can track down the corresponding version to that Composer commit!

Copy link
Contributor Author

@Jean85 Jean85 Nov 22, 2017

Choose a reason for hiding this comment

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

The plugin API version seems to have been declared here in 2013:

composer/composer@92b1ee2#diff-9761e5e6cef580d24c5a05d870dcc479R30

It's two years after getPrettyVersion got added to the interface, so we should be ok! 👍

Copy link

Choose a reason for hiding this comment

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

@Jean85 what's the case when you expect $rootPackage->getPrettyVersion() to return NULL so that the code falls back to using $rootPackage->getVersion()? Given that the pretty version is the one obtained from the VCS, it should be always available. Otherwise, there's nothing to be further normalized.

If I'm wrong, and it's possible then this case probably should be covered by an additional test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added that because it's already covered by some test somewhere. If you try to remove that, you will see PHPUnit fail.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm... that test may as well be wrong then. Can you dig it up so we review it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've commited the differences, see the latest commit of this PR: ca0fd61

I just had to update the mocks! I'll commit a small refactoring of the tests now...

Copy link
Owner

Choose a reason for hiding this comment

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

Looking good :-)

@Ocramius Ocramius added this to the 1.2.0 milestone Nov 22, 2017
@Ocramius Ocramius assigned Ocramius and unassigned Jean85 Nov 22, 2017
Copy link
Owner

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

Looking good! 👍

@@ -177,6 +177,6 @@ private static function getVersions(Locker $locker, RootPackageInterface $rootPa
);
}

yield $rootPackage->getName() => $rootPackage->getVersion() . '@' . $rootPackage->getSourceReference();
yield $rootPackage->getName() => ($rootPackage->getPrettyVersion() ?? $rootPackage->getVersion()) . '@' . $rootPackage->getSourceReference();
Copy link
Owner

Choose a reason for hiding this comment

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

👍

@Ocramius
Copy link
Owner

@Jean85 seems like you'll need a rebase before I can merge this.

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 22, 2017

Yep, the funny thing is that I de-synced it myself with #50 😄

@Ocramius
Copy link
Owner

@Jean85 I see you merged master into this branch: please do rebase instead.

@Ocramius Ocramius assigned Jean85 and unassigned Ocramius Nov 22, 2017
@Jean85
Copy link
Contributor Author

Jean85 commented Nov 22, 2017

@Ocramius sorry, I just used the web interface "Update branch" button, and I wasn't sure what it would do.

Rebased 👍

@Jean85
Copy link
Contributor Author

Jean85 commented Nov 24, 2017

Ok, I've fixed the mocks as per my comment and also pushed a small refactoring of the mock for the root package in the tests.

Copy link
Owner

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

@Jean85 awesome, thanks!

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.

3 participants