-
Notifications
You must be signed in to change notification settings - Fork 3
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
Manage language packs for all dependency types #224
Conversation
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.
This approach feels right to me 👍 I've encountered a few bugs for various configs not currently accounted for.
Separate testing issues comment to follow...
|
||
namespace Dxw\Whippet\Dependencies; | ||
|
||
class DependencyTypes |
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 like this a lot 👍
Testing issues: So it looks like the failure is happening because of the call to My ideal solution would probably be for But that would involve a reasonably substantial refactor. It might be possible to stub the call to |
OK, I notice that we only really use ❯ git grep whippet_init
src/Dependencies/Updater.php:26: $this->whippet_init();
src/Modules/Helpers/WhippetHelpers.php:25: public function whippet_init()
src/Modules/Plugin.php:60: $this->whippet_init();
src/Modules/Plugin.php:263: $this->whippet_init();
src/Modules/Release.php:18: $this->whippet_init();
tests/Helpers.php:126: // WhippetHelpers. I think this is because in whippet_init() we ignore
tests/Helpers.php:131: // repo, and whippet_init() recurses the directory to find a .json file. So, only Refactoring work as been raised as #227 |
It looks like https://github.com/dxw/whippet/blob/main/src/Modules/Helpers/WhippetHelpers.php#L42 https://github.com/dxw/whippet/blob/main/src/Modules/Helpers/WhippetHelpers.php#L50 https://github.com/dxw/whippet/blob/main/src/Modules/Release.php#L80 |
This resolves a deprecation warning.
We have a small number of extant tests with no assertions. These raise a "risky test" warning when running ./script/test. This commit adds some sensible assertions to the tests to avoid this warning.
Previously we hard-coded the list of dependency types wherever we needed to use them. In order to manage language packs within Whippet, we now need to add to the list of dependency types. So, rather than have them scattered over the code, we now have them in one place. Once we have dropped PHP 7.4 support, we should really use an enumeration here. Fixes #70
Note that at this point, it isn't clear how we will need to manage language packs, and it may be that we do not pin languages to versions or hashes in the lockfile. For this reason, the relevant test data is mostly blank, with the expectation that this will change (or more tests will be added) in later commits.
In order to manage language files, we will need a semver version for each plugin and theme in the whippet.json file. These versions are obtainable via the Describer class, but currently the relevant method just prints out version information. This commit splits that code into two parts, one to fetch and return the information, and one to print it, so that we can reuse the code elsewhere. Since both methods are already tested by the existing tests, this commit doesn't add any more.
Language packs in WordPress are available for WP Core, plugins and themes. In a manual install, they can be added with: wp language core install wp language plugin classic-editor ja wp language theme install twentytwenty ja and the wp cli command will work out the required versions of the language packs, based on already installed versions of the core, plugins and themes. The language packs themselves are downloaded a .zip files from wordpress.org. In this commit, we replicate this behaviour, by: * Looking up the versions of language packs that are required for each langauge or theme, based on the APIs documented here: https://codex.wordpress.org/WordPress.org_API#Translations * We add the locations of the relevant .zip files to the 'src' key/value pair in the whippet.lock file with the revision of the dependency (core/plugin/theme) that the language pack relates to. Note that language packs are different to plugins and themes in a number of ways. Relevant to the Updater, is the fact that language packs relate to other dependencies. So, the 'name' value for each one is either: * Just the language code (e.g. 'en_US') if the related dependency is core. * '<language>/<type>/<slug>' otherwise, e.g. 'ja/plugins/classic-editor' or 'ja/themes/twentytwenty'.
2949ad0
to
d87eca5
Compare
This commit adds the ability to install language packs into an existing WordPress application. Languages live in 'wp-content/languages/', they are not unzipped into separate directories. Similarly, lanaguage packs for plugins go in 'wp-content/languages/plugins' and for themes, 'wp-content/languages/themes'. Again, these do not have one directory per theme or plugin, they all go in the same directory. This behaviour can be verified by running a local WordPress app and using wp cli to manually install language packs, e.g.: wp language core install wp language plugin classic-editor ja wp language theme install twentytwenty ja
Language packs are slightly different to other dependencies because a single language pack may have separate sources for WP core, any plugins for which the language is available and any themes. We expect that if a language code is in the .json file, it should have a related language pack for WP core as a minimum, but there may be any number more entries in the lockfile for that language code.
This commit ensures that `whippet deps describe` shows information about language packs. Note that the version numbers shown are the versions of the related dependencies, so for example output like: "languages": { "ja": "6.3.1", "ja/plugins/classic-editor": "1.6.3", } is showing the versions of WordPress Core, and the Classic Editor plugin. Versions of the translations themselves are not when installing language packs, but translations for WP Core, plugins and themes need to be consistent with the the versions of those dependencies that Whippet is installing. Therefore, we don't need to store version informations for language packs themselves.
d87eca5
to
74f9ec0
Compare
Initial testing of Whippet behaviour without language packs all seems as expected:
However, when I run
With the following
The results for the core language packs in
The WordPress snapshot I think what's happening is that |
1ef747e
to
af11347
Compare
In repos we have a config file that determines the version of WordPress Core that needs to be deployed to a live site. This can be a full semver version (e.g. 1.2.3) or a "version" that is actually a moveable tag related to a major release (e.g. v6). Previously, we did not check for this edge case, which means that in some cases, we did not return a full semver version and this caused a bug in updating language packs whereby old language packs would be written into repos and lockfiles. Now, we remove any leading 'v' characters and return a fully qualified semver version (e.g. 1.2.3). We make an assumption that the list of available core versions (e.g. https://api.wordpress.org/translations/core/1.0/?version=6) is ordered by most recent release first.
af11347
to
9d91b4d
Compare
oops
PR #261 merged in the first few repo chores and small fixes/refactorings from this PR. I'm going to close this now because there's a lot of comment churn here which suggests that I haven't tested these changes well enough. Also, this needs a significant refactoring, because I've made an assumption about where the plugin/theme packs can be written to, which doesn't necessarily hold. If this work comes back, it would be easier to merge a series of smaller PRs than to try and fix this larger one. |
['themes', 'plugins']
everywhere is not DRY #70Summary
This PR adds the ability to manage WordPress language packs with Whippet. Once this PR is merged, it should be possible to run any
whippet deps ...
command withlanguages
as a dependency (rather thanplugins
orthemes
). Commands that do not specify a dependency type (e.g.whippet deps validate
) should now take language packs into account.About WordPress language packs
WordPress language packs are slightly different to other dependency types (core, plugins, themes) and those differences complicate this PR.
Language packs are versioned separately, but they are available for all other dependency types. So, installing the
pt_BR
language pack might install translations for WordPress Core, and for a number of plugins and themes that are also managed by Whippet.Whereas with other dependencies we mirror the repositories for each dependency, in this PR we have opted not to do that, due to the complexity of retrieving the "correct" translation packs for each dependency. Instead, we rely on the
wordpress.org
APIs to describe the location of each translation.For example, if we have a repo pinned to version 6.3.3 of WordPress Core, which uses the
classic-editor
plugin and thetwentytwenty
theme, and we want to installpt_BR
translations, we would query the following JSON APIs to find the URI for each language pack:https://api.wordpress.org/translations/core/1.0/?version=6.3.3
classic-editor
v1.6.3:https://api.wordpress.org/translations/plugins/1.0/?slug=classic-editor&version=1.6.3
twentytwenty
v1.0.0:https://api.wordpress.org/translations/themes/1.0/?slug=twentytwenty&version=1.0.0
This is equivalent to the behaviour of wp-cli which provides commands for manually installing and removing translations, e.g.
The
whippet.json
andwhippet.lock
filesTo add language packs to the Whippet dependencies of a repository, the country codes for the languages should be added to the JSON file, e.g.:
On running
whippet deps update
the lockfile will be populated with information from thewordpress.org
APIs. Language codes are considered valid if and only if a translation is available for the current pinned version of WordPress Core.Note that here, the
revision
for each entry is the revision of the relevant dependency. So,6.3.1
in the example below refers to the version of WordPress Core, not the version of the translation files, which are versioned separately.The code in Whippet expects that each lockfile object will contain a
name
, asrc
and arevision
. For language packs, we may want to install a number of different translation packs for each country code. Rather than complicate the code that manages lockfiles by adding more attributes to the lockfile objects, I have opted to encode dependency types in the names of each translation. So, thept_BR
translations for thetwentytwenty
theme would be encoded aspt_BR/themes/twentytwenty
.For example:
About this PR
Whippet is not as compliant with the SOLID principles as it might be, which means that some parts of the code are not well encapsulated and there are several hidden dependencies.
Because of this, I have made some compromises to ship this code in a reasonable timeframe, without completely refactoring the codebase.
In particular:
Switching on type is a code smell, and ideally dependency types would be able to update and install "themselves". However, the current code structure in Whippet is that we have classes for commands, not classes for dependencies, and so this would require a large refactoring of code that does no have good test coverage.
wordpress.org
APIs with version information about plugins and themes. This dependency would exist whether we refactor the code or not, and is another reason for switching on dependency type in this branch.DependencyTypes
is a class with constants, and not an enumeration.Preparing for manual testing
If you have
whippet
installed system-wide, you might want to create an alias for testing this branch, i.e.:Most Whippet commands require a Whippetised repository with some default files and directories. You might want to create some structures in
/tmp
for testing.To run
whippet deps update
you need a minimum set of files and directories:whippet.json
file.gitignore
config/
wp-content/
wp-content/plugins/
It's a good idea to have at least one plugin with language packs, maybe
classic-editor
orakismet
.To run
whippet deploy
you need a slightly different directory structure:The
wp-config.php
file should look like this:Then you can create a new whippet app with
whippet generate app
, move to thewhippet-app
directory and runwhippet deps update
to install the dependencies.whippet deploy ../
can be run from withinwhippet-app
.More information can be found in the documentation.
Testing
./script/test
describe
,validate
,install
,update
. You might also want to checkdeploy
andrelease
with and without language packs.whippet deps update
to populate the lockfile and install all dependencieswhippet deps validate
to check that the new lockfile is validwhippet deps install
(should be idempotent toupdate
)wp-content/languages
. There may also be awp-content/languages/plugins
directory.wp-content/languages
directory, and install the same things via wp-cli to check the install, e.g.:wp-content/languages
directory and runwhippet deps update languages/ja
or similar to check that a single language pack can be manually updated. Expected behaviour is that the language pack will be installed for core and relevant themes and plugins.whippet.json
returns an error message onwhippet deps update
.