ricklamers / gpt-code-ui

An open source implementation of OpenAI's ChatGPT Code interpreter
MIT License
3.57k stars 447 forks source link

`grep` Command in `Makefile` Does Not Work With Default macOS `grep` #54

Closed dasmy closed 1 year ago

dasmy commented 1 year ago

Please check that this issue hasn't been reported before.

Expected Behavior

Running make compile_frontend should not emit an error.

Current behaviour

...it however does on macOS:

gpt-code-ui % make compile_frontend
grep: invalid option -- P
usage: grep [-abcdDEFGHhIiJLlMmnOopqRSsUVvwXxZz] [-A num] [-B num] [-C[num]]
    [-e pattern] [-f file] [--binary-files=value] [--color=when]
    [--context[=num]] [--directories=action] [--label] [--line-buffered]
    [--null] [pattern] [file ...]
cd frontend && \
    npm install && \
    npm run build && \
    find ../gpt_code_ui/webapp/static -mindepth 1 ! -name '.gitignore' -delete && \
    rsync -av dist/ ../gpt_code_ui/webapp/static
...

This also means, the code is unable to extract the version number from setup.py to inject it into the frontend build.

Steps to reproduce

see above, tested on macOS Ventura 13.4.1.

Possible solution

The problem stems from Perl-style regexes not being supported by the default macOS grep. One could install a more compatible grep via Homebrew, but fixing the grep expression seems simpler for users. This can be done with the following patch that just avoids perl-style expressions:

diff --git a/Makefile b/Makefile
index 01d4f74..ef0eeeb 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 .PHONY: all compile_frontend bundle_pypi upload_pypi increment_version release check_env_var

 # Extract version from setup.py file
-VERSION := $(shell grep -oP "(?<=version=')[^']*" setup.py)
+VERSION := $(shell grep -e "^\s*version='[ˆ']*" setup.py | cut -d "'" -f 2)

 all: check_env_var build upload_pypi

@@ -11,7 +11,7 @@ setenv:
     export VITE_APP_VERSION=${VERSION}

 increment_version:
-       @VERSION=$$(grep -oP "(?<=version=')[^']*" setup.py) && \
+       @VERSION=$$(grep -e "^\s*version='[ˆ']*" setup.py | cut -d "'" -f 2) && \
        MAJOR=$$(echo $$VERSION | cut -d. -f1) && \
        MINOR=$$(echo $$VERSION | cut -d. -f2) && \
        PATCH=$$(echo $$VERSION | cut -d. -f3) && \

Which Operating Systems are you using?

Programming Version

irrelevant

gpt-code-ui Version

https://github.com/ricklamers/gpt-code-ui/commit/6bdc463722dc662b184ce318fd2a10a13ae2098e

Acknowledgements

ricklamers commented 1 year ago

I’ve worked around this by installed GNU grep on macOS

https://formulae.brew.sh/formula/grep

Why macOS doesn’t ship that version in coreutils beats me…