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
d3217029
Commit
d3217029
authored
1 year ago
by
Klaus Reuter
Browse files
Options
Downloads
Patches
Plain Diff
add support for pip requirements.txt file
parent
a89d6ea1
No related branches found
No related tags found
No related merge requests found
Pipeline
#181649
passed
1 year ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+4
-2
4 additions, 2 deletions
README.md
condainer/condainer.py
+29
-4
29 additions, 4 deletions
condainer/condainer.py
with
33 additions
and
6 deletions
README.md
+
4
−
2
View file @
d3217029
...
@@ -106,8 +106,10 @@ to the same directory.
...
@@ -106,8 +106,10 @@ to the same directory.
### Build and compress an environment using `cnd build`
### Build and compress an environment using `cnd build`
Build the conda environment specified in
`environment.yml`
and
Build the conda environment specified in
`environment.yml`
. In case
create a compressed squashfs image.
a file
`requirements.txt`
is present, its contents will be installed
additionally using
`pip`
. Finally, create a compressed
squashfs image, and delete the files from staging the environment.
### Execute a command using `cnd exec`
### Execute a command using `cnd exec`
...
...
This diff is collapsed.
Click to expand it.
condainer/condainer.py
+
29
−
4
View file @
d3217029
...
@@ -27,12 +27,13 @@ class termcol:
...
@@ -27,12 +27,13 @@ class termcol:
def
get_example_environment_yml
():
def
get_example_environment_yml
():
raw
=
\
raw
=
\
"""
"""
name: basic
numpy
name: basic
channels:
channels:
- conda-forge
- conda-forge
dependencies:
dependencies:
- python=3.9
- python=3.9
- numpy
- pip
#- numpy
"""
"""
return
yaml
.
safe_load
(
raw
)
return
yaml
.
safe_load
(
raw
)
...
@@ -174,18 +175,40 @@ def create_condainer_environment(cfg):
...
@@ -174,18 +175,40 @@ def create_condainer_environment(cfg):
exe
=
os
.
path
.
join
(
os
.
path
.
join
(
env_directory
,
'
bin
'
),
cfg
[
'
conda_exe
'
])
exe
=
os
.
path
.
join
(
os
.
path
.
join
(
env_directory
,
'
bin
'
),
cfg
[
'
conda_exe
'
])
environment_yml
=
cfg
[
"
environment_yml
"
]
environment_yml
=
cfg
[
"
environment_yml
"
]
cmd
=
f
"
{
exe
}
env create --file
{
environment_yml
}
--name condainer
"
.
split
()
cmd
=
f
"
{
exe
}
env create --file
{
environment_yml
}
--name condainer
"
.
split
()
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
)
env
=
copy
.
deepcopy
(
os
.
environ
)
if
"
PYTHONPATH
"
in
env
:
del
env
[
"
PYTHONPATH
"
]
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
env
=
env
)
proc
.
communicate
()
proc
.
communicate
()
assert
(
proc
.
returncode
==
0
)
assert
(
proc
.
returncode
==
0
)
def
pip_condainer_environment
(
cfg
):
"""
Install user-defined software stack (requirements.txt) into
'
condainer
'
environment.
"""
env_directory
=
get_env_directory
(
cfg
)
exe
=
os
.
path
.
join
(
os
.
path
.
join
(
env_directory
,
'
bin
'
),
'
pip3
'
)
requirements_txt
=
cfg
[
"
requirements_txt
"
]
if
os
.
path
.
isfile
(
requirements_txt
):
cmd
=
f
"
{
exe
}
install --requirement
{
requirements_txt
}
--no-cache-dir
"
.
split
()
env
=
copy
.
deepcopy
(
os
.
environ
)
if
"
PYTHONPATH
"
in
env
:
del
env
[
"
PYTHONPATH
"
]
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
env
=
env
)
proc
.
communicate
()
assert
(
proc
.
returncode
==
0
)
def
clean_environment
(
cfg
):
def
clean_environment
(
cfg
):
"""
Delete pkg files and other unnecessary files from base environment.
"""
Delete pkg files and other unnecessary files from base environment.
"""
"""
env_directory
=
get_env_directory
(
cfg
)
env_directory
=
get_env_directory
(
cfg
)
exe
=
os
.
path
.
join
(
os
.
path
.
join
(
env_directory
,
'
bin
'
),
cfg
[
'
conda_exe
'
])
exe
=
os
.
path
.
join
(
os
.
path
.
join
(
env_directory
,
'
bin
'
),
cfg
[
'
conda_exe
'
])
cmd
=
f
"
{
exe
}
clean --all --yes
"
.
split
()
cmd
=
f
"
{
exe
}
clean --all --yes
"
.
split
()
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
)
env
=
copy
.
deepcopy
(
os
.
environ
)
if
"
PYTHONPATH
"
in
env
:
del
env
[
"
PYTHONPATH
"
]
proc
=
subprocess
.
Popen
(
cmd
,
shell
=
False
,
env
=
env
)
proc
.
communicate
()
proc
.
communicate
()
assert
(
proc
.
returncode
==
0
)
assert
(
proc
.
returncode
==
0
)
...
@@ -227,6 +250,7 @@ def init(args):
...
@@ -227,6 +250,7 @@ def init(args):
cfg
=
{}
cfg
=
{}
cfg
[
'
environment_yml
'
]
=
'
environment.yml
'
cfg
[
'
environment_yml
'
]
=
'
environment.yml
'
cfg
[
"
requirements_txt
"
]
=
'
requirements.txt
'
cfg
[
'
installer_url
'
]
=
installer_url
cfg
[
'
installer_url
'
]
=
installer_url
cfg
[
'
conda_exe
'
]
=
'
mamba
'
cfg
[
'
conda_exe
'
]
=
'
mamba
'
cfg
[
'
mount_base_directory
'
]
=
'
/tmp
'
cfg
[
'
mount_base_directory
'
]
=
'
/tmp
'
...
@@ -276,6 +300,7 @@ def build(args):
...
@@ -276,6 +300,7 @@ def build(args):
os
.
makedirs
(
env_directory
,
exist_ok
=
True
,
mode
=
0o700
)
os
.
makedirs
(
env_directory
,
exist_ok
=
True
,
mode
=
0o700
)
create_base_environment
(
cfg
)
create_base_environment
(
cfg
)
create_condainer_environment
(
cfg
)
create_condainer_environment
(
cfg
)
pip_condainer_environment
(
cfg
)
clean_environment
(
cfg
)
clean_environment
(
cfg
)
compress_environment
(
cfg
)
compress_environment
(
cfg
)
write_activate_script
(
cfg
)
write_activate_script
(
cfg
)
...
...
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