aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2019-02-08 14:48:24 -0800
committergenotrance <dev@genotrance.com>2019-02-08 16:48:24 -0600
commit5e212ce60634e2ab670819541b7a25fdd422de0e (patch)
tree9d0126280d052be81a063191c48b32e59bc81549
parentbed87aa2d897368f9c0afcb25ee20bbfd20032b4 (diff)
downloadnimterop-5e212ce60634e2ab670819541b7a25fdd422de0e.tar.gz
nimterop-5e212ce60634e2ab670819541b7a25fdd422de0e.zip
make relativePath more robust (#115)
-rw-r--r--nimterop/all.nim2
-rw-r--r--nimterop/compat.nim24
-rw-r--r--nimterop/git.nim12
3 files changed, 26 insertions, 12 deletions
diff --git a/nimterop/all.nim b/nimterop/all.nim
index dd42c03..78249a1 100644
--- a/nimterop/all.nim
+++ b/nimterop/all.nim
@@ -4,4 +4,4 @@ Module that should import everything so that `nim doc --project nimtero/all` run
# TODO: make sure it does import everything.
-import "."/[cimport, git, types, plugin]
+import "."/[cimport, git, types, plugin, compat]
diff --git a/nimterop/compat.nim b/nimterop/compat.nim
new file mode 100644
index 0000000..7f89358
--- /dev/null
+++ b/nimterop/compat.nim
@@ -0,0 +1,24 @@
+#[
+module for backward compatibility
+put everything that requires `when (NimMajor, NimMinor, NimPatch)` here
+]#
+
+import os
+
+when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9):
+ export relativePath
+else:
+ import std/[ospaths,strutils]
+
+ proc relativePath*(file, base: string): string =
+ ## naive version of `os.relativePath` ; remove after nim >= 0.19.9
+ runnableExamples:
+ import ospaths, unittest
+ check:
+ "/foo/bar/baz/log.txt".unixToNativePath.relativePath("/foo/bar".unixToNativePath) == "baz/log.txt".unixToNativePath
+ "foo/bar/baz/log.txt".unixToNativePath.relativePath("foo/bar".unixToNativePath) == "baz/log.txt".unixToNativePath
+ var base = base.normalizedPath
+ var file = file.normalizedPath
+ if not base.endsWith DirSep: base.add DirSep
+ doAssert file.startsWith base
+ result = file[base.len .. ^1]
diff --git a/nimterop/git.nim b/nimterop/git.nim
index 1d28179..c51c079 100644
--- a/nimterop/git.nim
+++ b/nimterop/git.nim
@@ -1,6 +1,6 @@
import macros, os, osproc, regex, strformat, strutils
-import "."/paths
+import "."/[paths, compat]
proc execAction*(cmd: string, nostderr=false): string =
var
@@ -49,16 +49,6 @@ proc cpFile*(source, dest: string, move=false) =
proc mvFile*(source, dest: string) =
cpFile(source, dest, move=true)
-when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
- proc relativePath*(file, base: string): string =
- ## naive version of `os.relativePath` ; remove after nim >= 0.19.9
- runnableExamples:
- doAssert "/foo/bar/baz/log.txt".relativePath("/foo/bar") == "baz/log.txt"
- var base = base
- if not base.endsWith "/": base.add "/"
- doAssert file.startsWith base
- result = file[base.len .. ^1]
-
proc extractZip*(zipfile, outdir: string) =
var cmd = "unzip -o $#"
if defined(Windows):