From fc68aa8e9edbc450cfd29054ca4c59c0f1566582 Mon Sep 17 00:00:00 2001 From: Adam Miller Date: May 19 2017 19:39:17 +0000 Subject: [PATCH 1/2] bump to version 0.0.4 Signed-off-by: Adam Miller --- diff --git a/setup.py b/setup.py index 461fb8d..b407367 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ if sys.version_info[0] == 2: setup( name='flr', - version='0.0.1', + version='0.0.4', description="Fedora Lib Rel-Eng", long_description=long_description, author='Adam Miller', From aa1ae27f77bd6f3b82165a75b6401701f6236a8f Mon Sep 17 00:00:00 2001 From: Adam Miller Date: May 19 2017 19:43:06 +0000 Subject: [PATCH 2/2] add contribution guidelines, fix up cli to comply Signed-off-by: Adam Miller --- diff --git a/README.rst b/README.rst index d36e305..3dcac7d 100644 --- a/README.rst +++ b/README.rst @@ -16,8 +16,8 @@ modules. Also, there are a series of small comand line tools meant to expose the Python API to the user via the command line. These utilities should be small as they are meant to perform effectively "one thing" such that they can easily be -delegated via sudo permissions for `RelEng Automation`. These utilities are -written using `click`. +delegated via sudo permissions for `RelEng Automation`_. These utilities are +written using `click`_. The topmost object namespace in flr is mostly just an indexing logical namespace, with the real work being broken up into submodules targets named @@ -50,6 +50,45 @@ Directory layout of this git repository: - tests - Tests, run with ``runtests.sh`` (uses `pytest`_ for tests) +Contribution Guidelines +======================= + +Below are guidelines that should be followed when submitting code to `flr`_. + +Style +----- + +Code should be `PEP8`_. + +User Experience +--------------- + +Command line utils should use `click`_ and multi-word commands for the command +line utilities that expose the API should be implemented in a similar pattern as +follows. + +.. code-block:: python + + import click + import flr.foo + + @click.group() + def cli(): + pass + + @click.command() + @click.argument('bar') + def some_command(bar): + print (bar) + + cli.add_command(some_command, name="some-command") + + if __name__ == '__main__': + cli() + +The desire is to have all small command-line utilities in `flr`_ have a similar +unified "feel" from an user perspective. + Development Workflow ==================== @@ -134,8 +173,10 @@ In the example below we are releasing the ``0.0.2`` version. The resulting file ``/tmp/flr-0.0.2.tar.gz`` would then be uploaded using the ``Pagure Release Page``. +.. _flr: https://pagure.io/flr .. _pytest: http://pytest.org/ .. _Fedora: https://getfedora.org/ +.. _PEP8: https://www.python.org/dev/peps/pep-0008/ .. _Sphinx Doc: http://www.sphinx-doc.org/en/stable/ .. _Release Engineering: https://docs.pagure.org/releng/ .. _Fedora Release Engineering pagure git repo: https://pagure.io/releng diff --git a/flr-docker b/flr-docker index 6ecf123..55693c8 100755 --- a/flr-docker +++ b/flr-docker @@ -31,17 +31,17 @@ def cli(): @click.option('--daemon', help="Docker daemon URI", default=None) @click.option('--registry', help="Docker registry URI to login to", default=None) @click.option('--username', help="Username to login as to provided registry", default=None) -def remotecopy(srcimg, destimg, daemon, registry, username): +def remote_copy(srcimg, destimg, daemon, registry, username): """ copy an image from a source registry repo to a destination registry repo - Usage: flr-docker remotecopy SRCIMG DESTIMG + Usage: flr-docker remote-copy SRCIMG DESTIMG \b SRCIMG - Source Docker Image URI DESTIMG - Destination Docker Image URI - This utility exposes flr.dkr.remotecopy() to the cli + This utility exposes flr.dkr.remote_copy() to the cli """ if daemon: @@ -49,7 +49,7 @@ def remotecopy(srcimg, destimg, daemon, registry, username): else: clientargs = {} - flr.dkr.remotecopy( + flr.dkr.remote_copy( srcimg, destimg, client_args=clientargs, @@ -59,22 +59,22 @@ def remotecopy(srcimg, destimg, daemon, registry, username): @click.command() @click.argument('imagename') -def removeimage(imagename): +def remove_image(imagename): """ Remove a local docker image - Usage: flr-docker removeimage IMAGENAME + Usage: flr-docker remove-image IMAGENAME \b IMAGENAME - Local Docker Image Name to remove - This utility exposes flr.dkr.removeimage() to the cli + This utility exposes flr.dkr.remove_image() to the cli """ - flr.dkr.removeimage(imagename) + flr.dkr.remove_image(imagename) -cli.add_command(remotecopy) -cli.add_command(removeimage) +cli.add_command(remote_copy, name="remote-copy") +cli.add_command(remove_image, name="remove-image") if __name__ == '__main__': cli() diff --git a/flr/dkr.py b/flr/dkr.py index 83ef3f6..5f8c9b8 100644 --- a/flr/dkr.py +++ b/flr/dkr.py @@ -60,7 +60,7 @@ def split_repo(repo_name): return (image_repo, image_tag) -def remotecopy(src_image, dest_image, client_args={}, registry=None, username=None): +def remote_copy(src_image, dest_image, client_args={}, registry=None, username=None): """ :param src_image: str, source docker image repo uri @@ -96,7 +96,7 @@ def remotecopy(src_image, dest_image, client_args={}, registry=None, username=No ) dc.push(dest_image) -def removeimage(image_name): +def remove_image(image_name): """ :param image_name: str, name of docker image to remove diff --git a/tests/test_docker.py b/tests/test_docker.py index e239529..1c24f3e 100644 --- a/tests/test_docker.py +++ b/tests/test_docker.py @@ -23,9 +23,9 @@ import docker import flr.dkr @mock.patch('docker.Client', spec=docker.Client) -def test_dockerclient_remotecopy(mock_dc): +def test_dockerclient_remote_copy(mock_dc): """ - test case for flr.dkr.remotecopy without login + test case for flr.dkr.remote_copy without login """ src_img = "foo:1" @@ -34,7 +34,7 @@ def test_dockerclient_remotecopy(mock_dc): src_split = flr.dkr.split_repo(src_img) dest_split = flr.dkr.split_repo(dest_img) - flr.dkr.remotecopy(src_img, dest_img) + flr.dkr.remote_copy(src_img, dest_img) assert mock.call().pull(src_split[0], tag=src_split[1]) in mock_dc.mock_calls assert mock.call().tag(src_img, dest_split[0], tag=dest_split[1], force=True) \ @@ -42,9 +42,9 @@ def test_dockerclient_remotecopy(mock_dc): assert mock.call().push(dest_img) in mock_dc.mock_calls @mock.patch('docker.Client', spec=docker.Client) -def test_dockerclient_remotecopy_login(mock_dc): +def test_dockerclient_remote_copy_login(mock_dc): """ - test case for flr.dkr.remotecopy without login + test case for flr.dkr.remote_copy without login """ src_img = "foo:1" @@ -55,7 +55,7 @@ def test_dockerclient_remotecopy_login(mock_dc): src_split = flr.dkr.split_repo(src_img) dest_split = flr.dkr.split_repo(dest_img) - flr.dkr.remotecopy(src_img, dest_img, registry=registry, username=username) + flr.dkr.remote_copy(src_img, dest_img, registry=registry, username=username) assert mock.call().pull(src_split[0], tag=src_split[1]) in mock_dc.mock_calls assert mock.call().tag(src_img, dest_split[0], tag=dest_split[1], force=True) \ @@ -67,14 +67,14 @@ def test_dockerclient_remotecopy_login(mock_dc): in mock_dc.mock_calls @mock.patch('docker.Client', spec=docker.Client) -def test_dockerclient_removeimage(mock_dc): +def test_dockerclient_remove_image(mock_dc): """ - test case for flr.dkr.remotecopy without login + test case for flr.dkr.remove_image """ image_name = "foo:1" - flr.dkr.removeimage(image_name) + flr.dkr.remove_image(image_name) assert mock.call().remove_image(image_name) in mock_dc.mock_calls