arcee-ai / arcee-python

The Arcee client for executing domain-adpated language model routines https://pypi.org/project/arcee-py/
https://www.arcee.ai
25 stars 5 forks source link

'arcee configure' doesn't create parent directories #78

Open juliensimon opened 3 months ago

juliensimon commented 3 months ago

arcee configure doesn't create the parent directories for the config.json file if they're missing.

Example:

arcee configure
Current API URL: https://app.arcee.ai/api
API key: not in config (file or env)

Enter your Arcee API key 🔒
Hit enter to leave it as is.
See https://docs.arcee.ai/getting-arcee-api-key/getting-arcee-api-key for more details.
You can also pass this at runtime with the ARCEE_API_KEY environment variable.
: <MY_API_KEY>
Setting API key
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /Users/julien/Development/env-arcee-cloud/lib/python3.12/site-packages/arcee/cli/app.py:103 in   │
│ configure                                                                                        │
│                                                                                                  │
│   100 │   │   )                                                                                  │
│   101 │   │   if resp:                                                                           │
│   102 │   │   │   console.print("Setting API key")                                               │
│ ❱ 103 │   │   │   write_configuration_value("ARCEE_API_KEY", resp)                               │
│   104                                                                                            │
│   105                                                                                            │
│   106 # Enter the CLI                                                                            │
│                                                                                                  │
│ /Users/julien/Development/env-arcee-cloud/lib/python3.12/site-packages/arcee/config.py:42 in     │
│ write_configuration_value                                                                        │
│                                                                                                  │
import json
│   39 │   │   │   except json.JSONDecodeError:                                                    │
│   40 │   │   │   │   pass                                                                        │
│   41 │   else:                                                                                   │
│ ❱ 42 │   │   conf_path.touch()                                                                   │
│   43 │                                                                                           │
│   44 │   config[key] = value                                                                     │
│   45                                                                                             │
│                                                                                                  │
│ /opt/homebrew/Cellar/python@3.12/3.12.4/Frameworks/Python.framework/Versions/3.12/lib/python3.12 │
│ /pathlib.py:1303 in touch                                                                        │
│                                                                                                  │
│   1300 │   │   flags = os.O_CREAT | os.O_WRONLY                                                  │
│   1301 │   │   if not exist_ok:                                                                  │
│   1302 │   │   │   flags |= os.O_EXCL                                                            │
│ ❱ 1303 │   │   fd = os.open(self, flags, mode)                                                   │
│   1304 │   │   os.close(fd)                                                                      │
│   1305 │                                                                                         │
│   1306 │   def mkdir(self, mode=0o777, parents=False, exist_ok=False):                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
FileNotFoundError: [Errno 2] No such file or directory: '/Users/julien/Library/Application Support/arcee/config.json'

Indeed, the arcee directory doesn't exist on my machine.

I have a one-line fix. PR on the way :)