Skip to content

Commit

Permalink
Merge remote-tracking branch 'source/main' into import-ops-scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Sep 27, 2024
2 parents 05af34f + 8d26b14 commit 0a2b124
Show file tree
Hide file tree
Showing 80 changed files with 15,183 additions and 0 deletions.
60 changes: 60 additions & 0 deletions ops-scenario/.github/workflows/build_wheels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build

on:
push:
branches:
- main

jobs:
build_wheel:
name: Build wheel on ubuntu (where else???)
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v3

- name: Install build
run: pip install build

- name: Build wheel
run: python -m build

- uses: actions/upload-artifact@v3
with:
path: ./dist/*.whl

- name: Get the version
id: get_version
run: echo "VERSION=$(sed -n 's/^ *version.*=.*"\([^"]*\)".*/\1/p' pyproject.toml)" >> $GITHUB_OUTPUT

- name: release
uses: actions/create-release@v1
id: create_release
with:
draft: false
prerelease: false
tag_name: ${{ steps.get_version.outputs.VERSION }}
release_name: ${{ steps.get_version.outputs.VERSION }}

env:
GITHUB_TOKEN: ${{ github.token }}

# - name: Setup upterm session
# uses: lhotari/action-upterm@v1

- name: upload wheel
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/ops_scenario-${{ steps.get_version.outputs.VERSION }}-py3-none-any.whl
asset_name: ops_scenario-${{ steps.get_version.outputs.VERSION }}-py3-none-any.whl
asset_content_type: application/wheel

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
45 changes: 45 additions & 0 deletions ops-scenario/.github/workflows/quality_checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Tests

on:
pull_request:
branches:
- main
- 7.0

jobs:
linting:
name: Linting
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: python -m pip install tox
- name: Run linter
run: tox -vve lint
- name: Run static checks
run: tox -vve static


unit-test:
name: Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: python -m pip install tox
- name: Run unit tests
run: tox -vve unit
15 changes: 15 additions & 0 deletions ops-scenario/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
venv/
.venv/
build/
docs/_build/
*.charm
.tox/
.coverage
__pycache__/
*.py[cod]
.idea
*.egg-info
dist/
*.pytest_cache
htmlcov/
.vscode
77 changes: 77 additions & 0 deletions ops-scenario/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
files: ^scenario/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-merge-conflict
- id: check-yaml
- id: check-toml
- id: debug-statements
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.1.0
hooks:
- id: add-trailing-comma
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: ["--py37-plus"]
exclude: "^(tests/demo_pkg_inline/build.py)$"
- id: pyupgrade
files: "^(tests/demo_pkg_inline/build.py)$"
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
# Run the Ruff linter.
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.1.2
hooks:
# Run the Ruff linter.
- id: ruff
# Run the Ruff formatter.
- id: ruff-format
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.3]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-backticks
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.3.0"
hooks:
- id: tox-ini-fmt
args: ["-p", "fix"]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.7.1"
hooks:
- id: prettier
additional_dependencies:
- [email protected]
- "@prettier/[email protected]"
args: ["--print-width=120", "--prose-wrap=always"]
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.33.0
hooks:
- id: markdownlint
- repo: local
hooks:
- id: changelogs-rst
name: Changelog filenames
language: fail
entry: "changelog files must be named ####.(feature|bugfix|doc|removal|misc).rst"
exclude: ^docs/changelog/(\d+\.(feature|bugfix|doc|removal|misc).rst|template.jinja2)
files: ^docs/changelog/
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
1 change: 1 addition & 0 deletions ops-scenario/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @pietropasotti
51 changes: 51 additions & 0 deletions ops-scenario/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Contributing

![GitHub License](https://img.shields.io/github/license/canonical/ops-scenario)
![GitHub Commit Activity](https://img.shields.io/github/commit-activity/y/canonical/ops-scenario)
![GitHub Lines of Code](https://img.shields.io/tokei/lines/github/canonical/ops-scenario)
![GitHub Issues](https://img.shields.io/github/issues/canonical/ops-scenario)
![GitHub PRs](https://img.shields.io/github/issues-pr/canonical/ops-scenario)
![GitHub Contributors](https://img.shields.io/github/contributors/canonical/ops-scenario)
![GitHub Watchers](https://img.shields.io/github/watchers/canonical/ops-scenario?style=social)

This documents explains the processes and practices recommended for contributing enhancements to this project.

- Generally, before developing enhancements to this project, you should consider [opening an issue](https://github.com/canonical/ops-scenario/issues) explaining your use case.
- If you would like to chat with us about your use-cases or proposed implementation, you can reach us at [Canonical Mattermost public channel](https://chat.charmhub.io/charmhub/channels/charm-dev) or [Discourse](https://discourse.charmhub.io/).
- Familiarising yourself with the [Charmed Operator Framework](https://juju.is/docs/sdk) library will help you a lot when working on new features or bug fixes.
- All enhancements require review before being merged. Code review typically examines:
- code quality
- test coverage
- user experience
- When evaluating design decisions, we optimize for the following personas, in descending order of priority:
- charm authors and maintainers
- the contributors to this codebase
- juju developers
- Please help us out in ensuring easy to review branches by rebasing your pull request branch onto the `main` branch. This also avoids merge commits and creates a linear Git commit history.

## Notable design decisions

- The `State` object is immutable from the perspective of the test writer.
At the moment there is some hackery here and there (`object.__setattr__`...) to bypass the read-only dataclass for when the charm code mutates the state; at some point it would be nice to refactor the code to make that unnecessary.

- At the moment the mocking operates at the level of `ops.ModelBackend`-mediated hook tool calls. `ModelBackend` would `Popen` hook tool calls, but `Scenario` patches the methods that would call `Popen`, which is therefore never called. Instead, values are returned according to the `State`. We could consider allowing to operate in increasing levels of stricter confinement:
- Actually generate hook tool scripts that read/write from/to `State`, making patching `ModelBackend` unnecessary.
- On top of that, run the whole simulation in a container.

## Developing

To set up the dependencies you can run:
`pip install . ; pip uninstall ops-scenario`

We recommend using the provided `pre-commit` config. For how to set up git pre-commit: [see here](https://pre-commit.com/).
If you dislike that, you can always manually remember to `tox -e lint` before you push.

### Testing
```shell
tox -e fmt # auto-fix your code as much as possible, including formatting and linting
tox -e lint # code style
tox -e unit # unit tests
tox -e lint-tests # lint testing code
tox # runs 'lint', 'lint-tests' and 'unit' environments
```

Loading

0 comments on commit 0a2b124

Please sign in to comment.