Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Condainer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpcdf
Condainer
Commits
dacdaa52
Commit
dacdaa52
authored
1 year ago
by
Klaus Reuter
Browse files
Options
Downloads
Plain Diff
Merge branch 'fix_quiet_cfg'
parents
55a4f980
59ef6718
No related branches found
No related tags found
No related merge requests found
Pipeline
#191218
passed
1 year ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
condainer/condainer.py
+22
-22
22 additions, 22 deletions
condainer/condainer.py
with
22 additions
and
22 deletions
condainer/condainer.py
+
22
−
22
View file @
dacdaa52
...
...
@@ -184,7 +184,7 @@ def release_lock(lock_fh):
lock_fh
.
close
()
def
create_base_environment
(
cfg
):
def
create_base_environment
(
cfg
,
args
):
"""
Create base environment.
"""
conda_installer
=
get_installer_path
(
cfg
)
...
...
@@ -193,7 +193,7 @@ def create_base_environment(cfg):
env
=
copy
.
deepcopy
(
os
.
environ
)
if
"
PYTHONPATH
"
in
env
:
del
env
[
"
PYTHONPATH
"
]
if
cfg
.
get
(
"
dryrun
"
)
:
if
args
.
dryrun
:
print
(
f
"
dryrun:
{
'
'
.
join
(
cmd
)
}
"
)
else
:
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
env
=
env
)
...
...
@@ -206,7 +206,7 @@ def create_base_environment(cfg):
fp
.
write
(
yaml
.
safe_dump
(
condarc
))
def
create_condainer_environment
(
cfg
):
def
create_condainer_environment
(
cfg
,
args
):
"""
Install user-defined software stack (environment.yml) into
'
condainer
'
environment.
"""
env_directory
=
get_base_env_directory
(
cfg
)
...
...
@@ -219,7 +219,7 @@ def create_condainer_environment(cfg):
env
=
copy
.
deepcopy
(
os
.
environ
)
if
"
PYTHONPATH
"
in
env
:
del
env
[
"
PYTHONPATH
"
]
if
cfg
.
get
(
"
dryrun
"
)
:
if
args
.
dryrun
:
print
(
f
"
dryrun:
{
'
'
.
join
(
cmd
)
}
"
)
write_cfg
(
cfg
)
else
:
...
...
@@ -230,7 +230,7 @@ def create_condainer_environment(cfg):
write_cfg
(
cfg
)
def
pip_condainer_environment
(
cfg
):
def
pip_condainer_environment
(
cfg
,
args
):
"""
Install user-defined software stack (requirements.txt) into
'
condainer
'
environment.
"""
exe
=
os
.
path
.
join
(
get_user_env_directory
(
cfg
),
'
bin
'
,
'
pip3
'
)
...
...
@@ -240,18 +240,18 @@ def pip_condainer_environment(cfg):
env
=
copy
.
deepcopy
(
os
.
environ
)
if
"
PYTHONPATH
"
in
env
:
del
env
[
"
PYTHONPATH
"
]
if
cfg
.
get
(
"
dryrun
"
)
:
if
args
.
dryrun
:
print
(
f
"
dryrun:
{
'
'
.
join
(
cmd
)
}
"
)
else
:
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
env
=
env
)
proc
.
communicate
()
assert
(
proc
.
returncode
==
0
)
else
:
if
not
cfg
.
get
(
"
quiet
"
)
:
if
not
args
.
quiet
:
print
(
f
"
{
requirements_txt
}
not found, skipping pip
"
)
def
clean_environment
(
cfg
):
def
clean_environment
(
cfg
,
args
):
"""
Delete pkg files and other unnecessary files from base environment.
"""
env_directory
=
get_base_env_directory
(
cfg
)
...
...
@@ -260,7 +260,7 @@ def clean_environment(cfg):
env
=
copy
.
deepcopy
(
os
.
environ
)
if
"
PYTHONPATH
"
in
env
:
del
env
[
"
PYTHONPATH
"
]
if
cfg
.
get
(
"
dryrun
"
)
:
if
args
.
dryrun
:
print
(
f
"
dryrun:
{
'
'
.
join
(
cmd
)
}
"
)
else
:
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
env
=
env
)
...
...
@@ -280,14 +280,14 @@ def get_squashfs_num_threads():
return
n_cores
def
compress_environment
(
cfg
,
read_only_flags
=
True
):
def
compress_environment
(
cfg
,
args
,
read_only_flags
=
True
):
"""
Create squashfs image from base environment.
"""
env_directory
=
get_base_env_directory
(
cfg
)
# explicitly set read-only flags before compressing
if
read_only_flags
:
cmd
=
f
"
chmod -R a-w
{
env_directory
}
"
.
split
()
if
cfg
.
get
(
"
dryrun
"
)
:
if
args
.
dryrun
:
print
(
f
"
dryrun:
{
'
'
.
join
(
cmd
)
}
"
)
else
:
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
)
...
...
@@ -297,7 +297,7 @@ def compress_environment(cfg, read_only_flags=True):
squashfs_image
=
get_image_filename
(
cfg
)
num_threads
=
get_squashfs_num_threads
()
cmd
=
f
"
mksquashfs
{
env_directory
}
/
{
squashfs_image
}
-noappend -processors
{
num_threads
}
"
.
split
()
if
cfg
.
get
(
"
dryrun
"
)
:
if
args
.
dryrun
:
print
(
f
"
dryrun:
{
'
'
.
join
(
cmd
)
}
"
)
else
:
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
)
...
...
@@ -306,7 +306,7 @@ def compress_environment(cfg, read_only_flags=True):
# restore permissions, allowing to delete the staging directory later
if
read_only_flags
:
cmd
=
f
"
chmod -R u+w
{
env_directory
}
"
.
split
()
if
cfg
.
get
(
"
dryrun
"
)
:
if
args
.
dryrun
:
print
(
f
"
dryrun:
{
'
'
.
join
(
cmd
)
}
"
)
else
:
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
)
...
...
@@ -399,8 +399,6 @@ def build(args):
"""
Create conda environment and create compressed squashfs image from it.
"""
cfg
=
get_cfg
()
cfg
[
"
quiet
"
]
=
args
.
quiet
cfg
[
"
dryrun
"
]
=
args
.
dryrun
squashfs_image
=
get_image_filename
(
cfg
)
env_directory
=
get_base_env_directory
(
cfg
)
if
os
.
path
.
isfile
(
squashfs_image
):
...
...
@@ -414,28 +412,30 @@ def build(args):
try
:
if
not
args
.
quiet
:
print
(
termcol
.
BOLD
+
"
Starting Condainer build process ...
"
+
termcol
.
ENDC
)
print
(
"
By continuing you accept the BSD-3-Clause license of the Miniforge installer,
"
)
print
(
"
see https://github.com/conda-forge/miniforge for details.
"
)
if
not
args
.
dryrun
:
os
.
makedirs
(
env_directory
,
exist_ok
=
True
,
mode
=
0o700
)
if
(
1
in
steps
)
and
(
not
cfg
.
get
(
'
non_conda_application
'
)):
if
not
args
.
quiet
:
print
(
termcol
.
BOLD
+
termcol
.
CYAN
+
"
1) Creating
\"
base
\"
environment ...
"
+
termcol
.
ENDC
)
create_base_environment
(
cfg
)
create_base_environment
(
cfg
,
args
)
if
(
2
in
steps
)
and
(
not
cfg
.
get
(
'
non_conda_application
'
)):
if
not
args
.
quiet
:
print
(
termcol
.
BOLD
+
termcol
.
CYAN
+
f
"
2) Creating
\"
condainer
\"
environment from
{
cfg
[
'
environment_yml
'
]
}
...
"
+
termcol
.
ENDC
)
create_condainer_environment
(
cfg
)
create_condainer_environment
(
cfg
,
args
)
if
(
3
in
steps
)
and
(
not
cfg
.
get
(
'
non_conda_application
'
)):
if
not
args
.
quiet
:
print
(
termcol
.
BOLD
+
termcol
.
CYAN
+
f
"
3) Adding packages from
{
cfg
[
'
requirements_txt
'
]
}
via pip ...
"
+
termcol
.
ENDC
)
pip_condainer_environment
(
cfg
)
pip_condainer_environment
(
cfg
,
args
)
if
(
4
in
steps
)
and
(
not
cfg
.
get
(
'
non_conda_application
'
)):
if
not
args
.
quiet
:
print
(
termcol
.
BOLD
+
termcol
.
CYAN
+
"
4) Cleaning environments from unnecessary files ...
"
+
termcol
.
ENDC
)
clean_environment
(
cfg
)
clean_environment
(
cfg
,
args
)
if
5
in
steps
:
if
not
args
.
quiet
:
print
(
termcol
.
BOLD
+
termcol
.
CYAN
+
"
5) Compressing installation directory into SquashFS image ...
"
+
termcol
.
ENDC
)
compress_environment
(
cfg
)
compress_environment
(
cfg
,
args
)
if
(
6
in
steps
)
and
(
not
cfg
.
get
(
'
non_conda_application
'
)):
if
not
args
.
quiet
:
print
(
termcol
.
BOLD
+
termcol
.
CYAN
+
"
6) Creating activate and deactivate scripts ...
"
+
termcol
.
ENDC
)
...
...
@@ -465,7 +465,7 @@ def mount(args):
if
cfg
.
get
(
'
multiuser_mountpoint
'
):
assert
(
cfg
.
get
(
'
non_conda_application
'
)
==
True
)
if
is_mounted
(
cfg
):
if
(
not
args
.
quiet
)
and
()
:
if
not
args
.
quiet
:
print
(
"
hint: condainer already mounted
"
)
else
:
env_directory
=
get_base_env_directory
(
cfg
)
...
...
@@ -542,7 +542,7 @@ def prereq(args):
def
status
(
args
):
"""
Print status of the present Condainer.
"""
Print status of the present Condainer
project directory
.
"""
cfg
=
get_cfg
()
print
(
termcol
.
BOLD
+
"
Condainer status
"
+
termcol
.
ENDC
)
...
...
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