Fix Altair import in tools scripts #2872
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current importing behaviour in the
tools
scripts has some inconsistencies which this PR tries to address. These issues were partially discovered in #2814.Issue 1: Altair is imported for
generate_api_docs
before the vegalite files are updatedThe statement
import generate_api_docs
was previously at the top ofgenerate_schema_wrapper.py
. Ingenerate_api_docs.py
, one of the first statements is the import of Altair -> Altair got imported beforegenerate_schema_wrapper
can update the vegalite files. This was presumably not a big issue so far as this script is usually run multiple times anyway and so the api docs were updated eventually.This PR solves this by moving the
import generate_api_docs
statement at the end of themain
function ingenerate_schema_wrapper.py
.Issue 2: If Altair is installed as a site-package, it might be imported instead of the currently checked out version
If you execute
python tools/generate_api_docs.py
then Python correctly uses Altair from the root folder due to the modification ofsys.path
in the beginning of the script. However, ifgenerate_api_docs
is improted fromgenerate_schema_wrapper
, Python seems to usesys.path
as it's defined ingenerate_schema_wrapper
for the whole import procedure, i.e.sys.path
needs to be modified to be able to import Altair beforegenerate_api_docs
is imported.You can check this by installing Altair in
site-packages
with pip and then adding the following lines ingenerate_api_docs.py
right after the Altair import:On the current
master
branch, when I executepython tools/generate_schema_wrapper.py
I get the path to mysite-packages
Altair:When I execute
python tools/generate_api_docs.py
I get the path to the correct local version in the current folder (/workspaces/altair
):This PR solves this by adding the root folder to sys.path already in
generate_schema_wrapper.py
so it doesn't matter anymore if you callpython tools/generate_schema_wrapper.py
orpython tools/generate_api_docs.py
. Both now import the correct local version of Altair.