ricklamers / gpt-code-ui

An open source implementation of OpenAI's ChatGPT Code interpreter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dasmy opened this issue · comments

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

  • I searched previous Bug Reports didn't find any similar reports.

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?

  • Android
  • iPhone/iPad
  • Linux
  • macOS
  • Windows

Programming Version

irrelevant

gpt-code-ui Version

6bdc463

Acknowledgements

  • My issue title is concise, descriptive, and in title casing.
  • I have searched the existing issues to make sure this bug has not been reported yet.
  • I am using the latest version of gpt-code-ui.
  • I have provided enough information for the maintainers to reproduce and diagnose the issue.

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…