Problem/Motivation

The module requires a server extension that is not widely available on all installations and it is required for it to work in Drupal 7

Proposed resolution

Check if the YAML extension is installed during the module installation process, if it is not, switch to using the SPYC library, to be able to read and process the yaml files.

Remaining tasks

Run tests agains different configurations to make sure both configuration methods work, either with the extension or the library.

User interface changes

N/A

API changes

Modify the hook_requirements for the module.

-----------------------------------------------
Original text
-----------------------------------------------
Hey, i would like to propose to drop the server side yaml dependencies. First of all it's unclear how to install them at the moment (not an impossible task) and second of all D8 and the current branch of drush depends on the symfony yaml component. Why not switch to that one?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

muschpusch’s picture

Status: Active » Needs review
FileSize
5.33 KB

Since the good way of adding the symfony component would be using composer which would add some extra unneeded complexity here a patch using the spyc library:

https://github.com/mustangostang/spyc

If php_yaml is available it would be still used. The patch also fixes some coding standard errors.

muschpusch’s picture

Sorry! The emit part was missing from the patch....

sreynen’s picture

Status: Needs review » Needs work

I like the idea of removing dependencies, and spyc looks like a good way to do that. But the implementation here has some issues we need to fix:

1) This makes a call to libraries_load() with nothing to ensure the libraries API module is enabled. I'm not sure the best way to handle this. If we add a dependency on libraries, that will force people to install libraries even if they already have the PHP YAML extension and wouldn't actually be using libraries. But if we do a module_exists() check, then the module could be enabled without any working YAML functionality. Maybe a hook_requirements() on runtime phase would be a good way to handle that potential confusion.
2) When libraries API is enabled and the spyc module is missing, it still tries to load it, which throws an error. Again, I think hook_requirements() would solve this.
3) This one's just a personal preference, but I don't like pseudo-private function names like _cinc_yaml_yaml_parse() and _cinc_yaml_yaml_emit(). The underscores there say other modules shouldn't use those because they might change, and I would rather spend the time to plan for broader use, since thinking about potential reuse very often improves code even for the immediate use case. In this case, thinking about potential reuse doesn't actually change anything that I see. It's already very reusable code, so I don't see any reason to suggest otherwise with the underscore prefix.
4) On a related, but smaller issue, those function names could also be more descriptive. I don't think we need to mirror the yaml_parse() and yaml_emit() names, since anyone familiar with those functions would probably be calling them directly rather than calling these CINC wrappers. So I suggest something more like cinc_yaml_from_yaml() and cinc_yaml_to_yaml().
5) This one is super nit-picky, but I'd like to standardize on imperative verb tense in function comments, focusing on what the function does, not how it does it, so something like "parses a yaml file using php_yaml or the spyc library." That format is only required in coding standards for hook functions per Drupal documentation, but I find it improves readability to use it everywhere.

muschpusch’s picture

Assigned: Unassigned » muschpusch

1.) Agreed we should check if php_yaml or libraries is installed. If php_yaml is there the libraries_load would never get executed.
2-5.) Make sense too :)

muschpusch’s picture

Hey sreynen, please review the path attached. I'm not very familiar to hook_requirements. I didn't do the checks on runtime but install phase since cinc_yaml shouldn't install without any parser or not? The rest of your comments should be implemented as well.

muschpusch’s picture

Assigned: muschpusch » Unassigned
Status: Needs work » Needs review
muschpusch’s picture

Lowering error level to warning

icampana’s picture

Issue summary: View changes

So far I checked the patch and seems to be working propperly, including the libraries setting and finding if spyc is present. The only problem was some line endings differences.

I think we should ran more tests with some YAML configuration modules I did a test with one generan

chrowe’s picture

I tried applying the latest patch and got

git apply 2406025-drop-yaml-server-dependency-5.patch
error: patch failed: modules/cinc_yaml/cinc_yaml.install:12
error: modules/cinc_yaml/cinc_yaml.install: patch does not apply
error: patch failed: modules/cinc_yaml/cinc_yaml.module:118
error: modules/cinc_yaml/cinc_yaml.module: patch does not apply

Looks like there were a couple commits sine this patch and one had a lot of changes.

rballou’s picture

Adding a new patch to address #9 and:

* CINC::yaml was calling cinc_yaml_to_yaml without checking that the module is enabled, so I added that.
* I removed some of the stylistic changes that don't apply to this issue (but should maybe be their own issue ;))
* Reduced the if/else statements to just if statements in cinc_yaml_to_yaml, etc. In either case, there can be a case here, probably addressed by hook_requirements where the library does not load and the function won't exist. I think it's OK though.
* Added a couple $variable = array() calls where the anti-pattern $variable[thing] = ... was used (I blame Drupal for perpetuating this behavior!)

Please double-check this work as it was a manual process!

  • sreynen committed dc7dddd on 7.x-1.x authored by rballou
    Issue #2406025 by muschpusch, rballou, sreynen: drop yaml server...
sreynen’s picture

Status: Needs review » Fixed

#10 is committed with 3 minor changes:

1. I changed the library load syntax to follow the example from https://www.drupal.org/node/1342238 to avoid the possibility of calling missing functions in spyc.
2. I changed the first requirement, that either the PHP YAML extension or the libraries module be enabled, to a REQUIREMENTS_ERROR message, to avoid the possibility of calling missing functions in the libraries module.
3. I changed the second requirement, that spyc be installed if PHP YAML is not loaded, to a runtime check, to avoid the possibility of installing the module and having it do nothing with no idea why, since I wasn't seeing any warning message on install via drush. Now it shows a warning on the status report.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.