Skip to content

Commit 25cc201

Browse files
b-coopermcous
andauthored
fix(app): no longer require app restart after python override path config is updated (#11049)
Instead of requiring the app to restart in order to incorporate a new pathToPythonOverride config value, handle the config change on the fly Closes #10612 Co-authored-by: Mike Cousins <[email protected]>
1 parent fdea70b commit 25cc201

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

app-shell/src/protocol-analysis/__tests__/protocolAnalysis.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { when, resetAllWhenMocks } from 'jest-when'
22

3-
import { Config, getConfig } from '../../config'
3+
import { Config, getConfig, handleConfigChange } from '../../config'
44
import { getValidLabwareFilePaths } from '../../labware'
55
import { selectPythonPath, getPythonPath } from '../getPythonPath'
66
import { executeAnalyzeCli } from '../executeAnalyzeCli'
@@ -29,6 +29,9 @@ const mockWriteFailedAnalysis = writeFailedAnalysis as jest.MockedFunction<
2929
const mockGetValidLabwareFilePaths = getValidLabwareFilePaths as jest.MockedFunction<
3030
typeof getValidLabwareFilePaths
3131
>
32+
const mockHandleConfigChange = handleConfigChange as jest.MockedFunction<
33+
typeof handleConfigChange
34+
>
3235

3336
describe('analyzeProtocolSource', () => {
3437
afterEach(() => {
@@ -45,6 +48,15 @@ describe('analyzeProtocolSource', () => {
4548
initializePython()
4649

4750
expect(mockSelectPythonPath).toHaveBeenCalledWith('/some/override/python')
51+
expect(mockHandleConfigChange).toHaveBeenCalledWith(
52+
'python.pathToPythonOverride',
53+
expect.any(Function)
54+
)
55+
56+
// the 'python.pathToPythonOverride' change handler
57+
const changeHandler = mockHandleConfigChange.mock.calls[0][1]
58+
changeHandler('/new/override/python', '/old/path/does/not/matter')
59+
expect(mockSelectPythonPath).toHaveBeenCalledWith('/new/override/python')
4860
})
4961

5062
it('should get the Python path and execute the analyze CLI with custom labware', () => {

app-shell/src/protocol-analysis/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createLogger } from '../log'
2-
import { getConfig } from '../config'
2+
import { getConfig, handleConfigChange } from '../config'
33

44
import { getValidLabwareFilePaths } from '../labware'
55
import { selectPythonPath, getPythonPath } from './getPythonPath'
@@ -11,6 +11,10 @@ const log = createLogger('protocol-analysis')
1111
export function initializePython(): void {
1212
const pathToPythonOverride = getConfig().python.pathToPythonOverride
1313
selectPythonPath(pathToPythonOverride)
14+
15+
handleConfigChange('python.pathToPythonOverride', newValue => {
16+
selectPythonPath(newValue)
17+
})
1418
}
1519

1620
export function analyzeProtocolSource(

0 commit comments

Comments
 (0)