Skip to main content
Sultan logo https://badge.fury.io/py/sower.png https://travis-ci.org/aeroxis/sower.svg?branch=master MIT License

Sower

Sower “plants” directories, files and symlinks on your filesystem based on a contract you tell it.

How to Install

$ pip install sower

Why Do You Need Sower?

The Problem

Have you ever been in a situation where you needed to create a large set of files, that may span multiple subdirectories? You might need to do this for testing, especially if your application that you’re testing is supposed to be tested for how it manages a set of files based on their directory structure.

The Solution - Part 1

Sower is the solution for this problem! You simply define a contract in YAML or JSON like the following:

YAML (sower-contract.yml)

JSON (sower-contract.json)

---
sower:
    plan:
        bin:
            start.sh:
                type: file
                content: "echo 'Starting foobar'"
            stop.sh:
                type: file
                content: "echo 'Stopping foobar'"
        data:
            test-data.tar.gz:
                type: file
                content: "!random!"
                size: 1Mb
        src:
            foobar:
                __init__.py:
                    type: file
                    content: "# just a comment"
                main.py:
                    type: file
                    content: >
                        import os\n
                        print('Foo Bar: %s' % os.path.abspath('.'))\n\n
                link_main.py:
                    type: symlink
                    target: ../foobar/main.py
{
    "sower": {
        "plan": {
            "bin": {
                "start.sh": {
                    "type": "file",
                    "content": "echo'Startingfoobar'"
                },
                "stop.sh": {
                    "type": "file",
                    "content": "echo'Stoppingfoobar'"
                }
            },
            "data": {
                "test-data.tar.gz": {
                    "type": "file",
                    "content": "!random!",
                    "size": "1Mb"
                }
            },
            "src": {
                "foobar": {
                    "__init__.py": {
                        "type": "file",
                        "content": "#justacomment"
                    },
                    "main.py": {
                        "type": "file",
                        "content": "importos\nprint('FooBar: %s'%os.path.abspath('.')\n\n
                    },
                    "link_main.py": {
                        "type": "symlink",
                        "target": "../foobar/main.py"
                    }
                }
            }
        }
    }
}

Save the Contract to disk (choose either YAML or JSON listing from above). Now we simply tell Sower where to create these files, and the path to this contract.

If we want to create files based on this contract on /home/davydany/foobar, we would do the following:

If you chose the YAML, run the following: .. code:: bash

$ sower sow /home/davydany/foobar /tmp/sower-contract.yml

If you chose the JSON, run the following: .. code:: bash

$ sower sow /home/davydany/foobar /tmp/sower-contract.json

This would create the following structure:

/home/davydany/foobar
├── bin
│   ├── start.sh
│   └── stop.sh
├── data
│   └── test-data.tar.gz
└── src
    └── foobar
        ├── __init__.py
        ├── link_main.py -> /tmp/foobar/src/foobar/main.py
        └── main.py

4 directories, 6 files

The Solution - Part 2

Now, suppose you need to do this in your integration tests that use python’s unittest. You can still leverage this with the Sower API.

You would have something like this in your test’s setUp method.

import tempfile
import unittest
from sower.farm import perform_sow

class TestMyApp(unittest.TestCase):

    def setUp(self):

        self.root = tempfile.mkdtemp('_farmer_test')
        self.contract = """

        ---
        sower:
            plan:
                bin:
                    start.sh:
                        type: file
                        content: "echo 'Starting foobar'"
                    stop.sh:
                        type: file
                        content: "echo 'Stopping foobar'"
                data:
                    test-data.tar.gz:
                        type: file
                        content: "!random!"
                        size: 1Mb
                src:
                    foobar:
                        __init__.py:
                            type: file
                            content: "# just a comment"
                        main.py:
                            type: file
                            content: >
                                import os\n
                                print('Foo Bar: %s' % os.path.abspath('.'))\n\n
                        link_main.py:
                            type: symlink
                            target: ../foobar/main.py
        """
        perform_sow(self.contract, self.root)

Metadata

Release files for sower 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for sower 1.1.1
File Interpreter ABI Platform
sower-1.1.1-py3-none-any.whl Python 3 none any Details
sower-1.1.1-py2-none-any.whl Python 2 none any Details

Total release size: 21.3 kB

Release files / sower-1.1.1-py3-none-any.whl

Download URL sower-1.1.1-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ea16fd396e62cbfb51782c0d2a9f31faeb2da8223b5282c6e352b1e8b68091c
BLAKE2b-256 checksum
How to use checksums
64970c7ccf94b9daa2f17358820f1aa67c842509a3e90e17e4906a992b4da091
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / sower-1.1.1-py2-none-any.whl

Download URL sower-1.1.1-py2-none-any.whl
Size 10.6 kB
Tags Python 2
SHA-256 checksum
How to use checksums
eb637c342b04b0dd9256be6e8aef22bcdee9cdb704d9a3518a9a60ec4ec2033c
BLAKE2b-256 checksum
How to use checksums
42f9ac71a9b56ba9bedee8e262d579bf566ecbf7541e37bbaae7729efa2712e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

1 release file

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page