Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

running black-20.8b1 for linting, pinning version in testing #168

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ jobs:
- uses: actions/checkout@v2

- name: Setup black linter
run: conda create --quiet --name black black pyflakes
run: conda create --quiet --name black pyflakes

- name: Lint python code with black
run: |
export PATH="/usr/share/miniconda/bin:$PATH"
source activate black
pip install black==20.8b1
black --check spython

- name: Check unused imports with pyflakes
Expand Down
10 changes: 4 additions & 6 deletions spython/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ def get_parser():


def set_verbosity(args):
"""determine the message level in the environment to set based on args.
"""
"""determine the message level in the environment to set based on args."""
level = "INFO"

if args.debug:
Expand All @@ -141,8 +140,7 @@ def set_verbosity(args):


def version():
"""version prints the version, both for the user and help output
"""
"""version prints the version, both for the user and help output"""
import spython

return spython.__version__
Expand All @@ -153,8 +151,8 @@ def main():
parser = get_parser()

def print_help(return_code=0):
"""print help, including the software version and active client
and exit with return code.
"""print help, including the software version and active client
and exit with return code.
"""
v = version()
print("\nSingularity Python [v%s]\n" % (v))
Expand Down
8 changes: 4 additions & 4 deletions spython/client/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@


def main(args, options, parser):
"""This function serves as a wrapper around the DockerParser,
SingularityParser, DockerWriter, and SingularityParser converters.
We can either save to file if args.outfile is defined, or print
to the console if not.
"""This function serves as a wrapper around the DockerParser,
SingularityParser, DockerWriter, and SingularityParser converters.
We can either save to file if args.outfile is defined, or print
to the console if not.
"""
# We need something to work with
if not args.files:
Expand Down
12 changes: 4 additions & 8 deletions spython/client/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ def main(args, options, parser):


