{"id":722,"date":"2020-03-24T17:14:43","date_gmt":"2020-03-25T00:14:43","guid":{"rendered":"http:\/\/www.toadstorm.com\/blog\/?p=722"},"modified":"2024-08-16T11:46:02","modified_gmt":"2024-08-16T18:46:02","slug":"doing-away-with-houdini-env","status":"publish","type":"post","link":"https:\/\/www.toadstorm.com\/blog\/?p=722","title":{"rendered":"Doing away with Houdini.env"},"content":{"rendered":"\n<p>This is a sort of sequel to the <a href=\"https:\/\/www.toadstorm.com\/blog\/?p=678\">previous post<\/a> I made about handling the Houdini.env file, and about configuring environments in general. Houdini 17.5 introduced the concept of &#8220;packages&#8221;, which are little JSON files (JSON meaning JavaScript Object Notation, filling a similar role as XML or YAML) that define Houdini-specific changes to be made to the environment. They&#8217;re meant to fill the exact same role as the Houdini.env file. JSON syntax can take a little getting used to, but the advantage of using packages over the Houdini.env file is that these packages can be easily enabled or disabled individually, and they can support special syntax for loading packages only when certain conditions are met (such as a specific build of Houdini). <\/p>\n\n\n\n<p>SideFX has a reasonably long <a href=\"https:\/\/www.sidefx.com\/docs\/houdini\/ref\/plugins.html\">documentation page<\/a> on what packages are and how they work, but I still keep seeing a lot of badly-configured package files floating around out there that can prevent your environment from working correctly when multiple packages are combined. Part of this is due to the internal inconsistency of how different &#8220;keys&#8221; in the package file are handled; for some reason, SideFX decided that any additions to the HOUDINI_PATH variable can be done with a special key called &#8220;path&#8221; that automatically operates in &#8220;prepend&#8221; mode, meaning each package automatically <em>adds<\/em> the new value to the beginning of HOUDINI_PATH. However, other environment-related keys default to the &#8220;replace&#8221; mode, and confusingly one of the common environment variables you need to edit is named &#8220;PATH&#8221;, and this is not the same as the special &#8220;path&#8221; key. Little inconsistencies like this can really throw a wrench in what should otherwise be a pretty simple file format. I&#8217;m going to explain a bit about how this syntax is supposed to work, and then write a couple of sample packages you can follow that should be enough to configure just about any add-on or plugin you choose to add to Houdini.<\/p>\n\n\n\n<p><strong>Important update:<\/strong> SideFX has deprecated the &#8220;path&#8221; key in packages in favor of &#8220;hpath&#8221;. The syntax is otherwise exactly the same. Moving forward past Houdini 20.0, you will want to start using &#8220;hpath&#8221; anywhere you see &#8220;path&#8221; (except for the &#8220;PATH&#8221; keys you see in the &#8220;env&#8221;!)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Package Syntax<\/h2>\n\n\n\n<p>Houdini package files are written in JSON, which is a bit <em>finicky<\/em> to say the least. If you&#8217;re not used to dealing with JSON, it&#8217;s basically a bunch of key\/value pairs in a hierarchical structure. Each &#8220;object&#8221; in this structure is surrounded by curly braces (<code>{ }<\/code>). The file itself is one of these, so you&#8217;re going to have a pair of curly braces opening and closing the file as a whole. Any environment variables you want to store are another object, named <code>env<\/code>. This object internally is a <em>list<\/em> of environment variables you want to adjust, so it&#8217;s going to be surrounded by square braces (<code>[ ]<\/code>). So, before we&#8217;re adding any variables to our environment at all, here&#8217;s what a blank package would look like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n{\n    &quot;env&quot;: &#x5B;\n        {\n        \n        }\n    ]\n}\n<\/pre><\/div>\n\n\n<p>That&#8217;s looking pretty&#8230; useless. But now we can start filling in the blanks. You can see that I put another pair of curly braces in there, inside the square braces that define the list of environment variables we&#8217;re going to add. This is because each environment variable addition we make is another <em>object<\/em>, each with its own properties. Let&#8217;s start with the most obvious property here&#8230; what environment variable are we setting?<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; highlight: [4]; title: ; notranslate\" title=\"\">\n{\n    &quot;env&quot;: &#x5B;\n        {\n            &quot;PATH&quot;: &quot;C:\/ProgramData\/Redshift\/bin&quot;\n        }\n    ]\n}\n<\/pre><\/div>\n\n\n<p>The actual key\/value pairs are just strings, separated by a colon. This is setting the <code>PATH <\/code>environment variable to be the given path on disk. It&#8217;s the equivalent of writing this in Houdini.env:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nPATH=&quot;C:\/ProgramData\/Redshift\/bin&quot;\n<\/pre><\/div>\n\n\n<p>Those of you who have already slogged through a Houdini.env might notice that something&#8217;s missing, though&#8230; you usually want to <em>append<\/em> or <em>prepend<\/em> to the PATH variable, not replace it entirely. In Houdini.env, you typically do this by saying <code>PATH=$PATH;\"C:\/ProgramData\/Redshift\/bin\"<\/code>, and then writing this line over and over again for any other plugins you might be adding to your system path. With packages, you do this via the <code>method<\/code> property of this JSON object:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; highlight: [4,5]; title: ; notranslate\" title=\"\">\n{\n    &quot;env&quot;: &#x5B;\n        {\n            &quot;PATH&quot;: &quot;C:\/ProgramData\/Redshift\/bin&quot;,\n            &quot;method&quot;: &quot;append&quot;\n        }\n    ]\n}\n<\/pre><\/div>\n\n\n<p>Note that there&#8217;s a comma there after the PATH definition&#8230; JSON is very particular about this! You need a comma in between multiple objects in the same hierarchy. Setting the <code>method <\/code>to <code>append<\/code> here ensures that our new key is just going to be added to what&#8217;s already there. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Houdini gotchas<\/h2>\n\n\n\n<p>Of course, because it&#8217;s Houdini, it can&#8217;t be <em>that<\/em> easy. There&#8217;s a specially-named key in Houdini package files that you&#8217;ll frequenty see called <code>path<\/code>. This has nothing to do with the <code>PATH<\/code> environment variable set above&#8230; it&#8217;s actually a shortcut for <code>HOUDINI_PATH<\/code>. Worse still, it <em>automatically assumes that you&#8217;re using the <code>prepend<\/code> method<\/em>, whereas the <code>env<\/code> key assumes you are using the <code>replace<\/code> method. This trips up a lot of people when they&#8217;re trying to do anything more complex in a package than adding something to <code>HOUDINI_PATH<\/code>. You might even see this in some widely-distributed packages out there on the internet. If things start to fail when you&#8217;re combining multiple packages together, it&#8217;s worth taking a look in there and seeing if they&#8217;re following the right syntax!<\/p>\n\n\n\n<p>Following our previous example for configuring a Redshift package, we still need to add the Redshift plugin path to <code>HOUDINI_PATH<\/code> to complete the install. Using the special <code>path<\/code> key, our package will look like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; highlight: [7,8]; title: ; notranslate\" title=\"\">\n{\n    &quot;env&quot;: &#x5B;\n        {\n            &quot;PATH&quot;: &quot;C:\/ProgramData\/Redshift\/bin&quot;,\n            &quot;method&quot;: &quot;append&quot;\n        }\n    ],\n    &quot;path&quot;: &quot;C:\/ProgramData\/Redshift\/Plugins\/Houdini\/18.0.391&quot;\n}\n<\/pre><\/div>\n\n\n<p>Notice that extra comma after the closing square bracket! Now that we&#8217;re defining multiple keys inside the outermost object, we need a comma in between them.<\/p>\n\n\n\n<p>The last main gotcha here is that you can&#8217;t have these things defined in Houdini.env and in a package file at the same time&#8230; it&#8217;s one or the other. My recommendation is to hose out your Houdini.env file entirely and replace all the keys you&#8217;re setting with packages. They&#8217;re so easy to individually swap in and out that you&#8217;ll have a much easier time adding, removing, or updating plugins and tools as necessary, even on a show-by-show basis.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Finishing up<\/h2>\n\n\n\n<p>The Houdini packages documentation goes into the specifics of where you can put these package files, but the usual directory is wherever your Houdini.env file typically goes on your system, plus \/packages. So on Windows, you&#8217;d place all of these JSON files into C:\/Users\/butt\/Documents\/houdini18.0\/packages. Each of these files will be processed in turn, and the result is the total environment for Houdini. Once you get used to the JSON syntax, it&#8217;s way easier than doing the old dance of semicolons and ampersands that we all had to do in Houdini.env.<\/p>\n\n\n\n<p>The last thing I should mention is that packages are only a replacement for Houdini&#8217;s environment&#8230; they can never replace your <em>system<\/em> environment. I still recommend learning about how to manipulate environment keys on your given OS so that you can configure your projects in a more flexible manner&#8230; having auto-configured variables like <code>$SHOW<\/code> and <code>$SHOT<\/code> can save you a ton of time if done right, and the environment is a great place to tuck away &#8220;global&#8221; variables that you might need in multiple software packages all communicating with each other. <\/p>\n\n\n\n<p>As a final example, here&#8217;s another package file that you could use to configure Arnold for Houdini. It&#8217;s almost exactly the same as Redshift&#8230; you can use this as a template for other tools you want to install, too! (Except MOPs. Use the included JSON for that one.) Just replace <code>\/path\/to\/htoa<\/code> with the install location on your machine:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\n{\n    &quot;env&quot;: &#x5B;\n        {\n            &quot;PATH&quot;: &quot;C:\/path\/to\/htoa\/htoa-5.0.2_raba8949_houdini-18.0.348\/scripts\/bin&quot;,\n            &quot;method&quot;: &quot;append&quot;\n        }\n    ],\n    &quot;path&quot;: &quot;C:\/path\/to\/htoa\/htoa-5.0.2_raba8949_houdini-18.0.348&quot;\n}\n<\/pre><\/div>\n\n\n<p>Happy packaging!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a sort of sequel to the previous post I made about handling the Houdini.env file, and about configuring environments in general. Houdini 17.5 introduced the concept of &#8220;packages&#8221;, which are little JSON files (JSON meaning JavaScript Object Notation, filling a similar role as XML or YAML) that define [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30],"tags":[75,31,77],"_links":{"self":[{"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/722"}],"collection":[{"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=722"}],"version-history":[{"count":5,"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/722\/revisions"}],"predecessor-version":[{"id":1117,"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/722\/revisions\/1117"}],"wp:attachment":[{"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.toadstorm.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}