Skip to content

sed command in helper scripts breaks on some platforms #301

@ckadner

Description

@ckadner

The sed command is used in many of our helper scripts. However sed preinstalled on macOS is not POSIX compliant (works differently than on most Linux distributions). But testing for the OS on which the script is being run on is not a good proxy to find out which version of sed is going to be available since macOS users can easily reinstall it (Homebrew, symlink, ...). On top of that, some Bash emulators used on Windows do not present as an operating system.

We need to replace this test for specific operating systems (or specific Bash emulator):

https://github.com/machine-learning-exchange/mlx/blob/c24c2ed4dca89ec6d5018c88e0f7308a62a6114a/tools/bash/add_license_headers.sh#L10-L22

With this more generic test:

if ! sed -i '1s/^/test/' $(mktemp) 2> /dev/null; then
    # macOS (BSD) version of sed
    alias gsed="sed -i ''" 
else
    # POSIX compliant version of sed 
    alias gsed="sed -i"
fi

sed is used in various script in the mlx and katalog repo where the platform check needs to be replaced:

  • in the mlx repo:
    • mlx/api/codegen.sh
    • mlx/tools/bash/add_license_headers.sh
  • in the katalog repo:
    • katalog/tools/bash/upgrade_notebook_requirements.sh
    • katalog/tools/bash/add_license_headers.sh

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions