Comments (4)
@yarikoptic How will the Python version be installed? If not via pip, what third-party libraries can I use?
from containers.
Ideally none which datalad-container does not use, or even better - just whatever comes with python. Which particular library you have in mind for this?
FWIW, here is the code chatgpt generated for 1-to-1 dummy translation of that script into python - if of any help
#!/usr/bin/env python3
import os
import sys
import subprocess
import tempfile
import argparse
# Helper function to perform in-place modifications with sed-like behavior
def sed_i(filename, *args):
with tempfile.NamedTemporaryFile(mode="w", delete=False) as tf:
subprocess.run(["sed", *args, filename], stdout=tf)
os.replace(tf.name, filename)
# Error function to print error messages
def error(*args):
print("ERROR:", *args, file=sys.stderr)
# Parse command line arguments
def parse_args():
parser = argparse.ArgumentParser(description="Freeze or copy container versions")
parser.add_argument("containers", nargs="+", help="containers to freeze or copy")
parser.add_argument("--save-dataset", help="save the dataset to a different location")
return parser.parse_args()
# Get the path to the top directory
topd = os.path.join(os.path.dirname(sys.argv[0]), "..")
if os.path.realpath(topd) == os.path.realpath("."):
topd = "."
args = parse_args()
save_ds = args.save_dataset
target_ds = save_ds or topd
topd_rel = ""
frozen = []
print("topd_rel:", topd_rel)
for arg in args.containers:
if arg.startswith("--"):
print(f"Unknown option '{arg}'", file=sys.stderr)
sys.exit(1)
frozen.append(arg) # Store arguments for commit message
img, ver = arg.split("=") if "=" in arg else (arg, "")
print(f"I: {img} -> {ver}")
if "=" in arg:
imgprefix = os.path.join(topd, f"images/{img.split('-')[0]}/{img}--{ver}")
if os.path.isdir(imgprefix):
imgpath = imgprefix
else:
imgpaths = [p for p in os.listdir(f"{topd}/images/{img.split('-')[0]}") if p.startswith(f"{img}--")]
if len(imgpaths) == 0:
error(f"There is no {imgprefix}.* files. Available images for the app are:")
print("\n".join([f" {p}" for p in os.listdir(f"{topd}/images/{img.split('-')[0]}")]))
sys.exit(1)
elif len(imgpaths) == 1:
imgpath = os.path.realpath(os.path.join(topd, imgpaths[0]))
else:
error("There are multiple images available. Include extension into your version specification. Available images are:")
print("\n".join([f" {p}" for p in imgpaths]))
sys.exit(1)
else:
imgpath = topd_rel + subprocess.check_output(["git", "-C", topd, "config", "-f", ".datalad/config",
f"datalad.containers.{img}.image"]).decode().strip()
subprocess.run(["git", "-C", target_ds, "config", "--replace-all",
f"datalad.containers.{img}.image", imgpath])
if topd_rel:
git_config_output = subprocess.check_output(["git", "-C", topd, "config", "-f", ".datalad/config",
"--get-regexp", f"containers.{img}."]).decode()
for line in git_config_output.splitlines():
var, value = line.split(" ", 1)
if var.endswith(".image"):
continue
if "{img_dspath}/" in value:
value = value.replace("{img_dspath}/", f"{topd_rel}")
else:
value = f"{topd_rel}{value}"
subprocess.run(["git", "-C", target_ds, "config", "--replace-all", var, value])
else:
sed_i(os.path.join(topd, ".datalad/config"), f"s,{imgpath}([ \t].*)*$,{imgpath} # frozen,")
if save_ds is not None:
subprocess.run(["datalad", "save", "-d", save_ds, "-m", f"Freeze container versions {' '.join(frozen)}",
os.path.join(save_ds.rstrip("/"), ".datalad/config")])
from containers.
Which particular library you have in mind for this?
I initially thought this issue was about that Perl script you were working on recently, in which case I would likely have needed at least requests
and beautifulsoup4
.
from containers.
no - perl
script will remain perl script
for now.
from containers.
Related Issues (20)
- containers/scripts/singularity_cmd: Argument list too long HOT 2
- Add retries for docker hub connections
- Add option for "--bind" when running containers HOT 1
- Establish collection of health checks HOT 1
- Provide neurodesk convenience command
- Add ability to specify version of container when running HOT 4
- Go through the typical workflow and "relate" to reproman workflow HOT 3
- Expanded version of explanations for typical workflow HOT 1
- MRIQC OOM error causes unhelpful nipype NodeExecutionError HOT 3
- Warning in output: Set MPLCONFIGDIR when running bids-mriqc HOT 4
- JOSS paper
- make "freeze_version" freeze them in the "super-dataset" instead of the ReproNim/containers HOT 6
- Make testing actually test the version of this dataset as provided in PR
- Update walkthrough for the new preferable way of freezing in superds HOT 1
- fmriprep-fake docker image breaks build process HOT 4
- Bind files/directories into containers? HOT 5
- Investigate CDI support
- apptainer, cache write error HOT 2
- Move from travis to github actions HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from containers.