Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Introduce weak vendors mode#21539

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfromgreg0ire:weak_vendors
Feb 28, 2017
Merged

Conversation

@greg0ire
Copy link
Contributor

@greg0iregreg0ire commentedFeb 5, 2017
edited
Loading

Deprecations coming from the vendors are segregated from other
deprecations. A new mode is introduced, in which deprecations coming
from the vendors are not taken into account when deciding to exit with
an error code.

QA
Branch?master
Bug fix?no
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
LicenseMIT
Doc PRsymfony/symfony-docs#7453

Sample output :

Weak vendor mode

With both vendors and non-vendor errors

WARNINGS!Tests: 1068, Assertions: 2714, Warnings: 6, Skipped: 15.Remaining deprecation notices (1)some error: 1x    1x in SonataAdminBundleTest::testBuild from Sonata\AdminBundle\TestsRemaining vendor deprecation notices (4)Legacy deprecation notices (48)

Exit code is 1

After fixing non-vendor errors

WARNINGS!Tests: 1068, Assertions: 2714, Warnings: 6, Skipped: 15.Remaining vendor deprecation notices (4)Legacy deprecation notices (48)

Exit code is 0

TODO

  • fix colorization issues (vendor deprecation notices are always in red)
  • make the vendor detection more robust
  • make the vendor dir configurable
  • figure out how to run tests and add more of them
    • test on non-vendor file
    • test on vendor file
  • do not change the output of other modes

Taluu, dbu, and soullivaneuh reacted with thumbs up emoji
@nicolas-grekas
Copy link
Member

nicolas-grekas commentedFeb 5, 2017
edited
Loading

I see two issues here:

  • the first, minor, is that the vendor dir is not always called "vendors"
  • the second is more serious: any code in vendors is always called by some code in userland. Code don't get called magically - but because userland asked for it - thus there is not such thing as "vendor deprecations" vs others. Or do you have a way to decide that works reliably?

@greg0ire
Copy link
ContributorAuthor

greg0ire commentedFeb 5, 2017
edited
Loading

  1. Yes that's an issue (see my todo list), maybe I can work around that with another env var?
  2. Not an issue IMO, I'm only looking at the first file of the stack trace, which is the one wheretrigger_error is written. Quoting themanual : "The third parameter is optional, errfile, which contains the filename that the error was raised in, as a string. " So to sum up, a deprecation is a "vendor deprecations" iff thetrigger_error that raises it is written in a file that lives invendor

$trace =debug_backtrace(true);
$group ='other';

$isVendor = (strpos($file,'/vendor/') !==false);
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

@nicolas-grekas : we're outside the while on$trace here, so really, we're not looking at every file of the stack trace, but only at the file that has the error triggered in it.

@greg0ire
Copy link
ContributorAuthor

Third issue, even more minor, some people might have avendor directory inside theirsrc (why not). Might be solvable with__DIR__ though.

@nicolas-grekas
Copy link
Member

I'm only looking at the first file of the stack trace

That means you target deprecations triggered by code in src/. Ok.

For vendors, see my PR about ComposerResource.

greg0ire reacted with thumbs up emoji

@greg0ire
Copy link
ContributorAuthor

I'm only looking at the first file of the stack trace

Actually that was wrong and has nothing to do with the stack trace, I'm looking at the$errfile argument of the error handler function. So if I have a file insrc, that calls a function from thevendor dir, that has atrigger_error in it,$errfile will bevendor/callee.php, and notsrc/caller.php, right?

@greg0ire
Copy link
ContributorAuthor

For vendors, see my PR about ComposerResource.

link for the lazy

soullivaneuh reacted with thumbs up emoji

@ogizanagi
Copy link
Contributor

link for the laziest 😄

greg0ire, lenybernard, and soullivaneuh reacted with laugh emoji

@greg0ire
Copy link
ContributorAuthor

greg0ire commentedFeb 5, 2017
edited
Loading

Maybe I should explain a bit more the goal of this PR, I feel I'm being unclear.

This is going to used way more in libs than in project, that seldom use deprecation notices themselves.@nicolas-grekas I think that's why you talk about userland vs vendors.

Let there be lib X, that has n dependencies. Anytime any of the n dependencies introduces a new deprecation, I have to fix it, andno PR can be merged during that time, unless I useSYMFONY_DEPRECATIONS_HELPER=weak.

