-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
added exclude function for composer autoload generation #1607
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
Conversation
res/composer-schema.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say from classmap generation
|
Please follow the PSR-2 coding standards which are used by Composer. and your new feature should be tested. Btw, you are breaking tests here as by default, you are excluding everything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding .* before and after the excluding pattern is useless as your regex is not anchored anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the packages/libraries with exclude in their composer.json I generate a blacklist pattern like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, at least the right is useless
|
you still need to add tests for the blacklist feature |
|
@JohnDoe007 was so friendly to fix the CS and unit test issues. Thanks @JohnDoe007! (just fyi, he`s a team mate of me and we worked together on this feature). Why we need this feature? Here you can find a minimal example how to reproduce this: https://gist.github.com/andygrunwald/4994295 I got a small chat with @Seldaek about this "feature" over twitter: https://twitter.com/andygrunwald/status/304163183541772288 If you got further notices / changes about this feature, let us know. |
|
I think this is counterproductive. There should be no tests in autoloader. The question is - how did they get there in the first place? I think excluding them, by not including them, is better approach. But hey, if it won't broke any existing library... it's ok I guess. |
|
@hosiplan As you can see in the discussion from twitter with me and @Seldaek there is a regular expression to exclude all files which ends with Test.php (see https://github.com/composer/composer/blob/master/src/Composer/Autoload/AutoloadGenerator.php#L126) This regular expression is not very "aggressiv" and in a Tests/-Folder there ar emuch more files as *Test.php |
|
@hosiplan the test is not in the autoloader. In it in the autoloader generator (which is generating the autoloader configuration when you run |
|
@hosiplan is correct that you should not configure any autoload for the test files in your package definition, however in some cases like symfony bundles and others, tests are within the psr-0 mapped folder. In this case the ability to exclude them from generated classmaps would be a good thing. |
|
Hello! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to PSR-2, the curly brace should be on the same line than the if
|
@Parad0X probably this could be interesting for you |
|
hmmm... any idea why there is no new travis build? |
|
Isn't it better to have both a whitelist and blacklist approach? Although the blacklist would at least solve issues we have with eZ Publish 5. |
|
@patrickallaert if you say the blacklist solves your problem then it can't be a bad solution. I think using blacklist and whitelist together could be really confusing? |
|
Don't get me wrong @JohnDoe007, I +1 this PR. Just that I see a use case for whitelisting: if you just want to cherry-pick some files or directories, it is just easier to select those rather than excluding everything else. |
|
@patrickallaert if you just want a few files/directories, you can do it with |
|
@JohnDoe007 @Seldaek The need is indeed just to include some files/directories, so this is already implement. I was not aware of that since I'm not the guy touching that part of eZ Publish. So +1. |
|
I prefer integration of Finder component from symfony (#1406): "classmap": ["src/*Bundle/", "src(/[^/]+(?<!test|Tests|foo/bar))*"]and/or add support for complex configuration (http://symfony.com/doc/current/components/finder.html): "classmap": ["src", {"in": ["vendor"], "depth": "2", "not-path": "..."}, {"in": ["lib"], "name": "*.cls"}] |
|
Please rename it to a more descriptive name, eg. "autoload": {
"psr-0": {"Acme": "src"},
"exclude": ["Tests"]
}$autoloader->findFile('Acme\Tests\FooTest'); // returns /.../src/Acme/Tests/FooTest.php |
|
@hason I agree about the exclude name, it is not the clearest. Maybe IMO it's easier to do this blacklist of explicit pathes than to integrate finder stuff because not everyone is familiar with it and not everyone can write lookahead regexes without shooting themselves in the foot :) |
|
@rk3rn3r reviewed again and I wrote down one issue, apart from that it should also be rebased again if possible. But I think then it's good to merge. Sorry for the delay, many things to review. |
|
Come on @rk3rn3r , go go go. |
|
What happened with this feature? |
|
@klapifoch nothing yet. We (@trivago / @rk3rn3r / me) are now responsible. Just give us a few more days to solve this. Ok? |
…go/composer into add_exclude * 'add_exclude' of https://github.com/trivago/composer: # By Jordi Boggiano (239) and others # Via Jordi Boggiano (184) and others * 'master' of https://github.com/trivago/composer: (638 commits) Simplified syntax github deprecation changes fix bug in GitDriver::supports for remote repo strict check, testcase(s) Fix regex matching and add more tests for addSubNode, refs composer#3721, fixes composer#3716 solve edge case for `composer remove vendor/pkg` chmod 644 src/Composer/Command/RemoveCommand.php Avoid failing on composer show of lazy providers Show more info when a download fails Add notion of autoloader skipping autoload-dev rules Satis grammar fix. remove unused statements removed needless output param + limit git ls-remote to heads + escape repo url add check for remote Repository in GitDriver::supports suppress the prefix Improve notice about /usr/local/bin Reuse current file permissions Add the P character to the regex pattern Added deprecated warning for the dev option ... Conflicts: src/Composer/Autoload/AutoloadGenerator.php src/Composer/Autoload/ClassMapGenerator.php
…go/composer into add_exclude * Resolve conflicts and update unit test
|
Hey @stof, @Seldaek, |
|
The state was tested against the unit tests and the test case https://gist.github.com/andygrunwald/4994295 by @andygrunwald with the following composer-json: Result:
|
|
Not merged yet? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see the removal of this block still has not been accounted for..
The problem is such, if you use psr-0, right now the dir is usually src/ and the namespace prefix Foo\Bar. So it will build up a classmap for all of src/ but exclude files not matching the whitelist (i.e. anything not in src/Foo/Bar).
Removing the whitelist is ok but then I think the $dir should be modified to have the namespace prefix appended if $psrType === 'psr-0' && strpos($namespace, '_') === false is true, that way we only scan the relevant files.
|
@andygrunwald @rk3rn3r Another thing that's missing for an easy merge is including it in the Unrelated: @klapifoch can you be more of an obnoxious and ungrateful person please? |
|
@Seldaek If have updated the doc/04-schema.md and integrate a desciption. I checked the whitelist handling again and i'm not sure if the logic make also sense for the blacklist handling: With the "exclude-from-blacklist" you are free to define pattern to avoid classes in the classmap. If we extend the "user pattern" with the directories (and namespaces for psr-0), like the whitelist functionality, it's possbile to produce wrong or invalid patterns (if somebody use "^ - Start of string or line" for example). It's looks like some of the unit tests failed because of temporary connections problems to "pear.phpmd.org"!? |
|
@Seldaek It wasn't my intention to be annoying, it is just a feature i want to use in a project. |
…d_exclude # By Jordi Boggiano (30) and others # Via Jordi Boggiano (37) and Morgan Campbell (1) * 'master' of https://github.com/composer/composer: (83 commits) Update 01-basic-usage.md Revert 331425b as well, fixes composer#3612 Revert "Disable overwrites when no-ansi is present, fixes composer#3612" Update deps Use justinrainbow/json-schema 1.4 Improved wording Fix docs basic-auth => http-basic Add test for Generics class Single variable for traits and enums Use HHVM_VERSION instead of HPHP_VERSION Add support for using classmap to autoload Hack enums Re-use existing autoloader suffix if available, fixes composer#3701 Report Travis CI build success early Test on HHVM nightly releases. Allow to fail. Make parseJson safer Use get home from Config instead of factory Fix env override regression, fixes composer#3820 [create-project] Used no progress value for dependencies Add docBlock and fix CS Fix output of first line of progress when output is not decorated, refs composer#3818 ...
|
@Seldaek: We reintegrated the current master again to our fork. |
|
Any update here? |
…ake sure they are all package-relative and do not leak to other packages, refs #1607
|
I guess 2.5y is a pretty long time, sorry about that, but we got there :) Finally took the time to merge this and try it out, tweaked things a bit because it was matching stuff a bit too greedily for my taste. Now you have to specify exact paths from package root to things you want to exclude, I see that it's not always the easiest think it's better that way rather than accidentally matching too much. We can always add support for wildcards or such later on if really needed. Thanks @rk3rn3r |
|
So I added support for wildcards after all, see 6c16510 |
|
So when exluding test files from the autoload optimization, it means test classes might not be available anymore. So it is similar to using exclusion via gitattributes. But IMO using gitattributes is the better approach as this will actually also make the package considerably smaller. And developers still have a choice with --prefer-dist vs --prefer-source. |
|
No, that is only true if you rely on classmap autoloading. It you use psr0
or 4 plus optimized classmap dumping then what is not found in the classmap
is still found using psr rules. Unless you use the classmap authoritative
flag but that's something you really just should do in prod where tests
don't matter IMO.
|
example: