Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.admin
Commits
8a77e386
Commit
8a77e386
authored
7 years ago
by
Amir MOHAMMADI
Browse files
Options
Downloads
Patches
Plain Diff
Minor fixes to the conda-bootstrap script
parent
7b85ed0c
No related branches found
No related tags found
1 merge request
!81
Minor fixes to the conda-bootstrap script
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
conda/conda-bootstrap.py
+53
-38
53 additions, 38 deletions
conda/conda-bootstrap.py
with
53 additions
and
38 deletions
conda/conda-bootstrap.py
+
53
−
38
View file @
8a77e386
...
@@ -82,11 +82,13 @@ def which(env, program):
...
@@ -82,11 +82,13 @@ def which(env, program):
fpath
,
fname
=
os
.
path
.
split
(
program
)
fpath
,
fname
=
os
.
path
.
split
(
program
)
if
fpath
:
if
fpath
:
if
is_exe
(
program
):
return
program
if
is_exe
(
program
):
return
program
else
:
else
:
for
path
in
os
.
environ
[
"
PATH
"
].
split
(
os
.
pathsep
):
for
path
in
os
.
environ
[
"
PATH
"
].
split
(
os
.
pathsep
):
exe_file
=
os
.
path
.
join
(
path
,
program
)
exe_file
=
os
.
path
.
join
(
path
,
program
)
if
is_exe
(
exe_file
):
return
exe_file
if
is_exe
(
exe_file
):
return
exe_file
return
None
return
None
...
@@ -106,13 +108,14 @@ def get_rendered_recipe(args):
...
@@ -106,13 +108,14 @@ def get_rendered_recipe(args):
destfile
=
os
.
path
.
join
(
d
,
'
meta.yaml
'
)
destfile
=
os
.
path
.
join
(
d
,
'
meta.yaml
'
)
print
(
'
$ cp %s -> %s
'
%
(
orig
,
destfile
))
print
(
'
$ cp %s -> %s
'
%
(
orig
,
destfile
))
print
(
'
$ edit %s # add bob-devel to host section
'
%
(
destfile
,))
print
(
'
$ edit %s # add bob-devel to host section
'
%
(
destfile
,))
with
open
(
destfile
,
'
wt
'
)
as
f
:
f
.
write
(
contents
)
with
open
(
destfile
,
'
wt
'
)
as
f
:
f
.
write
(
contents
)
cmd
=
[
cmd
=
[
args
.
conda
,
'
render
'
,
args
.
conda
,
'
render
'
,
'
--variant-config-files
'
,
args
.
config
,
'
--variant-config-files
'
,
args
.
config
,
'
--python
'
,
args
.
python
,
d
'
--python
'
,
args
.
python
,
d
]
]
print
((
'
$ CONDARC=%s
'
%
args
.
condarc
)
+
'
'
.
join
(
cmd
))
print
((
'
$ CONDARC=%s
'
%
args
.
condarc
)
+
'
'
.
join
(
cmd
))
output
=
subprocess
.
check_output
(
cmd
,
env
=
args
.
env
)
output
=
subprocess
.
check_output
(
cmd
,
env
=
args
.
env
)
print
(
'
$ rm -rf %s
'
%
(
d
,))
print
(
'
$ rm -rf %s
'
%
(
d
,))
...
@@ -126,7 +129,7 @@ def parse_dependencies(args):
...
@@ -126,7 +129,7 @@ def parse_dependencies(args):
recipe
[
'
requirements
'
].
get
(
'
build
'
,
[])
+
\
recipe
[
'
requirements
'
].
get
(
'
build
'
,
[])
+
\
recipe
[
'
requirements
'
].
get
(
'
run
'
,
[])
+
\
recipe
[
'
requirements
'
].
get
(
'
run
'
,
[])
+
\
recipe
.
get
(
'
test
'
,
{}).
get
(
'
requires
'
,
[])
+
\
recipe
.
get
(
'
test
'
,
{}).
get
(
'
requires
'
,
[])
+
\
[
'
bob.buildout
'
,
'
mr.developer
'
,
'
ipdb
'
]
#
packages required for local dev
[
'
bob.buildout
'
,
'
mr.developer
'
,
'
ipdb
'
]
#
packages required for local dev
def
get_env_directory
(
args
):
def
get_env_directory
(
args
):
...
@@ -135,7 +138,8 @@ def get_env_directory(args):
...
@@ -135,7 +138,8 @@ def get_env_directory(args):
output
=
subprocess
.
check_output
(
cmd
,
env
=
args
.
env
)
output
=
subprocess
.
check_output
(
cmd
,
env
=
args
.
env
)
data
=
json
.
loads
(
output
)
data
=
json
.
loads
(
output
)
retval
=
[
k
for
k
in
data
.
get
(
'
envs
'
,
[])
if
k
.
endswith
(
os
.
sep
+
args
.
name
)]
retval
=
[
k
for
k
in
data
.
get
(
'
envs
'
,
[])
if
k
.
endswith
(
os
.
sep
+
args
.
name
)]
if
retval
:
return
retval
[
0
]
if
retval
:
return
retval
[
0
]
return
None
return
None
...
@@ -143,31 +147,35 @@ def conda_create(args, packages):
...
@@ -143,31 +147,35 @@ def conda_create(args, packages):
specs
=
[]
specs
=
[]
for
k
in
packages
:
for
k
in
packages
:
k
=
'
'
.
join
(
k
.
split
()[:
2
])
#
remove eventual build string
k
=
'
'
.
join
(
k
.
split
()[:
2
])
#
remove eventual build string
if
not
k
.
startswith
(
'
bob
'
):
if
not
k
.
startswith
(
'
bob
'
):
k
=
k
.
split
()[
0
]
#get whatever is compatible for those
k
=
k
.
split
()[
0
]
# get whatever is compatible for those
if
any
(
elem
in
k
for
elem
in
'
><|
'
):
specs
.
append
(
k
.
replace
(
'
'
,
''
))
if
any
(
elem
in
k
for
elem
in
'
><|
'
):
else
:
specs
.
append
(
k
.
replace
(
'
'
,
'
=
'
))
specs
.
append
(
k
.
replace
(
'
'
,
''
))
else
:
specs
.
append
(
k
.
replace
(
'
'
,
'
=
'
))
#if the current environment exists, delete it first
#
if the current environment exists, delete it first
envdir
=
get_env_directory
(
args
)
envdir
=
get_env_directory
(
args
)
if
envdir
is
not
None
:
if
envdir
is
not
None
:
if
args
.
overwrite
:
if
args
.
overwrite
:
cmd
=
[
args
.
conda
,
'
env
'
,
'
remove
'
,
'
--yes
'
,
'
--name
'
,
args
.
name
]
cmd
=
[
args
.
conda
,
'
env
'
,
'
remove
'
,
'
--yes
'
,
'
--name
'
,
args
.
name
]
print
((
'
$ CONDARC=%s
'
%
args
.
condarc
)
+
'
'
.
join
(
cmd
))
print
((
'
$ CONDARC=%s
'
%
args
.
condarc
)
+
'
'
.
join
(
cmd
))
status
=
subprocess
.
call
(
cmd
,
env
=
args
.
env
)
status
=
subprocess
.
call
(
cmd
,
env
=
args
.
env
)
if
status
!=
0
:
return
status
if
status
!=
0
:
return
status
else
:
else
:
raise
RuntimeError
(
'
environment `%s
\'
exists in `%s
\'
- use
'
\
raise
RuntimeError
(
'
environment `%s
\'
exists in `%s
\'
- use
'
'
--overwrite to overwrite
'
%
(
args
.
name
,
envdir
))
'
--overwrite to overwrite
'
%
(
args
.
name
,
envdir
))
cmd
=
[
args
.
conda
,
'
create
'
,
'
--yes
'
,
'
--name
'
,
args
.
name
]
+
specs
cmd
=
[
args
.
conda
,
'
create
'
,
'
--yes
'
,
'
--name
'
,
args
.
name
]
+
specs
print
((
'
$ CONDARC=%s
'
%
args
.
condarc
)
+
'
'
.
join
(
cmd
))
print
((
'
$ CONDARC=%s
'
%
args
.
condarc
)
+
'
'
.
join
(
cmd
))
status
=
subprocess
.
call
(
cmd
,
env
=
args
.
env
)
status
=
subprocess
.
call
(
cmd
,
env
=
args
.
env
)
if
status
!=
0
:
return
status
if
status
!=
0
:
return
status
#copy the used condarc file to the just created environment
#
copy the used condarc file to the just created environment
envdir
=
get_env_directory
(
args
)
envdir
=
get_env_directory
(
args
)
destrc
=
os
.
path
.
join
(
envdir
,
'
.condarc
'
)
destrc
=
os
.
path
.
join
(
envdir
,
'
.condarc
'
)
print
(
'
$ cp %s -> %s
'
%
(
args
.
condarc
,
destrc
))
print
(
'
$ cp %s -> %s
'
%
(
args
.
condarc
,
destrc
))
...
@@ -179,41 +187,48 @@ def main():
...
@@ -179,41 +187,48 @@ def main():
subst
=
{
'
prog
'
:
os
.
path
.
basename
(
sys
.
argv
[
0
])}
subst
=
{
'
prog
'
:
os
.
path
.
basename
(
sys
.
argv
[
0
])}
parser
=
argparse
.
ArgumentParser
(
description
=
'
Creates a conda
'
\
parser
=
argparse
.
ArgumentParser
(
description
=
'
Creates a conda
'
'
environment with the build/run/test dependencies of a package
'
,
'
environment with the build/run/test dependencies of a package
'
,
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
,
formatter_class
=
argparse
.
RawDescriptionHelpFormatter
,
epilog
=
__doc__
%
subst
)
epilog
=
__doc__
%
subst
)
parser
.
add_argument
(
'
name
'
,
help
=
'
name of the target environment to create
'
)
parser
.
add_argument
(
parser
.
add_argument
(
'
recipe
'
,
help
=
'
path to the **directory**
'
\
'
name
'
,
help
=
'
name of the target environment to create
'
)
parser
.
add_argument
(
'
recipe
'
,
help
=
'
path to the **directory**
'
'
containing the conda recipe [default: %(default)s]
'
,
nargs
=
'
?
'
,
'
containing the conda recipe [default: %(default)s]
'
,
nargs
=
'
?
'
,
default
=
os
.
path
.
join
(
os
.
path
.
realpath
(
'
.
'
),
'
conda
'
))
default
=
os
.
path
.
join
(
os
.
path
.
realpath
(
'
.
'
),
'
conda
'
))
parser
.
add_argument
(
parser
.
add_argument
(
'
-p
'
,
'
--python
'
,
help
=
'
version of python to build the
'
\
'
-p
'
,
'
--python
'
,
help
=
'
version of python to build the
'
'
environment for [default: %(default)s]
'
,
nargs
=
'
?
'
,
'
environment for [default: %(default)s]
'
,
nargs
=
'
?
'
,
default
=
(
'
%d.%d
'
%
sys
.
version_info
[:
2
]))
default
=
(
'
%d.%d
'
%
sys
.
version_info
[:
2
]))
parser
.
add_argument
(
'
-c
'
,
'
--conda
'
,
default
=
which
(
os
.
environ
,
'
conda
'
),
parser
.
add_argument
(
help
=
'
path leading to the conda executable to use if not available on
'
\
'
-c
'
,
'
--conda
'
,
default
=
which
(
os
.
environ
,
'
conda
'
),
'
$PATH [default: %(default)s]
'
)
help
=
'
path leading to the conda executable to use if not available on
'
parser
.
add_argument
(
'
-o
'
,
'
--overwrite
'
,
action
=
'
store_true
'
,
default
=
False
,
'
$PATH [default: %(default)s]
'
)
help
=
'
if set and an environment with the same name exists,
'
\
parser
.
add_argument
(
'
deletes it first before creating the new environment
'
)
'
-o
'
,
'
--overwrite
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
'
if set and an environment with the same name exists,
'
BASEDIR
=
os
.
path
.
realpath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
'
deletes it first before creating the new environment
'
)
BASEDIR
=
os
.
path
.
realpath
(
os
.
path
.
dirname
(
sys
.
argv
[
0
]))
default_condarc
=
os
.
path
.
join
(
BASEDIR
,
'
build-condarc
'
)
default_condarc
=
os
.
path
.
join
(
BASEDIR
,
'
build-condarc
'
)
default_condarc
=
os
.
environ
.
get
(
'
CONDARC
'
,
default_condarc
)
default_condarc
=
os
.
environ
.
get
(
'
CONDARC
'
,
default_condarc
)
parser
.
add_argument
(
'
-r
'
,
'
--condarc
'
,
default
=
default_condarc
,
parser
.
add_argument
(
help
=
'
overwrites the path leading to the condarc file to use
'
\
'
-r
'
,
'
--condarc
'
,
default
=
default_condarc
,
'
[default: %(default)s]
'
)
help
=
'
overwrites the path leading to the condarc file to use
'
'
[default: %(default)s]
'
)
default_variant
=
os
.
path
.
join
(
os
.
path
.
dirname
(
BASEDIR
),
'
gitlab
'
,
default_variant
=
os
.
path
.
join
(
os
.
path
.
dirname
(
BASEDIR
),
'
gitlab
'
,
'
conda_build_config.yaml
'
)
'
conda_build_config.yaml
'
)
parser
.
add_argument
(
'
-m
'
,
'
--config
'
,
'
--variant-config-files
'
,
parser
.
add_argument
(
'
-m
'
,
'
--config
'
,
'
--variant-config-files
'
,
default
=
default_variant
,
default
=
default_variant
,
help
=
'
overwrites the path leading to variant configuration file to
'
\
help
=
'
overwrites the path leading to variant configuration file to
'
'
use [default: %(default)s]
'
)
'
use [default: %(default)s]
'
)
# no surprises, no globals - all configuration comes from the cmdline
# no surprises, no globals - all configuration comes from the cmdline
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
...
@@ -230,12 +245,12 @@ def main():
...
@@ -230,12 +245,12 @@ def main():
raise
RuntimeError
(
"
The directory %s does not exist
"
%
args
.
recipe
)
raise
RuntimeError
(
"
The directory %s does not exist
"
%
args
.
recipe
)
# use this environment for all conda-related commands
# use this environment for all conda-related commands
args
.
env
=
env
=
copy
.
copy
(
os
.
environ
)
args
.
env
=
copy
.
copy
(
os
.
environ
)
args
.
env
[
'
CONDARC
'
]
=
args
.
condarc
args
.
env
[
'
CONDARC
'
]
=
args
.
condarc
deps
=
parse_dependencies
(
args
)
deps
=
parse_dependencies
(
args
)
status
=
conda_create
(
args
,
deps
)
status
=
conda_create
(
args
,
deps
)
print
(
'
$ #execute on your shell:
source
activate %s
'
%
args
.
name
)
print
(
'
$ #execute on your shell:
conda
activate %s
'
%
args
.
name
)
sys
.
exit
(
status
)
sys
.
exit
(
status
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment