github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/assets/contents/activestate.yaml.python.tpl (about)

     1  scripts:
     2    - name: activationMessage
     3      language: {{.Language}}
     4      value: |
     5        import textwrap
     6        print(textwrap.dedent("""
     7          Quick Start
     8          -----------
     9          * To add a package to your runtime, type "state install <package name>"
    10          * Learn more about how to use the State Tool, type "state learn"
    11        """))
    12    - name: pip
    13      language: {{.Language}}
    14      value: |
    15          import os
    16          import subprocess
    17          import sys
    18  
    19          env = os.environ.copy()
    20          env["ACTIVESTATE_SHIM"] = "pip"
    21  
    22          project_path = os.path.join(r"${project.path()}", "activestate.yaml")
    23  
    24          def configure_message():
    25              print("To configure this shim edit the following file:\n" + project_path + "\n")
    26  
    27          def mapcmds(mapping):
    28              for fromCmd, toCmd in mapping.items():
    29                  if len(sys.argv) == 1:
    30                      print("pip requires an argument. Try:\n pip [install, uninstall, list, show, search, help]")
    31                      sys.exit()
    32                  if sys.argv[1] != fromCmd:
    33                      continue
    34  
    35                  print(("Shimming command to: 'state %s'") % toCmd)
    36                  configure_message()
    37  
    38                  code = subprocess.call(["state", toCmd] + sys.argv[2:], env=env)
    39                  sys.exit(code)
    40  
    41          mapcmds({
    42              "help": "help",
    43              "install": "install",
    44              "uninstall": "uninstall",
    45              "list": "packages",
    46              "show": "info",
    47              "search": "search",
    48          })
    49  
    50          print("Could not shim your command as it is not supported by the State Tool.\n" + 
    51                "Please check 'state --help' to find the best analog for the command you're trying to run.\n")
    52          configure_message()
    53  
    54  events:
    55    # This is the ACTIVATE event, it will run whenever a new virtual environment is created (eg. by running `state activate`)
    56    # On Linux and macOS this will be ran as part of your shell's rc file, so you can use it to set up aliases, functions, environment variables, etc.
    57    - name: ACTIVATE
    58      value: {{.LangExe}} $scripts.activationMessage.path()