Skip to content

Commit

Permalink
fix(api): Write .env with absolute path for conf on make install
Browse files Browse the repository at this point in the history
The old checked-in .env had a relative path into tests/ for the development
index.json file that drives settings. This makes it impossible to import
opentrons from outside the api directory. One way to fix this would be to add correct, sane, and not duplicated
logic to the way we load settings; another is to write the .env and the
index.json with absolute paths when you run make install.

Also, this fixes an issue where ‘make local-install’ worked on appveyor (because
appveyor uses mingw make) but doesn’t work on other dev setups that install make
using e.g. chocolatey into the windows shell or powershell, which do not do
wildcard expansion.

Closes #2495
  • Loading branch information
sfoster1 committed Oct 17, 2018
1 parent fc809e2 commit 96b775a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ venv/
env/
.env/

# Generated files for local API server config paths
api/.env
api/index.json

# MyPy caches
.mypy_cache

Expand Down Expand Up @@ -78,6 +82,7 @@ target/

# Testing
api/tests/opentrons/data/configs/
api/tests/opentrons/data/labware-def/
api/opentrons/config/*.json
sample_protocol.py
api/opentrons/server/endpoints/ignore.json
Expand Down
1 change: 0 additions & 1 deletion api/.env

This file was deleted.

3 changes: 2 additions & 1 deletion api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ test_opts ?=
.PHONY: install
install:
pipenv sync $(pipenv_opts)
$(python) write_localenv.py

.PHONY: all
all: lint test
Expand Down Expand Up @@ -70,7 +71,7 @@ wheel: clean

.PHONY: local-install
local-install: wheel
$(pip) install --ignore-installed --no-deps dist/opentrons-*.whl
$(pip) install --ignore-installed --no-deps dist/$(shell ls dist/)

.PHONY: local-shell
local-shell: local-install
Expand Down
11 changes: 0 additions & 11 deletions api/tests/opentrons/data/index.json

This file was deleted.

29 changes: 29 additions & 0 deletions api/write_localenv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import json
import os

here = os.getcwd()

with open('./.env', 'w') as dotenv:
dotenv.write('OVERRIDE_SETTINGS_DIR={}'.format(here))

shared_data = os.path.join(here, os.pardir, 'shared-data')
test_data = os.path.join(here, 'tests', 'opentrons', 'data')
local_index = {
"labware": {
"baseDefinitionDir": os.path.join(shared_data, 'definitions'),
"userDefinitionDir": os.path.join(test_data, 'labware-def',
'definitions'),
"offsetDir": os.path.join(test_data, 'labware-def', 'offsets')
},
"pipetteConfigFile": os.path.join(shared_data, 'robot-data',
'pipette-config.json'),
"featureFlagFile": os.path.join(shared_data, 'settings.json'),
"deckCalibrationFile": os.path.join(test_data,
'configs',
'deckCalibration.json'),
"robotSettingsFile": os.path.join(test_data, 'configs',
'robotSettings.json')
}

with open('./index.json', 'w') as index:
index.write(json.dumps(local_index))

0 comments on commit 96b775a

Please sign in to comment.