def prepare_client(image):
"""prepare a client to embed in a shell with recipe parsers and writers.
"""
"""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
Expand All @@ -43,8 +42,7 @@ def prepare_client(image):


def ipython(image):
"""give the user an ipython shell
"""
"""give the user an ipython shell"""
client = prepare_client(image) # pylint: disable=unused-variable

try:
Expand All @@ -56,8 +54,7 @@ def ipython(image):


def run_bpython(image):
"""give the user a bpython shell
"""
"""give the user a bpython shell"""
client = prepare_client(image)

try:
Expand All @@ -69,8 +66,7 @@ def run_bpython(image):


def python(image):
"""give the user a python shell
"""
"""give the user a python shell"""
import code

client = prepare_client(image)
Expand Down
38 changes: 19 additions & 19 deletions spython/image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def __repr__(self):

def parse_image_name(self, image):
"""
simply split the uri from the image. Singularity handles
parsing of registry, namespace, image.
Parameters
==========
image: the complete image uri to load (e.g., docker://ubuntu)
simply split the uri from the image. Singularity handles
parsing of registry, namespace, image.

Parameters
==========
image: the complete image uri to load (e.g., docker://ubuntu)

"""
self._image = image
Expand All @@ -37,27 +37,27 @@ def parse_image_name(self, image):
class Image(ImageBase):
def __init__(self, image=None):
"""An image here is an image file or a record.
The user can choose to load the image when starting the client, or
update the main client with an image. The image object is kept
with the main client to make running additional commands easier.
The user can choose to load the image when starting the client, or
update the main client with an image. The image object is kept
with the main client to make running additional commands easier.

Parameters
==========
image: the image uri to parse (required)
Parameters
==========
image: the image uri to parse (required)

"""
super(Image, self).__init__()
self.parse_image_name(image)

def get_hash(self, image=None):
"""return an md5 hash of the file based on a criteria level. This
is intended to give the file a reasonable version. This only is
useful for actual image files.
Parameters
==========
image: the image path to get hash for (first priority). Second
priority is image path saved with image object, if exists.
is intended to give the file a reasonable version. This only is
useful for actual image files.

Parameters
==========
image: the image path to get hash for (first priority). Second
priority is image path saved with image object, if exists.

"""
hasher = hashlib.md5()
Expand Down
22 changes: 11 additions & 11 deletions spython/image/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@


def generate_image_commands():
""" The Image client holds the Singularity image command group, mainly
deprecated commands (image.import) and additional command helpers
that are commonly use but not provided by Singularity
"""The Image client holds the Singularity image command group, mainly
deprecated commands (image.import) and additional command helpers
that are commonly use but not provided by Singularity

The levels of verbosity (debug and quiet) are passed from the main
client via the environment variable MESSAGELEVEL.
The levels of verbosity (debug and quiet) are passed from the main
client via the environment variable MESSAGELEVEL.

These commands are added to Client.image under main/__init__.py to
expose subcommands:
These commands are added to Client.image under main/__init__.py to
expose subcommands:

Client.image.export
Client.image.imprt
Client.image.decompress
Client.image.create
Client.image.export
Client.image.imprt
Client.image.decompress
Client.image.create

"""

Expand Down
12 changes: 6 additions & 6 deletions spython/image/cmd/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
def create(self, image_path, size=1024, sudo=False, singularity_options=None):
"""create will create a a new image

Parameters
==========
image_path: full path to image
size: image sizein MiB, default is 1024MiB
filesystem: supported file systems ext3/ext4 (ext[2/3]: default ext3
singularity_options: a list of options to provide to the singularity client
Parameters
==========
image_path: full path to image
size: image sizein MiB, default is 1024MiB
filesystem: supported file systems ext3/ext4 (ext[2/3]: default ext3
singularity_options: a list of options to provide to the singularity client
"""
from spython.utils import check_install

Expand Down
10 changes: 5 additions & 5 deletions spython/image/cmd/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
def export(self, image_path, tmptar=None):
"""export will export an image, sudo must be used.

Parameters
==========
image_path: full path to image
tmptar: if defined, use custom temporary path for tar export
Parameters
==========

image_path: full path to image
tmptar: if defined, use custom temporary path for tar export

"""
from spython.utils import check_install
Expand Down
12 changes: 6 additions & 6 deletions spython/image/cmd/importcmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
def importcmd(self, image_path, input_source):
"""import will import (stdin) to the image

Parameters
==========
image_path: path to image to import to.
input_source: input source or file
import_type: if not specified, imports whatever function is given
Parameters
==========
image_path: path to image to import to.
input_source: input source or file
import_type: if not specified, imports whatever function is given

"""
from spython.utils import check_install

Expand Down
37 changes: 18 additions & 19 deletions spython/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
class Instance(ImageBase):
def __init__(self, image, start=True, name=None, **kwargs):
"""An instance is an image running as an instance with services.
This class has functions appended under cmd/__init__ and is
instantiated when the user calls Client.

Parameters
==========
image: the Singularity image uri to parse (required)
start: boolean to start the instance (default is True)
name: a name for the instance (will generate RobotName
if not provided)
This class has functions appended under cmd/__init__ and is
instantiated when the user calls Client.

Parameters
==========
image: the Singularity image uri to parse (required)
start: boolean to start the instance (default is True)
name: a name for the instance (will generate RobotName
if not provided)
"""
super(Instance, self).__init__()
self.parse_image_name(image)
Expand All @@ -38,7 +38,7 @@ def __init__(self, image, start=True, name=None, **kwargs):

def generate_name(self, name=None):
"""generate a Robot Name for the instance to use, if the user doesn't
supply one.
supply one.
"""
# If no name provided, use robot name
if name is None:
Expand All @@ -47,27 +47,26 @@ def generate_name(self, name=None):

def parse_image_name(self, image):
"""
simply split the uri from the image. Singularity handles
parsing of registry, namespace, image.
Parameters
==========
image: the complete image uri to load (e.g., docker://ubuntu)
simply split the uri from the image. Singularity handles
parsing of registry, namespace, image.

Parameters
==========
image: the complete image uri to load (e.g., docker://ubuntu)

"""
self._image = image
self.protocol = "instance"

def get_uri(self):
"""return the image uri (instance://) along with it's name
"""
"""return the image uri (instance://) along with it's name"""
return self.__str__()

# Metadata

def _update_metadata(self, kwargs=None):
"""Extract any additional attributes to hold with the instance
from kwargs
from kwargs
"""

# If not given metadata, use instance.list to get it for container
Expand Down
6 changes: 3 additions & 3 deletions spython/instance/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@


def generate_instance_commands():
""" The Instance client holds the Singularity Instance command group
The levels of verbosity (debug and quiet) are passed from the main
client via the environment variable MESSAGELEVEL.
"""The Instance client holds the Singularity Instance command group
The levels of verbosity (debug and quiet) are passed from the main
client via the environment variable MESSAGELEVEL.

"""
from spython.instance import Instance
Expand Down
18 changes: 9 additions & 9 deletions spython/instance/cmd/iutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

def parse_table(table_string, header, remove_rows=1):
"""parse a table to json from a string, where a header is expected by default.
Return a jsonified table.

Parameters
==========
table_string: the string table, ideally with a header
header: header of expected table, must match dimension (number columns)
remove_rows: an integer to indicate a number of rows to remove from top
the default is 1 assuming we don't want the header
Return a jsonified table.

Parameters
==========
table_string: the string table, ideally with a header
header: header of expected table, must match dimension (number columns)
remove_rows: an integer to indicate a number of rows to remove from top
the default is 1 assuming we don't want the header
"""
rows = [x for x in table_string.split("\n") if x]
rows = rows[0 + remove_rows :]
Expand All @@ -37,7 +37,7 @@ def parse_table(table_string, header, remove_rows=1):

def get(self, name, return_json=False, quiet=False, singularity_options=None):
"""get is a list for a single instance. It is assumed to be running,
and we need to look up the PID, etc.
and we need to look up the PID, etc.
"""
from spython.utils import check_install

Expand Down