TypeError raised for project.yml with vars containing int inside string
- Dominant language
- Python
- Stars
- 33.9k
- Forks
- 4.7k
- Avg merge
- 3m
- Merged PRs (30d)
- 1
Description
Hi spaCy developers,
This is my first open-source contribution, so please let me know if there are things I could have done better.
## How to reproduce the behavior
Given project.yml:
```yaml
vars:
my_var: "1"
commands:
- name: "example"
script:
- "echo ${vars.my_var}"
```
When running:
```bash
python -m spacy project run example
```
Then I expect:
```bash
Running command: echo 1
1
```
However I get:
```bash
.venv/lib/python3.9/site-packages/spacy/cli/project/run.py", line 69, in
commands = {cmd["name"]: cmd for cmd in config.get("commands", [])}
TypeError: string indices must be integers
```
---
This seems to be related to the ```my_var: "1"```, notice that ```my_var: 1``` does work as expected.
I dug a little into your code and it seems the issue is coming from a conversion to string that only gets partially reverted in _utip.py:substitute_project_variables on line 194:
```python
cfg = Config().from_str(cfg.to_str(), overrides=overrides)
```
before this line cfg contains a `commands` attribute that is a list as expected. However, after this line, the `commands` attribute becomes a string (the string does contain the list) which seems like the issue. At that point, it became a bit too advanced for me 😅
---
There is a workaround (using integers directly), but it did take me a couple of hours to figure out this was the issue 😅 , so a fix or a better exception might save others quite a bit of time.
## Your Environment
- **spaCy version:** 3.1.2
- **Platform:** macOS-10.15.6-x86_64-i386-64bit
- **Python version:** 3.9.6
## Final remark
Great library, great documentation, loved the "free interactive course" hopefully you find some time to update it to 3.x some time.
Contributor guide
Assessment
This issue has not been assessed yet.