Skip to content

Instantly share code, notes, and snippets.

@Jawabiscuit
Last active April 12, 2022 13:26
Show Gist options
  • Select an option

  • Save Jawabiscuit/113fdefb4a972eee51507cfd4af16336 to your computer and use it in GitHub Desktop.

Select an option

Save Jawabiscuit/113fdefb4a972eee51507cfd4af16336 to your computer and use it in GitHub Desktop.

Revisions

  1. Jawabiscuit revised this gist Apr 12, 2022. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions rez_package_snippets.md
    Original file line number Diff line number Diff line change
    @@ -100,6 +100,27 @@ def commands():
    alias("pycharm", "pycharm64")
    ```

    __resolve package command__

    Values are accessible via the `resolve` package command directly or through expansion.
    The end result of `resolve.rez.root` here is the same as the expansion `"$REZ_REZ_ROOT"` or `"{resolve.rez.root}"`, but generally using the command is preferable on Windows. In this particular example, if expansion is used, the value of `rez_cmake_module_path` would have `"\"` instead of `"/"` in it.

    [Wiki: resolve package command](https://github.com/nerdvegas/rez/wiki/Package-Commands#resolve)

    ```python
    def commands():
    import os

    rez_cmake_module_path = os.path.join(
    resolve.rez.root,
    "rezplugins",
    "build_system",
    "cmake_files"
    ).replace("\\", "/")

    env.CMAKE_MODULE_PATH.prepend(rez_cmake_module_path)
    ```

    ## Custom Package Attributes

    __extra attribute__
  2. Jawabiscuit revised this gist Mar 26, 2022. 1 changed file with 54 additions and 1 deletion.
    55 changes: 54 additions & 1 deletion rez_package_snippets.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,12 @@

    ## Tools

    __late binding functions__

    This snippet executes during a special context during build-time.

    [Wiki: Late Binding Functions](https://github.com/nerdvegas/rez/wiki/Package-Definition-Guide#late-binding-functions)

    ```python
    @late()
    def tools():
    @@ -22,6 +28,12 @@ def tools():

    ## Variants

    __early binding__

    This snippet executes during a special context during build-time.

    [Wiki: Early Binding Functions](https://github.com/nerdvegas/rez/wiki/Package-Definition-Guide#early-binding-functions)

    ```python
    @early()
    def variants():
    @@ -33,6 +45,12 @@ def variants():

    ## Private Build Requires

    __early binding__

    This snippet executes during a special context during build-time.

    [Wiki: Early Binding Functions](https://github.com/nerdvegas/rez/wiki/Package-Definition-Guide#early-binding-functions)

    ```python
    @early()
    def private_build_requires():
    @@ -70,6 +88,8 @@ def build_command():

    __command alias__

    In this snippet an alias to be used in a rez env context is created.

    ```python
    def commands():
    import os
    @@ -80,12 +100,45 @@ def commands():
    alias("pycharm", "pycharm64")
    ```

    ## Extras
    ## Custom Package Attributes

    __extra attribute__

    In this snippet a custom package attribute named "extra" is defined and used during build-time.

    ```python
    extra = {
    "vendor_version": version,
    "winget_package_name": "ShareX.ShareX",
    "winget_override_params": "/verysilent /suppressmsgboxes /tasks=!createdesktopicon,createsendtoicon",
    }
    ```

    ## Powershell Rez Build

    __install files__

    Selectively copy content from binary build dir to install dir

    Source: ffmpeg build.ps1

    ```powershell
    if (!($env:REZ_BUILD_INSTALL -eq "1")) {
    Write-Host "Nothing more to do. Use 'rez-build -i' to install."
    Exit 0
    }
    Write-Host "Installing..." -ForegroundColor "Green"
    Push-Location ".\$env:REZ_BUILD_PROJECT_NAME-$env:REZ_BUILD_PROJECT_VERSION"
    Get-ChildItem -Directory . | Where-Object {
    $_.Name -like "bin" -or
    $_.Name -like "doc" -or
    $_.Name -like "presets"
    } | ForEach-Object {
    Copy-Item -Path $_ -Destination $env:REZ_BUILD_INSTALL_PATH -Recurse -Force
    }
    Pop-Location
    ```
  3. Jawabiscuit revised this gist Mar 22, 2022. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions rez_package_snippets.md
    Original file line number Diff line number Diff line change
    @@ -54,6 +54,10 @@ def build_command():
    import os
    import sys

    os.environ["REZ_BUILD_PROJECT_VENDOR_VERSION"] = this.extra["vendor_version"]
    os.environ["REZ_BUILD_PROJECT_PACKAGE_NAME"] = this.extra["winget_package_name"]
    os.environ["REZ_BUILD_PROJECT_OVERRIDE_PARAMS"] = this.extra["winget_override_params"]

    if os.name == "nt":
    command = 'pwsh -File "{0}"'
    prefix = "%REZ_BUILD_SOURCE_PATH%"
    @@ -76,3 +80,12 @@ def commands():
    alias("pycharm", "pycharm64")
    ```

    ## Extras

    ```python
    extra = {
    "vendor_version": version,
    "winget_package_name": "ShareX.ShareX",
    "winget_override_params": "/verysilent /suppressmsgboxes /tasks=!createdesktopicon,createsendtoicon",
    }
    ```
  4. Jawabiscuit revised this gist Mar 21, 2022. 1 changed file with 57 additions and 0 deletions.
    57 changes: 57 additions & 0 deletions rez_package_snippets.md
    Original file line number Diff line number Diff line change
    @@ -19,3 +19,60 @@ def tools():

    return executables
    ```

    ## Variants

    ```python
    @early()
    def variants():
    from rez.package_py_utils import expand_requires

    requires = ["platform-**", "arch-**", "os-**", "python-2.7"]
    return [expand_requires(*requires)]
    ```

    ## Private Build Requires

    ```python
    @early()
    def private_build_requires():
    import os

    requires = ["pip-19+"]
    if os.name == "nt":
    return ["msvc-14.16+<14.20"] + requires
    return ["cmake-3"] + requires
    ```

    ## Build Commands

    __pwsh build_commands__

    ```python
    @early()
    def build_command():
    import os
    import sys

    if os.name == "nt":
    command = 'pwsh -File "{0}"'
    prefix = "%REZ_BUILD_SOURCE_PATH%"
    script = "rezbuild.ps1"

    return command.format(os.path.join(prefix, script))
    ```

    ## Commands

    __command alias__

    ```python
    def commands():
    import os

    env.PATH.prepend(os.path.join(this.root, this.name, "bin"))

    if os.name == "nt":
    alias("pycharm", "pycharm64")
    ```

  5. Jawabiscuit created this gist Mar 20, 2022.
    21 changes: 21 additions & 0 deletions rez_package_snippets.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # Rez Package Snippets

    ## Tools

    ```python
    @late()
    def tools():
    import os

    executables = []

    sitepath = os.path.join(this.root, "Lib", "site-packages", this.name)
    if os.path.exists(sitepath):
    executables.extend(os.listdir(sitepath))

    binpath = os.path.join(this.root, "Scripts")
    if os.path.exists(binpath):
    executables.extend(os.listdir(binpath))

    return executables
    ```