myano / jenni

jenni was a python IRC bot. Project is closed. Try Sopel instead, https://sopel.chat/

Home Page:https://sopel.chat/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bot.py "home" path is relative to where the script is executed.

WalkerGriggs opened this issue · comments

I noticed that when executing the ./jenni script from outside the jenni directory (say, root), modules were not loading and the python broke on an empty sequence (empty list of modules).

~ $ ./jenni/jenni 
Warning: Couldn't find any modules
Traceback (most recent call last):
  File "./jenni/jenni", line 267, in <module>
    main()
  File "./jenni/jenni", line 264, in main
    initialize_configs(opts.config)
  File "./jenni/jenni", line 247, in initialize_configs
    run(config_module) # @@ thread this
  File "/home/jenni/jenni/__init__.py", line 63, in run
    t.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/jenni/jenni/__init__.py", line 49, in run_jenni
    try: connect(config)
  File "/home/jenni/jenni/__init__.py", line 39, in connect
    p = bot.Jenni(config)
  File "/home/jenni/jenni/bot.py", line 48, in __init__
    self.setup()
  File "/home/jenni/jenni/bot.py", line 93, in setup
    self.bind_commands()
  File "/home/jenni/jenni/bot.py", line 185, in bind_commands
    max_pattern_width = max(len(f[2]) for f in bound_funcs)
ValueError: max() arg is an empty sequence

Currently, bot.py only recognizes modules if ./jenni is run from within the top level directory. This is, I believe, due to the way the home directory is being calculated. Currently:

# getcwd() is relative to your location in the file tree.
home = os.getcwd()

I believe it would be better calculated using the files realpath. This way, the initial script can run from any directory.

# realpath is the absolute path of the file.
home = os.path.dirname(os.path.realpath(__file__))