And that's what I do most of the time, because I don't want to shift the burden of fixing these to anyone who wants to contribute anything unrelated to the vendor lib, and has the bad luck of doing so at the wrong time.

Now let's suppose a contributor submits a new PR, and let's suppose that that PR introduces a deprecation notice inthe codebase of the lib , and by that I don't mean a deprecated call to another lib, I mean a call totrigger_error directly. Then they must be careful to mark all corresponding tests with@group legacy, and fix all calls throughout the codebase of the lib so that they use the new way of doing things.

In my experience, many people forget to do that, and deprecations are introduced, that could easily be avoided. Seethis PR where I end up doing the work that should have been done by the contributor from the start.

@nicolas-grekas
Copy link
Member

Doc PR would be really nice before merging since the use case should be explained there :)

@stof
Copy link
Member

stof commentedFeb 6, 2017

@greg0ire the issue is that your logic looks wrong. Vendor deprecations must not be distinguished based on the location of the deprecation, but based on the caller location.
You will almost never call your own deprecated code, as you are also the one deprecating it. However, you are very likely to be calling a deprecated method of one of your dependency. In this case,trigger_error is inside the vendor folder, but the place needing to be fixed is inside your own code.
And using the backtrace to identify whether it is called from your own code or no is fragile, because your code may not be the direct caller. We have cases in Symfony where we have more classes between your own code and the code triggering the deprecation for instance, while the fix is still needed in your own code, for instance when asking to migrate from a type name to a class name to reference form types in Symfony 2.8

@greg0ire
Copy link
ContributorAuthor

greg0ire commentedFeb 6, 2017
edited
Loading

You will almost never call your own deprecated code, as you are also the one deprecating it

That's precisely the case I'm trying to help fix however.There are contributors that contribute new deprecations, and forget to fix these calls. Then it get merged, but could have easily be prevented. Also, there are tests that are marked with@group Legacy (note the capital), which does not work either. That could also have been prevented easily. Or they just outright forget to mark tests with@group legacy That's what I want to catch here.

And using the backtrace to identify whether it is called from your own code or no is fragile

I'm not doing that (I think). I'm not indentify the caller location, I'm identifying the callee location. When developing a lib, the lib is always calling others or itself, but no other lib is calling my lib. So in that case, I think it's safe to want to know "is there any call to a deprecated methodof my lib in the codebaseof my lib?"

horizontally: caller / vertically: calleemy libmy dependency
my libThis is the case I want to catch. It can only be introduced in new contributions that come with a deprecation noticeCannot happen in the context of testing a library. If it happens, it means the dependency knows the lib, and that we have a circular dependency.
my dependencyThis is the case I don't want to catch, because it would make the build fail randomlyCan't happen either in the context of testing lib.

@greg0ire
Copy link
ContributorAuthor

Doc PR would be really nice before merging since the use case should be explained there :)

Didn't notice your comment. Will do!

@greg0ire
Copy link
ContributorAuthor

Here is the docs PR

@nicolas-grekas
Copy link
Member

Thanks, just posted a few short notes

greg0ire reacted with thumbs up emoji

