Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

[project]
name = "postgresql-charms-single-kernel"
dynamic = ["version"]
description = "Shared and reusable code for PostgreSQL-related charms"
readme = "README.md"
license = "Apache-2.0"
authors = [
{name = "Canonical Data Platform", email = "data-platform@lists.launchpad.net"}
]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: POSIX :: Linux",
]
requires-python = ">=3.8,<4.0"

[dependency-groups]
lib = [
"ops>=2.0.0",
"psycopg2>=2.9.10",
]
format = [
"ruff==0.12.11"
]
lint = [
"codespell==2.4.1"
]
unit = [
"coverage[toml]==7.9.1; python_version > '3.8'",
"pytest>=8.3.5; python_version < '3.9'",
"pytest==8.4.1; python_version >= '3.9'"
]

# Testing tools configuration
[tool.coverage.run]
branch = true

[tool.coverage.report]
show_missing = true
exclude_lines = [
"logger\\.debug"
]

[tool.pytest.ini_options]
minversion = "6.0"
log_cli_level = "INFO"

# Linting tools configuration
[tool.ruff]
# preview and explicit preview are enabled for CPY001
preview = true
target-version = "py38"
src = ["src", "."]
line-length = 99

[tool.ruff.lint]
explicit-preview-rules = true
select = ["A", "E", "W", "F", "C", "N", "D", "I001", "B", "CPY001", "RUF", "S", "SIM", "UP", "TCH"]
extend-ignore = [
"D203",
"D204",
"D213",
"D215",
"D400",
"D404",
"D406",
"D407",
"D408",
"D409",
"D413",
]
# Ignore E501 because using black creates errors with this
# Ignore D107 Missing docstring in __init__
ignore = ["E501", "D107"]

[tool.ruff.lint.per-file-ignores]
"tests/*" = [
"D100", "D101", "D102", "D103", "D104",
# Asserts
"B011",
# Disable security checks for tests
"S",
]

[tool.ruff.lint.flake8-copyright]
# Check for properly formatted copyright header in each file
author = "Canonical Ltd."
notice-rgx = "Copyright\\s\\d{4}([-,]\\d{4})*\\s+"
min-file-size = 1

[tool.ruff.lint.mccabe]
max-complexity = 10

[tool.ruff.lint.pydocstyle]
convention = "google"
3 changes: 3 additions & 0 deletions single_kernel_postgresql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.
"""PostgreSQL Operators Single Kernel."""
26 changes: 26 additions & 0 deletions single_kernel_postgresql/abstract_charm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.
"""Skeleton for the abstract charm."""

from ops.charm import CharmBase

from .config.literals import SYSTEM_USERS, USER
from .utils.postgresql import PostgreSQL


class AbstractPostgreSQLCharm(CharmBase):
"""An abstract PostgreSQL charm."""

def __init__(self, *args):
super().__init__(*args)

self.postgresql = PostgreSQL(
primary_host="localhost",
current_host="localhost",
user=USER,
# The password is hardcoded because this is an abstract charm and
# it meant to be used only in unit tests.
password="test-password", # noqa S106
database="test-database",
system_users=SYSTEM_USERS,
)
22 changes: 22 additions & 0 deletions single_kernel_postgresql/charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.
#
# This file is here only to run unit tests.
type: charm
name: postgresql-single-kernel
title: PostgreSQL Single Kernel Charm
summary: Placeholder charm for unit tests.
description: Placeholder charm for unit tests.

base: ubuntu@24.04
platforms:
amd64:
arm64:

peers:
database-peers:
interface: postgresql_peers

provides:
database:
interface: postgresql_client
3 changes: 3 additions & 0 deletions single_kernel_postgresql/config/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
This module should contain the literals used in the charms (paths, enums, etc).
"""

# Relations.
PEER = "database-peers"

# Users.
BACKUP_USER = "backup"
MONITORING_USER = "monitoring"
Expand Down
Loading