Skip to content

Commit

Permalink
Tweaks to the README, setup.py, etc, for release. (#305)
Browse files Browse the repository at this point in the history
* Tweaks to the README, setup.py, etc, for release.
  • Loading branch information
chipaca authored May 29, 2020
1 parent 63e7d9e commit 81e5f36
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 28 deletions.
27 changes: 12 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,19 @@ a particular Python file. It could be anything that makes sense to your project,
but let's assume this is `src/charm.py`. This file must be executable (and it
must have the appropriate shebang line).

This file must be symlinked from `dispatch` (supported by Juju 2.8; otherwise
from `hooks/install` and `hooks/upgrade-charm`, and `hooks/start` if it is a k8s
charm).

You also need the usual `metadata.yaml` and `config.yaml` files, and any Python
dependencies (maybe using some kind of virtualenv). In other words, your project
You need the usual `metadata.yaml` and (probably) `config.yaml` files, and a
`requirements.txt` for any Python dependencies. In other words, your project
might look like this:

```
.
my-charm
├── config.yaml
├── metadata.yaml
├── env/
│ └── # ... your Python dependencies, including the operator framework itself
├── src/
│ └── charm.py
└── dispatch -> src/charm.py
├── requirements.txt
└── src/
└── charm.py
```

> 🛈 once `charmcraft build` works the layout will get simpler!
`src/charm.py` here is the entry point to your charm code. At a minimum, it
needs to define a subclass of `CharmBase` and pass that into the framework's
`main` function:
Expand All @@ -83,9 +75,14 @@ if __name__ == "__main__":
That should be enough for you to be able to run

```
$ juju deploy .
$ charmcraft build
Done, charm left in 'my-charm.charm'
$ juju deploy my-charm.charm
```

> 🛈 More information on [`charmcraft`](https://pypi.org/project/charmcraft/) can
> also be found on its [github page](https://github.com/canonical/charmcraft).
Happy charming!

## Testing your charms
Expand Down
2 changes: 2 additions & 0 deletions ops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@

"""The Operator Framework."""

__version__ = '0.6.0'

# Import here the bare minimum to break the circular import between modules
from . import charm # NOQA
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PyYAML
-e . # i.e. get them from setup.py
56 changes: 44 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,60 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from setuptools import setup
import ast
from setuptools import setup, find_packages


def _read_me() -> str:
with open("README.md", "rt", encoding="utf8") as fh:
readme = fh.read()
return readme


def _get_version() -> str:
# ops.__init__ needs to pull in ops.charm to work around a circular
# import so we can't import it here as that pulls in yaml which isn't
# necessarily there yet.
version = 'unknown'
with open("ops/__init__.py", "rt", encoding="utf8") as fh:
source = fh.read()
code = ast.parse(source)
for node in code.body:
if isinstance(node, ast.Assign):
targets = [i.id for i in node.targets]
if '__version__' in targets:
if isinstance(node.value, ast.Str):
# Python < 3.8
version = node.value.s
else:
version = node.value.value
break
return version

with open("README.md", "r") as fh:
long_description = fh.read()

setup(
name="ops",
version="0.0.1",
version=_get_version(),
description="The Python library behind great charms",
long_description=long_description,
long_description=_read_me(),
long_description_content_type="text/markdown",
license="Apache-2.0",
url="https://github.com/canonical/operator",
packages=["ops"],
author="The Charmcraft team at Canonical Ltd.",
author_email="[email protected]",
packages=find_packages(include=('ops', 'ops.*')),
classifiers=[
"Development Status :: 4 - Beta",

"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",

"License :: OSI Approved :: Apache Software License",
"Development Status :: 4 - Beta",

"Intended Audience :: Developers",
"Intended Audience :: System Administrators",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX :: Linux",
# include Windows once we're running tests there also
# "Operating System :: Microsoft :: Windows",
],
python_requires='>=3.5',
install_requires=["PyYAML"],
)
25 changes: 25 additions & 0 deletions test/test_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import autopep8
from flake8.api.legacy import get_style_guide

import ops


def get_python_filepaths():
"""Helper to retrieve paths of Python files."""
Expand Down Expand Up @@ -100,6 +102,29 @@ def test_ensure_copyright(self):
if issues:
self.fail("Please add copyright headers to the following files:\n" + "\n".join(issues))

def _run_setup(self, *args):
proc = subprocess.run(
(sys.executable, 'setup.py') + args,
stdout=subprocess.PIPE,
check=True)
return proc.stdout.strip().decode("utf8")

def test_setup_version(self):
setup_version = self._run_setup('--version')

self.assertEqual(setup_version, ops.__version__)

def test_setup_description(self):
with open("README.md", "rt", encoding="utf8") as fh:
disk_readme = fh.read().strip()

setup_readme = self._run_setup('--long-description')

self.assertEqual(setup_readme, disk_readme)

def test_check(self):
self._run_setup('check', '--strict')


class ImportersTestCase(unittest.TestCase):

Expand Down

0 comments on commit 81e5f36

Please sign in to comment.