losDaniel / spot-connect

pip install spot-connect. Module that makes it easy to use AWS virtual machines at discount pricing
MIT License
19 stars 6 forks source link

Error: IndexError for sutils.load_profiles in unix based OS like mac, linux #20

Open gouthamravella opened 2 years ago

gouthamravella commented 2 years ago

I am getting the below error while running spot_connect.sutils.load_profiles() in the mac os.

python3 ec2_spot.py
lib:  profiles.txt profiles /
pull:  /Users/xyz/Desktop/MyComputer/Development/env_aws/lib/python3.8/site-packages/spot_connect
Traceback (most recent call last):
  File "ec2_spot.py", line 18, in <module>
    print(sutils.load_profiles())
  File "/Users/xyz/Desktop/MyComputer/Development/env_aws/lib/python3.8/site-packages/spot_connect/sutils.py", line 60, in load_profiles
    profile = [f for f in list(absoluteFilePaths(pull_root()+'/data/')) if f.split('\\')[-1]=='profiles.txt'][0]    
IndexError: list index out of range

Found issue during the

f.split('\\')[-1]=='profiles.txt'

Possible solution to this is using pathlib package.

import pathlib
path=pathlib.Path('/Users/xyz/Desktop/MyComputer/Developmentenv_aws/lib/python3.8/site-packages/spot_connect/data/profiles.txt')
print(path.name)

Output:
profiles.txt
tlamadon commented 2 years ago

I replaced the '\\' with os.path.sep. It happens in a few places. This is arguably a quick and dirty fix, pathlib might be better.