Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workspace vs proj options #108

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 57 additions & 39 deletions src/atlas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import std / [parseopt, strutils, os, osproc, tables, sets, json, jsonutils]
import versions, context, osutils, packagesjson, sat, gitops, nimenv, lockfiles,
depgraphs, confighandler, configutils, cloner, nimblechecksums, reporters,

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-nim-devel (master)

imported and not used: 'cloner' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-nim-devel (master)

imported and not used: 'nimblechecksums' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-i386-nim-devel (master)

imported and not used: 'cloner' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-i386-nim-devel (master)

imported and not used: 'nimblechecksums' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-i386-nim-devel (master)

imported and not used: 'cloner' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-i386-nim-devel (master)

imported and not used: 'nimblechecksums' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

imported and not used: 'cloner' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

imported and not used: 'nimblechecksums' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

imported and not used: 'cloner' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

imported and not used: 'nimblechecksums' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-nim-devel (master)

imported and not used: 'cloner' [UnusedImport]

Check warning on line 14 in src/atlas.nim

View workflow job for this annotation

GitHub Actions / macos-amd64-nim-devel (master)

imported and not used: 'nimblechecksums' [UnusedImport]
nimbleparser, pkgurls

from std/terminal import isatty
Expand Down Expand Up @@ -69,12 +69,17 @@
env <nimversion> setup a Nim virtual environment
--keep keep the c_code subdirectory

Command type options:
-p interperate command as a project command
-w interperate command as a workspace command

Options:
--keepCommits do not perform any `git checkouts`
--full perform full checkouts rather than the default shallow
--cfgHere also create/maintain a nim.cfg in the current
working directory
--workspace=DIR use DIR as workspace
--workspace=DIR, -d=DIR
use DIR as workspace
--project=DIR use DIR as the current project
--noexec do not perform any action that may run arbitrary code
--autoenv detect the minimal Nim $version and setup a
Expand All @@ -86,12 +91,12 @@
--showGraph show the dependency graph
--keepWorkspace do not update/overwrite `atlas.workspace`
--list list all available and installed versions
--version show the version
--version, -v show the version
--ignoreUrls don't error on mismatching urls
--verbosity=normal|trace|debug
set verbosity level to normal, trace, debug
--global use global workspace in ~/.atlas
--help show this help
--global, -g use global workspace in ~/.atlas
--help, -h show this help
"""

proc writeHelp() =
Expand Down Expand Up @@ -227,21 +232,14 @@
trace c, file, "updating directory"
gitops.updateDir(c, file, filter)


proc detectWorkspace(currentDir: string): string =
## find workspace by checking `currentDir` and its parents.
result = currentDir
while result.len > 0:
if fileExists(result / AtlasWorkspace):
return result
result = result.parentDir()
when false:
# That is a bad idea and I know no other tool (git etc.) that
# does such shenanigans.
# alternatively check for "sub-directory" workspace
for kind, file in walkDir(currentDir):
if kind == pcDir and fileExists(file / AtlasWorkspace):
return file
## TODO: implement possible better default workspace option

proc autoWorkspace(currentDir: string): string =
result = currentDir
Expand Down Expand Up @@ -318,6 +316,7 @@
proc main(c: var AtlasContext) =
var action = ""
var args: seq[string] = @[]

template singleArg() =
if args.len != 1:
fatal action & " command takes a single package name"
Expand All @@ -333,18 +332,51 @@
fatal action & " command takes no arguments"

template projectCmd() =
if explicitWorkspaceCmd:
fatal action & " command cannot be executed as a workspace command"
if c.projectDir == c.workspace or c.projectDir == c.depsDir:
fatal action & " command must be executed in a project, not in the workspace"

template setWorkspaceDir(val: string) =
if val == ".":
c.workspace = getCurrentDir()
createWorkspaceIn c
elif val.len > 0:
c.workspace = val
if not explicitProjectOverride:
c.currentDir = val
createDir(val)
createWorkspaceIn c
else:
writeHelp()

template setProjectDir(val: string) =
explicitProjectOverride = true
if isAbsolute(val):
c.currentDir = val
else:
c.currentDir = getCurrentDir() / val

proc findCurrentNimble(): string =
for x in walkPattern("*.nimble"):
return x

var autoinit = false
var explicitProjectOverride = false
var explicitDepsDirOverride = false
var
autoinit = false
explicitProjectOverride = false
explicitDepsDirOverride = false
explicitProjCmd = false
explicitWorkspaceCmd = false

# process cli environment variables
if existsEnv("NO_COLOR") or not isatty(stdout) or (getEnv("TERM") == "dumb"):
c.noColors = true
if existsEnv("ATLAS_WORKSPACE"):
setWorkspaceDir(getEnv("ATLAS_WORKSPACE"))
if existsEnv("ATLAS_PROJECT"):
setWorkspaceDir(getEnv("ATLAS_PROJECT"))

# process cli option flags
for kind, key, val in getopt():
case kind
of cmdArgument:
Expand All @@ -356,25 +388,13 @@
case normalize(key)
of "help", "h": writeHelp()
of "version", "v": writeVersion()
of "p": explicitProjCmd = true
of "w": explicitWorkspaceCmd = true
of "keepcommits": c.flags.incl KeepCommits
of "workspace":
if val == ".":
c.workspace = getCurrentDir()
createWorkspaceIn c
elif val.len > 0:
c.workspace = val
if not explicitProjectOverride:
c.currentDir = val
createDir(val)
createWorkspaceIn c
else:
writeHelp()
of "workspace", "d":
setWorkspaceDir(val)
of "project":
explicitProjectOverride = true
if isAbsolute(val):
c.currentDir = val
else:
c.currentDir = getCurrentDir() / val
setProjectDir(val)
of "deps":
if val.len > 0:
c.depsDir = val
Expand Down Expand Up @@ -435,6 +455,10 @@
if action != "tag":
createDir(c.depsDir)

if explicitProjCmd and explicitWorkspaceCmd:
fatal "Cannot specify both -w and -p flags together since they conflict with each other."

# process cli command
case action
of "":
fatal "No action."
Expand Down Expand Up @@ -474,7 +498,7 @@

of "pin":
optSingleArg(LockFileName)
if c.projectDir == c.workspace or c.projectDir == c.depsDir:
if explicitWorkspaceCmd or c.projectDir == c.workspace or c.projectDir == c.depsDir:
pinWorkspace c, args[0]
else:
let exportNimble = args[0] == NimbleLockFileName
Expand Down Expand Up @@ -553,12 +577,6 @@
setupNimEnv c, c.workspace, args[0], Keep in c.flags
of "outdated":
listOutdated(c)
#of "checksum":
# singleArg()
# let pkg = resolvePackage(c, args[0])
# let cfg = findCfgDir(c, pkg)
# let sha = nimbleChecksum(c, pkg, cfg)
# info c, pkg, "SHA1Digest: " & sha
of "new":
singleArg()
newProject(c, args[0])
Expand Down
3 changes: 2 additions & 1 deletion src/confighandler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## Configuration handling.

import std / [strutils, os, streams, json]
import std / [strutils, os, streams, json, options]
import versions, context, reporters, compiledpatterns, parse_requires

proc parseOverridesFile(c: var AtlasContext; filename: string) =
Expand Down Expand Up @@ -49,6 +49,7 @@ type
overrides: string
plugins: string
resolver: string
requires: Option[seq[string]]
graph: JsonNode

proc writeDefaultConfigFile*(c: var AtlasContext) =
Expand Down
Loading