diff --git a/pkg/cmd/mackupcmd_darwin.go b/pkg/cmd/mackupcmd_darwin.go index 221e6d54e33..b4103d2fb26 100644 --- a/pkg/cmd/mackupcmd_darwin.go +++ b/pkg/cmd/mackupcmd_darwin.go @@ -16,11 +16,10 @@ import ( ) var ( - mackupCommentRx = regexp.MustCompile(`\A#.*\z`) - mackupKeyValueRx = regexp.MustCompile(`\A(\w+)\s*=\s*(.*)\z`) - mackupSectionRx = regexp.MustCompile(`\A\[(.*)\]\z`) - mackupVersionRx = regexp.MustCompile(`\AMackup\s+(\d+\.\d+\.\d+)\s*\z`) - pythonMajorMinorVersionRx = regexp.MustCompile(`\APython\s+(\d+\.\d+)\.\d+\s*\z`) + mackupCommentRx = regexp.MustCompile(`\A#.*\z`) + mackupKeyValueRx = regexp.MustCompile(`\A(\w+)\s*=\s*(.*)\z`) + mackupSectionRx = regexp.MustCompile(`\A\[(.*)\]\z`) + mackupVersionRx = regexp.MustCompile(`\AMackup\s+(\d+\.\d+\.\d+)\s*\z`) ) type mackupApplicationApplicationConfig struct { @@ -139,31 +138,28 @@ func (c *Config) mackupApplicationsDir() (chezmoi.AbsPath, error) { } mackupVersion := string(mackupVersionMatch[1]) - pythonVersionCmd := exec.Command("python3", "--version") - pythonVersionData, err := pythonVersionCmd.Output() + libDirAbsPath := brewPrefix.JoinString("Cellar", "mackup", mackupVersion, "libexec", "lib") + dirEntries, err := c.baseSystem.ReadDir(libDirAbsPath) if err != nil { return chezmoi.EmptyAbsPath, err } - pythonMajorMinorVersionMatch := pythonMajorMinorVersionRx.FindSubmatch(pythonVersionData) - if pythonMajorMinorVersionMatch == nil { + var pythonDirRelPath chezmoi.RelPath + for _, dirEntry := range dirEntries { + if dirEntry.IsDir() && strings.HasPrefix(dirEntry.Name(), "python") { + pythonDirRelPath = chezmoi.NewRelPath(dirEntry.Name()) + break + } + } + if pythonDirRelPath.Empty() { return chezmoi.EmptyAbsPath, fmt.Errorf( - "%q: cannot determine Python version", - pythonVersionData, + "%s: could not find python directory", + libDirAbsPath, ) } - pythonMajorMinorVersion := string(pythonMajorMinorVersionMatch[1]) - - return brewPrefix.JoinString( - "Cellar", - "mackup", - mackupVersion, - "libexec", - "lib", - "python"+pythonMajorMinorVersion, - "site-packages", - "mackup", - "applications", - ), nil + + return libDirAbsPath.Join(pythonDirRelPath). + JoinString("site-packages", "mackup", "applications"), + nil } func parseMackupApplication(data []byte) (mackupApplicationConfig, error) { diff --git a/pkg/cmd/testdata/scripts/mackup_darwin.txt b/pkg/cmd/testdata/scripts/mackup_darwin.txt index c9579db1959..54fb6f927b2 100644 --- a/pkg/cmd/testdata/scripts/mackup_darwin.txt +++ b/pkg/cmd/testdata/scripts/mackup_darwin.txt @@ -2,13 +2,12 @@ chmod 755 bin/brew chmod 755 bin/mackup -chmod 755 bin/python3 # test that chezmoi mackup add adds normal dotfiles exec chezmoi mackup add curl cmp $CHEZMOISOURCEDIR/dot_curlrc golden/dot_curlrc -# test that chezmoi +# test that chezmoi mackup add adds XDG configuration files exec chezmoi mackup add vscode cmp $CHEZMOISOURCEDIR/dot_config/Code/User/settings.json golden/settings.json @@ -34,17 +33,6 @@ case "$*" in echo "Usage:" ;; esac --- bin/python3 -- -#!/bin/sh - -case "$*" in -"--version") - echo "Python 3.9.0" - ;; -*) - echo "Usage:" - ;; -esac -- golden/dot_curlrc -- # contents of .curlrc -- golden/settings.json --