diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bb1e54..c43ce0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The client here will eventually be released as "spython" (and eventually to singularity on pypi), and the versions here will coincide with these releases. ## [master](https://github.com/singularityhub/singularity-cli/tree/master) + - WORKDIR should create container for Singularity converter (0.0.12) - support for background process with client run (0.2.11) - parser bugfixes, arg from Docker not properly parsed (0.2.1) - version checks removed to support Singularity 3.x and above (0.2.0) diff --git a/spython/client/__init__.py b/spython/client/__init__.py index 343a5fa..2a6bed9 100644 --- a/spython/client/__init__.py +++ b/spython/client/__init__.py @@ -8,8 +8,8 @@ import argparse -import sys import os +import sys def get_parser(): diff --git a/spython/client/recipe.py b/spython/client/recipe.py index 189506b..57be3cb 100644 --- a/spython/client/recipe.py +++ b/spython/client/recipe.py @@ -4,16 +4,15 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.main.parse.writers import get_writer -from spython.main.parse.parsers import get_parser +import json +import os +import sys from spython.logger import bot +from spython.main.parse.parsers import get_parser +from spython.main.parse.writers import get_writer from spython.utils import write_file, write_json -import json -import sys -import os - def main(args, options, parser): """This function serves as a wrapper around the DockerParser, diff --git a/spython/client/shell.py b/spython/client/shell.py index 252165f..3e23b4b 100644 --- a/spython/client/shell.py +++ b/spython/client/shell.py @@ -27,8 +27,7 @@ def prepare_client(image): """prepare a client to embed in a shell with recipe parsers and writers.""" # The client will announce itself (backend/database) unless it's get from spython.main import get_client - from spython.main.parse import parsers - from spython.main.parse import writers + from spython.main.parse import parsers, writers client = get_client() diff --git a/spython/image.py b/spython/image.py index 8538cef..4a9b36b 100644 --- a/spython/image.py +++ b/spython/image.py @@ -6,6 +6,7 @@ import hashlib import os + from spython.logger import bot from spython.utils import split_uri diff --git a/spython/instance/__init__.py b/spython/instance/__init__.py index bfb32a3..2910243 100644 --- a/spython/instance/__init__.py +++ b/spython/instance/__init__.py @@ -4,10 +4,11 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.utils.fileio import read_file -from spython.image import ImageBase import os +from spython.image import ImageBase +from spython.utils.fileio import read_file + class Instance(ImageBase): def __init__(self, image, start=True, name=None, quiet=True, **kwargs): diff --git a/spython/instance/cmd/__init__.py b/spython/instance/cmd/__init__.py index 2580ea6..22fdaeb 100644 --- a/spython/instance/cmd/__init__.py +++ b/spython/instance/cmd/__init__.py @@ -13,16 +13,16 @@ def generate_instance_commands(): """ from spython.instance import Instance + # run_command uses run_cmd, but wraps to catch error + from spython.main.base.command import init_command, run_command + from spython.main.base.generate import RobotNamer from spython.main.base.logger import println from spython.main.instances import list_instances from spython.utils import run_command as run_cmd - # run_command uses run_cmd, but wraps to catch error - from spython.main.base.command import init_command, run_command - from spython.main.base.generate import RobotNamer + from .logs import _logs, error_logs, output_logs from .start import start from .stop import stop - from .logs import error_logs, output_logs, _logs Instance.RobotNamer = RobotNamer() Instance._init_command = init_command diff --git a/spython/instance/cmd/logs.py b/spython/instance/cmd/logs.py index 1d8aaa8..c407bac 100644 --- a/spython/instance/cmd/logs.py +++ b/spython/instance/cmd/logs.py @@ -5,10 +5,11 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.utils import get_userhome, get_username -from spython.logger import bot -import platform import os +import platform + +from spython.logger import bot +from spython.utils import get_userhome, get_username def error_logs(self, print_logs=False): diff --git a/spython/instance/cmd/start.py b/spython/instance/cmd/start.py index 485061e..8a11203 100644 --- a/spython/instance/cmd/start.py +++ b/spython/instance/cmd/start.py @@ -39,7 +39,7 @@ def start( singularity [...] instance.start [...] """ - from spython.utils import run_command, check_install + from spython.utils import check_install, run_command check_install() diff --git a/spython/logger/message.py b/spython/logger/message.py index 15637f8..b472ab0 100644 --- a/spython/logger/message.py +++ b/spython/logger/message.py @@ -6,9 +6,11 @@ import os import sys -from .spinner import Spinner + from spython.logger import decodeUtf8String +from .spinner import Spinner + ABORT = -5 CRITICAL = -4 ERROR = -3 diff --git a/spython/logger/spinner.py b/spython/logger/spinner.py index 9d32753..9a200e0 100644 --- a/spython/logger/spinner.py +++ b/spython/logger/spinner.py @@ -6,8 +6,8 @@ import sys -import time import threading +import time from random import choice diff --git a/spython/main/__init__.py b/spython/main/__init__.py index 4fdeccc..ad7feda 100644 --- a/spython/main/__init__.py +++ b/spython/main/__init__.py @@ -25,12 +25,12 @@ def get_client(quiet=False, debug=False): from .apps import apps from .build import build from .execute import execute, shell + from .export import export from .help import helpcmd from .inspect import inspect from .instances import list_instances, stopall # global instance commands - from .run import run from .pull import pull - from .export import export + from .run import run # Actions client.apps = apps diff --git a/spython/main/base/__init__.py b/spython/main/base/__init__.py index 7c7dc45..d87654d 100644 --- a/spython/main/base/__init__.py +++ b/spython/main/base/__init__.py @@ -14,9 +14,9 @@ from .command import generate_bind_list, init_command, run_command from .flags import parse_verbosity -from .sutils import get_uri, load, setenv, get_filename -from .logger import println, init_level from .generate import RobotNamer +from .logger import init_level, println +from .sutils import get_filename, get_uri, load, setenv class Client: diff --git a/spython/main/base/command.py b/spython/main/base/command.py index 3e19e8d..17a626f 100644 --- a/spython/main/base/command.py +++ b/spython/main/base/command.py @@ -5,13 +5,12 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.utils import run_command as run_cmd - -from spython.logger import bot - +import os import subprocess import sys -import os + +from spython.logger import bot +from spython.utils import run_command as run_cmd def init_command(self, action, flags=None): diff --git a/spython/main/base/logger.py b/spython/main/base/logger.py index 065e1cd..c449341 100644 --- a/spython/main/base/logger.py +++ b/spython/main/base/logger.py @@ -6,6 +6,7 @@ import os + from spython.logger import decodeUtf8String diff --git a/spython/main/base/sutils.py b/spython/main/base/sutils.py index bf4d802..265ace1 100644 --- a/spython/main/base/sutils.py +++ b/spython/main/base/sutils.py @@ -8,10 +8,11 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.logger import bot import os import re +from spython.logger import bot + def load(self, image=None): """load an image, either an actual path on the filesystem or a uri. diff --git a/spython/main/build.py b/spython/main/build.py index 5132b97..360dbf7 100644 --- a/spython/main/build.py +++ b/spython/main/build.py @@ -5,10 +5,11 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +import os +import re + from spython.logger import bot from spython.utils import stream_command -import re -import os def build( diff --git a/spython/main/execute.py b/spython/main/execute.py index 066abb4..c690cdf 100644 --- a/spython/main/execute.py +++ b/spython/main/execute.py @@ -5,11 +5,11 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +import os + from spython.logger import bot from spython.utils import stream_command, which -import os - def execute( self, diff --git a/spython/main/export.py b/spython/main/export.py index 1cc5027..8d3d8eb 100644 --- a/spython/main/export.py +++ b/spython/main/export.py @@ -5,9 +5,10 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.logger import bot import os +from spython.logger import bot + def export( self, diff --git a/spython/main/inspect.py b/spython/main/inspect.py index 079131d..35b8d79 100644 --- a/spython/main/inspect.py +++ b/spython/main/inspect.py @@ -5,8 +5,8 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. import json as jsonp -from spython.logger import bot +from spython.logger import bot from spython.utils import check_install, run_command diff --git a/spython/main/instances.py b/spython/main/instances.py index 53cabfc..f75b9a4 100644 --- a/spython/main/instances.py +++ b/spython/main/instances.py @@ -5,9 +5,10 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +import json + from spython.logger import bot from spython.utils import run_command -import json def list_instances( diff --git a/spython/main/parse/parsers/base.py b/spython/main/parse/parsers/base.py index cd64a1e..0661394 100644 --- a/spython/main/parse/parsers/base.py +++ b/spython/main/parse/parsers/base.py @@ -5,12 +5,13 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. import abc -from copy import deepcopy import os import re +from copy import deepcopy from spython.logger import bot from spython.utils import read_file + from ..recipe import Recipe diff --git a/spython/main/parse/parsers/docker.py b/spython/main/parse/parsers/docker.py index 3a900bd..51e9335 100644 --- a/spython/main/parse/parsers/docker.py +++ b/spython/main/parse/parsers/docker.py @@ -9,6 +9,7 @@ import re from spython.logger import bot + from .base import ParserBase @@ -425,6 +426,8 @@ def _workdir(self, line): """ # Save the last working directory to add to the runscript workdir = self._setup("WORKDIR", line) + workdir_mkdir = "mkdir -p %s" % ("".join(workdir)) + self.recipe[self.active_layer].install.append(workdir_mkdir) workdir_cd = "cd %s" % ("".join(workdir)) self.recipe[self.active_layer].install.append(workdir_cd) self.recipe[self.active_layer].workdir = workdir[0] diff --git a/spython/main/parse/parsers/singularity.py b/spython/main/parse/parsers/singularity.py index 1c3a1a6..151dee7 100644 --- a/spython/main/parse/parsers/singularity.py +++ b/spython/main/parse/parsers/singularity.py @@ -8,6 +8,7 @@ import re from spython.logger import bot + from .base import ParserBase diff --git a/spython/main/parse/writers/base.py b/spython/main/parse/writers/base.py index 342f426..4e06331 100644 --- a/spython/main/parse/writers/base.py +++ b/spython/main/parse/writers/base.py @@ -7,6 +7,7 @@ import os import tempfile + from spython.logger import bot from spython.utils import write_file diff --git a/spython/main/parse/writers/docker.py b/spython/main/parse/writers/docker.py index bf59d52..92f80c5 100644 --- a/spython/main/parse/writers/docker.py +++ b/spython/main/parse/writers/docker.py @@ -6,6 +6,7 @@ import re + from spython.logger import bot from .base import WriterBase diff --git a/spython/main/parse/writers/singularity.py b/spython/main/parse/writers/singularity.py index 8007ea0..907e72a 100644 --- a/spython/main/parse/writers/singularity.py +++ b/spython/main/parse/writers/singularity.py @@ -6,6 +6,7 @@ import re + from spython.logger import bot from .base import WriterBase diff --git a/spython/main/pull.py b/spython/main/pull.py index 38baa8c..c4eee6f 100644 --- a/spython/main/pull.py +++ b/spython/main/pull.py @@ -5,11 +5,12 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.logger import bot -from spython.utils import stream_command, ScopedEnvVar import os import re +from spython.logger import bot +from spython.utils import ScopedEnvVar, stream_command + def pull( self, diff --git a/spython/main/run.py b/spython/main/run.py index 03fb3dc..85ef271 100644 --- a/spython/main/run.py +++ b/spython/main/run.py @@ -5,9 +5,10 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +import json + from spython.logger import bot from spython.utils import stream_command -import json def run( diff --git a/spython/oci/cmd/__init__.py b/spython/oci/cmd/__init__.py index c89a767..cfe8e0f 100644 --- a/spython/oci/cmd/__init__.py +++ b/spython/oci/cmd/__init__.py @@ -9,18 +9,17 @@ def generate_oci_commands(): """The oci command group will allow interaction with an image using OCI commands. """ - from spython.oci import OciImage - - from spython.main.base.logger import println - # run_command uses run_cmd, but wraps to catch error from spython.main.base.command import run_command, send_command from spython.main.base.generate import RobotNamer + from spython.main.base.logger import println + from spython.oci import OciImage + + from .actions import _run, attach, create, delete, execute, run, update # Oci Command Groups from .mounts import mount, umount - from .states import kill, state, start, pause, resume, _state_command - from .actions import attach, create, delete, execute, run, _run, update + from .states import _state_command, kill, pause, resume, start, state # Oci Commands OciImage.start = start diff --git a/spython/oci/cmd/actions.py b/spython/oci/cmd/actions.py index 9f54bdb..80758ab 100644 --- a/spython/oci/cmd/actions.py +++ b/spython/oci/cmd/actions.py @@ -4,9 +4,10 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +import os + from spython.logger import bot from spython.utils import stream_command -import os def run( diff --git a/spython/tests/conftest.py b/spython/tests/conftest.py index b6a4969..dca8bca 100644 --- a/spython/tests/conftest.py +++ b/spython/tests/conftest.py @@ -1,6 +1,8 @@ -from glob import glob import os +from glob import glob + import pytest + from spython.main import Client from spython.utils import get_installdir diff --git a/spython/tests/test_client.py b/spython/tests/test_client.py index 67ff5db..3531114 100644 --- a/spython/tests/test_client.py +++ b/spython/tests/test_client.py @@ -6,13 +6,15 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.main import Client -from spython.utils import write_file -import shutil import os -import pytest +import shutil from subprocess import CalledProcessError +import pytest + +from spython.main import Client +from spython.utils import write_file + def test_build_from_docker(tmp_path): container = str(tmp_path / "container.sif") diff --git a/spython/tests/test_conversion.py b/spython/tests/test_conversion.py index e6fe7b2..3e04eb6 100644 --- a/spython/tests/test_conversion.py +++ b/spython/tests/test_conversion.py @@ -6,8 +6,8 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from glob import glob import os +from glob import glob def read_file(file): @@ -43,6 +43,11 @@ def test_docker2singularity(test_data, tmp_path): for dockerfile, recipe in test_data["d2s"]: parser = DockerParser(dockerfile) writer = SingularityWriter(parser.recipe) + if not writer.convert().strip("\n") == read_file(recipe): + import IPython + + IPython.embed() + assert writer.convert().strip("\n") == read_file(recipe) diff --git a/spython/tests/test_instances.py b/spython/tests/test_instances.py index ebd8aaa..3690ed1 100644 --- a/spython/tests/test_instances.py +++ b/spython/tests/test_instances.py @@ -6,12 +6,13 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -import pytest -from spython.main import Client - # name instance based on Python version in case running in parallel import sys +import pytest + +from spython.main import Client + version_string = "%s_%s_%s" % ( sys.version_info[0], sys.version_info[1], diff --git a/spython/tests/test_oci.py b/spython/tests/test_oci.py index aa48da1..83dbd62 100644 --- a/spython/tests/test_oci.py +++ b/spython/tests/test_oci.py @@ -6,14 +6,15 @@ # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -from spython.utils import get_installdir -from spython.main.base.generate import RobotNamer -from spython.main import Client -import shutil import os +import shutil + import pytest from semver import VersionInfo +from spython.main import Client +from spython.main.base.generate import RobotNamer +from spython.utils import get_installdir pytestmark = pytest.mark.skipif( Client.version_info() < VersionInfo(3, 0, 0), diff --git a/spython/tests/test_parsers.py b/spython/tests/test_parsers.py index 9cfc475..bc90826 100644 --- a/spython/tests/test_parsers.py +++ b/spython/tests/test_parsers.py @@ -7,6 +7,7 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. import os + from spython.main.parse.parsers import DockerParser, SingularityParser diff --git a/spython/tests/test_utils.py b/spython/tests/test_utils.py index 5076f9f..badf997 100644 --- a/spython/tests/test_utils.py +++ b/spython/tests/test_utils.py @@ -7,8 +7,10 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. import os + import pytest from semver import VersionInfo + from spython.utils import ScopedEnvVar @@ -41,6 +43,7 @@ def test_write_bad_json(tmp_path): def test_write_json(tmp_path): import json + from spython.utils import write_json good_json = {"Wakkawakkawakka": [True, "2", 3]} diff --git a/spython/tests/test_writers.py b/spython/tests/test_writers.py index b7bd30a..93ff7f0 100644 --- a/spython/tests/test_writers.py +++ b/spython/tests/test_writers.py @@ -7,6 +7,7 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. import os + from spython.main.parse.writers import DockerWriter, SingularityWriter diff --git a/spython/tests/testdata/docker2singularity/argsub.def b/spython/tests/testdata/docker2singularity/argsub.def index 2bd0f0d..d3b355d 100644 --- a/spython/tests/testdata/docker2singularity/argsub.def +++ b/spython/tests/testdata/docker2singularity/argsub.def @@ -24,6 +24,7 @@ apt-get install -y wget python3-pip python3 -m pip install --upgrade pip +mkdir -p /workspace cd /workspace python3 -m pip install -r /workspace/requirements.txt and &&\ rm /workspace/requirements.txt diff --git a/spython/tests/testdata/docker2singularity/workdir.def b/spython/tests/testdata/docker2singularity/workdir.def index 27b5941..a3888b7 100644 --- a/spython/tests/testdata/docker2singularity/workdir.def +++ b/spython/tests/testdata/docker2singularity/workdir.def @@ -3,6 +3,7 @@ From: busybox:latest Stage: spython-base %post +mkdir -p /code cd /code %runscript cd /code diff --git a/spython/utils/__init__.py b/spython/utils/__init__.py index 623e8a2..f30da08 100644 --- a/spython/utils/__init__.py +++ b/spython/utils/__init__.py @@ -1,7 +1,5 @@ -from .fileio import mkdir_p, write_file, write_json, read_file, read_json - +from .fileio import mkdir_p, read_file, read_json, write_file, write_json from .misc import ScopedEnvVar - from .terminal import ( check_install, format_container_name, @@ -12,7 +10,7 @@ get_username, remove_uri, run_command, - stream_command, split_uri, + stream_command, which, ) diff --git a/spython/utils/fileio.py b/spython/utils/fileio.py index 1f6ebf1..ea06147 100644 --- a/spython/utils/fileio.py +++ b/spython/utils/fileio.py @@ -9,11 +9,11 @@ """ import errno -import os import json -from spython.logger import bot +import os import sys +from spython.logger import bot ################################################################################ ## FOLDER OPERATIONS ########################################################### diff --git a/spython/utils/terminal.py b/spython/utils/terminal.py index 2fd32f4..5a53a1b 100644 --- a/spython/utils/terminal.py +++ b/spython/utils/terminal.py @@ -11,12 +11,13 @@ import os import pwd import re -import semver -from spython.logger import bot -from spython.logger import decodeUtf8String +import shlex import subprocess import sys -import shlex + +import semver + +from spython.logger import bot, decodeUtf8String ################################################################################ # Local commands and requests diff --git a/spython/version.py b/spython/version.py index 9ea7560..bc60c47 100644 --- a/spython/version.py +++ b/spython/version.py @@ -5,7 +5,7 @@ # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -__version__ = "0.2.11" +__version__ = "0.2.12" AUTHOR = "Vanessa Sochat" AUTHOR_EMAIL = "vsoch@users.noreply.github.com" NAME = "spython"