aiddata / gcdf-geospatial-data

Repository for AidData's Geospatial Global Chinese Development Finance Dataset (GeoGCDF)
https://aiddata.org/china
Other
27 stars 7 forks source link

Batch job check fails on local run #19

Closed jacobwhall closed 2 years ago

jacobwhall commented 2 years ago

This code throws an error when I run tuff_osm.py locally:

https://github.com/aiddata/china-osm-geodata/blob/c1ff3fafd4997bf9711e4821c392886414479ddb/tuff_osm.py#L30-L33

Traceback (most recent call last):                         
  File "tuff_osm.py", line 33, in <module>
    os.chdir(os.path.dirname(__file__))
FileNotFoundError: [Errno 2] No such file or directory: ''

sys only has the ps1 attribute in interactive modes.

Here is an example in the Python interpreter:

Python 3.9.12 (main, Jun  1 2022, 11:38:51) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> hasattr(sys, "ps1")
True

But saving the following code into a file and executing it with python file.py prints False:

import sys
print(hasattr(sys, "ps1"))

I suggest we find a better method of checking whether the program is running as a batch job, or change directories to the project's root regardless of what context the script is running in.

sgoodm commented 2 years ago

Replaced the current check / directory change with a more flexible approach that makes sure the config exists, is the right config, and then changes to the base_directory path from the config.

See 952287b4f5d9f1279ad74e233bd47a621ae91053