rezemika / humanized_opening_hours

A parser for the opening_hours fields from OpenStreetMap
GNU Affero General Public License v3.0
26 stars 20 forks source link

Avoid sys.path[0] for finding setup.py directory #8

Closed nbolten closed 6 years ago

nbolten commented 6 years ago

I wanted to use a fork (temporarily), and found that the default setup.py fails on my system (Python 3.5, Ubuntu 16.04) as it uses sys.path[0] in an attempt to find the development directory. I assume this is because the main dev environment involves prepending to $PYTHONPATH. However, this makes the package non-portable - system.path[0] is set to '' by default, so setup.py raises a FileNotFoundError when attempting to change to that directory.

To indicate the directory of setup.py, use __file__:

os.path.chdir(os.path.dirname(os.path.realpath(__file__)))

rezemika commented 6 years ago

Done by 350973d (I used a BASE_DIR variable). Can you confirm it works?

Thank you! :)

nbolten commented 6 years ago

The solution in commit 350973d

Hey! Your solution is better because it avoids running os.chdir at all.

It does have a redundant os.path.dirname though, just a heads up.

Other remaining impacts

main.py still runs os.chdir, and it's messing up my scripts because it changes the meaning of __file__ somehow, or something like that. So far as I can tell, its purpose is to make it so that field_parser.py can find the .ebnf file. I think this would fix it:

  1. Delete this line in main.py:

os.chdir(os.path.dirname(os.path.realpath(__file__)))

  1. Edit this line in field_parser.py:

From:

    base_dir = os.path.realpath(os.path.join(
        os.getcwd(), os.path.dirname(__file__)
    ))

To:

    base_dir = is.path.dirname(os.path.realpath(__file__))
rezemika commented 6 years ago

Thank you! Done with a1bdc6e, can you confirm (again) please?

rezemika commented 6 years ago

Ping @nbolten. ;)