Skip to content

Commit

Permalink
Split standardize path into two functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Oct 19, 2022
1 parent 3da9c27 commit 0001101
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion extension/src/cli/git/executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('GitExecutor', () => {
} as unknown as EventEmitter<CliStarted>
})

const cwd = standardizePath(__dirname) as string
const cwd = standardizePath(__dirname)

describe('pushBranch', () => {
it('should call createProcess with the correct parameters to push a branch', async () => {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/cli/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export class GitCli extends Cli {
public async getGitRepositoryRoot(cwd: string) {
const options = getOptions(cwd, Command.REV_PARSE, Flag.SHOW_TOPLEVEL)

return standardizePath(await this.executeProcess(options)) as string
return standardizePath(await this.executeProcess(options))
}
}
2 changes: 1 addition & 1 deletion extension/src/experiments/columns/collect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ export const collectParamsFiles = (
): Set<string> => {
const files = Object.keys(data.workspace.baseline.data?.params || {})
.filter(Boolean)
.map(file => standardizePath(join(dvcRoot, file))) as string[]
.map(file => standardizePath(join(dvcRoot, file)))
return new Set(files)
}
8 changes: 5 additions & 3 deletions extension/src/experiments/context.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Event, EventEmitter, window } from 'vscode'
import { Disposable, Disposer } from '@hediet/std/disposable'
import { setContextValue } from '../vscode/context'
import { standardizePath } from '../fileSystem/path'
import { standardizePossiblePath } from '../fileSystem/path'

const setContextOnDidChangeParamsFiles = (
setActiveEditorContext: (paramsFileActive: boolean) => void,
onDidChangeColumns: Event<void>,
getParamsFiles: () => Set<string>
): Disposable =>
onDidChangeColumns(() => {
const path = standardizePath(window.activeTextEditor?.document.fileName)
const path = standardizePossiblePath(
window.activeTextEditor?.document.fileName
)
if (!path) {
return
}
Expand All @@ -26,7 +28,7 @@ const setContextOnDidChangeActiveEditor = (
getParamsFiles: () => Set<string>
): Disposable =>
window.onDidChangeActiveTextEditor(event => {
const path = standardizePath(event?.document.fileName)
const path = standardizePossiblePath(event?.document.fileName)
if (!path) {
setActiveEditorContext(false)
return
Expand Down
4 changes: 2 additions & 2 deletions extension/src/fileSystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const findDvcSubRootPaths = async (

return children
.filter(child => isDirectory(join(cwd, child, '.dvc')))
.map(child => standardizePath(join(cwd, child)) as string)
.map(child => standardizePath(join(cwd, child)))
}

export const findDvcRootPaths = async (cwd: string): Promise<string[]> => {
Expand All @@ -59,7 +59,7 @@ export const findAbsoluteDvcRootPath = async (
return []
}

const absoluteRoot = standardizePath(resolve(cwd, relativePath)) as string
const absoluteRoot = standardizePath(resolve(cwd, relativePath))

return [absoluteRoot]
}
Expand Down
6 changes: 4 additions & 2 deletions extension/src/fileSystem/path.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Uri } from 'vscode'

export const standardizePath = (path?: string): string | undefined => {
export const standardizePath = (path: string): string => Uri.file(path).fsPath

export const standardizePossiblePath = (path?: string): string | undefined => {
if (!path) {
return
}
return Uri.file(path).fsPath
return standardizePath(path)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ beforeEach(() => {

describe('DecorationProvider', () => {
const dvcRoot = __dirname
const model = standardizePath(join(dvcRoot, 'model.pt')) as string
const dataDir = standardizePath(join(dvcRoot, 'data')) as string
const features = standardizePath(join(dataDir, 'features')) as string
const logDir = standardizePath(join(dvcRoot, 'logs')) as string
const logAcc = standardizePath(join(logDir, 'acc.tsv')) as string
const logLoss = standardizePath(join(logDir, 'loss.tsv')) as string
const dataXml = standardizePath(join(dataDir, 'data.xml')) as string
const dataCsv = standardizePath(join(dataDir, 'data.csv')) as string
const prepared = standardizePath(join(dataDir, 'prepared')) as string
const model = standardizePath(join(dvcRoot, 'model.pt'))
const dataDir = standardizePath(join(dvcRoot, 'data'))
const features = standardizePath(join(dataDir, 'features'))
const logDir = standardizePath(join(dvcRoot, 'logs'))
const logAcc = standardizePath(join(logDir, 'acc.tsv'))
const logLoss = standardizePath(join(logDir, 'loss.tsv'))
const dataXml = standardizePath(join(dataDir, 'data.xml'))
const dataCsv = standardizePath(join(dataDir, 'data.csv'))
const prepared = standardizePath(join(dataDir, 'prepared'))

const emptySet = new Set<string>()

Expand Down
6 changes: 2 additions & 4 deletions extension/src/test/suite/fileSystem/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ suite('File System Test Suite', () => {
const root = await reader.getGitRepositoryRoot(__dirname)
const submoduleDotGit = standardizePath(
resolve(root, gitPath.DOT_GIT, 'modules', 'demo')
) as string
)

const dotGitPath = getGitPath(dvcDemoPath, gitPath.DOT_GIT)
expect(dotGitPath).to.equal(submoduleDotGit)
Expand All @@ -39,9 +39,7 @@ suite('File System Test Suite', () => {
it('should get the expected paths for this project', async () => {
const reader = disposable.track(new GitReader())
const root = await reader.getGitRepositoryRoot(__dirname)
const rootDotGit = standardizePath(
resolve(root, gitPath.DOT_GIT)
) as string
const rootDotGit = standardizePath(resolve(root, gitPath.DOT_GIT))

const dotGitPath = getGitPath(root, gitPath.DOT_GIT)
expect(dotGitPath).to.equal(rootDotGit)
Expand Down

0 comments on commit 0001101

Please sign in to comment.