$mode =getenv('SYMFONY_DEPRECATIONS_HELPER');
}
if (DeprecationErrorHandler::MODE_WEAK !==$mode && (!isset($mode[0]) ||'/' !==$mode[0])) {
if (!in_array($mode,array(
Copy link
Contributor

Choose a reason for hiding this comment

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

Missingtrue as a 3rd parameter forin_array:https://3v4l.org/hsgBm

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

fixed, thanks!

Choose a reason for hiding this comment

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

the in_array + line splits look unreadable to me - what about using two comparisons on a single line instead?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I think it's a matter of taste, because to me the more readable version is of course mine. Plus it's less repetitive. I'll do as you say though, b/c you're probably more aware of what the sf style is.

@greg0ire
Copy link
ContributorAuthor

I changed the code so that other modes output is no longer split into vendors / non-vendors.

@greg0iregreg0ireforce-pushed theweak_vendors branch 2 times, most recently from028a816 tobd8f0b3CompareFebruary 8, 2017 22:49
@greg0ire
Copy link
ContributorAuthor

I fixed the colorization issue, deprecation notices are always in yellow now.

@fabpot
Copy link
Member

fabbot reports errors that should be fixed.

@greg0ire
Copy link
ContributorAuthor

@fab{b,p}ot : fixed

yceruto and soullivaneuh reacted with laugh emoji

@greg0ire
Copy link
ContributorAuthor

I rebased again, can anyone review and remove the "Needs work" label? This is supposed to be finished.

@greg0ire
Copy link
ContributorAuthor

Changed the poor man's error handler fromvar_dump toprint_r after discussing with@Nek-

$colorize =function ($str) {return$str; };
}
if ($currErrorHandler !==$deprecationHandler) {
print_r(error_get_last());

Choose a reason for hiding this comment

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

unrelated, and very fragile to me, should be removed from this PR

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ok let's remove it.

Copy link
ContributorAuthor

@greg0iregreg0ireFeb 21, 2017
edited
Loading

Choose a reason for hiding this comment

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

Not sure what exactly qualifies as fragile here though. I think both methods are rock solid.

Choose a reason for hiding this comment

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

the link betweenerror_get_last() and the error handler change - maybe I'm wrong - it's still unrelated so please open another PR if you want to investigate the idea

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Unrelated indeed. Will do

A new mode is introduced, in which deprecations coming from the vendorsare not taken into account when deciding to exit with an error code. Inthis mode, deprecations coming from the vendors are segregated fromother deprecations.
@greg0ire
Copy link
ContributorAuthor

This is supposed to be ready on my end, please review again.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

👍

@fabpot
Copy link
Member

Thank you@greg0ire.

greg0ire and sstok reacted with hooray emoji

@fabpotfabpot merged commit61fd043 intosymfony:masterFeb 28, 2017
fabpot added a commit that referenced this pull requestFeb 28, 2017
This PR was merged into the 3.3-dev branch.Discussion----------Introduce weak vendors modeDeprecations coming from the vendors are segregated from otherdeprecations. A new mode is introduced, in which deprecations comingfrom the vendors are not taken into account when deciding to exit withan error code.| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | no| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| License       | MIT| Doc PR        |symfony/symfony-docs#7453<!--- Bug fixes must be submitted against the lowest branch where they apply  (lowest branches are regularly merged to upper ones so they get the fixes too).- Features and deprecations must be submitted against the master branch.- Please fill in this template according to the PR you're about to submit.- Replace this comment by a description of what your PR is solving.-->Sample output :# Weak vendor mode## With both vendors and non-vendor errors```WARNINGS!Tests: 1068, Assertions: 2714, Warnings: 6, Skipped: 15.Remaining deprecation notices (1)some error: 1x    1x in SonataAdminBundleTest::testBuild from Sonata\AdminBundle\TestsRemaining vendor deprecation notices (4)Legacy deprecation notices (48)```Exit code is 1## After fixing non-vendor errors```WARNINGS!Tests: 1068, Assertions: 2714, Warnings: 6, Skipped: 15.Remaining vendor deprecation notices (4)Legacy deprecation notices (48)```Exit code is 0# TODO- [x] fix colorization issues (vendor deprecation notices are always in red)- [x] make the vendor detection more robust- [x] make the vendor dir configurable- [x] ~figure out how to run tests and~ add more of them    - [x] test on non-vendor file    - [x] test on vendor file- [x] do not change the output of other modesCommits-------61fd043 Introduce weak vendors mode
@greg0iregreg0ire deleted the weak_vendors branchFebruary 28, 2017 07:08
@greg0ire
Copy link
ContributorAuthor

Made a separate PR for the poor man's error handling :#21795

xabbuh added a commit to symfony/symfony-docs that referenced this pull requestMar 13, 2017
This PR was merged into the master branch.Discussion----------Document the weak_vendors valueSeesymfony/symfony#21539Commits-------abe88c6 Document the weak_vendors value
@nicolas-grekasnicolas-grekas modified the milestones:3.x,3.3Mar 24, 2017
@fabpotfabpot mentioned this pull requestMay 1, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@xabbuhxabbuhxabbuh approved these changes

+1 more reviewer

@rybakitrybakitrybakit requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

3.3

Development

Successfully merging this pull request may close these issues.

8 participants

@greg0ire@nicolas-grekas@ogizanagi@stof@fabpot@rybakit@xabbuh@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp