-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extract: Detect location of whosonfirst data from pelias.json #235
base: master
Are you sure you want to change the base?
Conversation
cmd/wof_extract_sqlite.js
Outdated
@@ -9,7 +9,9 @@ const combinedStream = require('combined-stream'); | |||
|
|||
const SQLITE_REGEX = /whosonfirst-data-[a-z0-9-]+\.db$/; | |||
|
|||
const WOF_DIR = process.env.WOF_DIR || '/data/whosonfirst-data/sqlite'; | |||
const WOF_DIR = process.env.WOF_DIR || // TODO: deprecate WOF_DIR env var after some time | |||
config.whosonfirst.datapath || // Preferred method of finding WOF data is to autodetect from pelias.json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With ES6 this can be written as config?.whosonfirst?.datapath
which will avoid fatal errors if the parent path doesn't exist.
Likely not an issue in practise as we have a default value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, these paths are always kinda confusing, standardising them is a nice idea, the one I linked from the defaults is different again 🤷♂️
dadea4f
to
20bda96
Compare
I just updated this with one minor change (adjust a comment where I originally proposed we eventually remove the Also, reading through some windows-related comments like this one it seems like this change might help some Windows users. |
bc72c16
to
9ad247a
Compare
Okay, I've updated this yet again to fix two issues with the path detection:
The |
Yeah I agree that we're very unlikely to go back to using the old One thing to be careful of is that the For now I think it's probably fine to leave the 'sqlite' directory, it allows us some flexibility in the future to write other formats in the same parent directory tree (such as As an aside, it's probably more robust to use |
I'm trying to understand this better... It looks like I don't see how/where So to run it locally, it will fail because In that case, I think your method is good, it can probably be simplified to: const path = require('path');
// Use WOF_DIR env variable when available, otherwise use the location specified in pelias.json
const WOF_DIR = process.env.WOF_DIR || path.join(config.datapath, 'sqlite'); |
In fact the I don't think the original intent was to make this a user-configurable ENV var, although it ended up that way. It was simply a way to tell the script to look in I seriously doubt anyone is setting Looking at the configs that The exception being the default config where everything points to I guess that's all a round-about way of saying we can probably delete |
Looking over the whole org for mentions of ![]() https://github.com/search?q=org%3Apelias+WOF_DIR&type=issues |
The same applies to |
I mean, all default path locations are sometimes wrong. This one is probably more often wrong though, so I agree. Also, we have a default whosonfirst datapath set in Your code snippet is the right way to go, I'll update the PR. Some followup thoughts/questions that are more minor though:
|
This change allows the Placeholder extract script to work in most cases _without_ specifying the `WOF_DIR` environment variable. Previously, unless you were using the particular arrangement of files and directories from pelias/docker, the default location the extract script looks for data (`/data/whosonfirst-data/sqlite`) was probably not correct. I noticed this inconvenience when running Pelias locally _without_ docker for the first time in quite a long time. My guess/recollection is an older version of the extract script (pre-sqlite) was pure bash, and so checking `pelias.json` was less convenient than in the current Node.js script. The `WOF_DIR` environment variable is left as an override, but my hope is with this change almost no one would have to use it.
9ad247a
to
57cbdda
Compare
I'm fine leaving it in if you think it's useful, of course someone could always do something like this, although agreed it's not very intuative: jq -n '.imports.whosonfirst.datapath="/foo"'
{
"imports": {
"whosonfirst": {
"datapath": "/foo"
}
}
}
Probably not, like you mentioned, it doesn't really make sense to configure something during |
This change allows the Placeholder extract script to work in most cases without specifying the
WOF_DIR
environment variable.Previously, unless you were using the particular arrangement of files and directories from pelias/docker, the default location the extract script looks for data (
/data/whosonfirst-data/sqlite
) was probably not correct.I noticed this inconvenience when running Pelias locally without docker for the first time in quite a long time.
My guess/recollection is an older version of the extract script (pre-sqlite) was pure bash, and so checking
pelias.json
was less convenient than in the current Node.js script.The
WOF_DIR
environment variable is left as an override, but my hope is with this change almost no one would have to use it.