Skip to content

Commit

Permalink
Update supported python and postgres versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ettanany committed Jun 17, 2024
1 parent d28945a commit fa116a7
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
strategy:
max-parallel: 5
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- id: checkout-code
Expand Down
18 changes: 9 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Requirements
============

PGHoard can backup and restore PostgreSQL versions 9.6 and above, but is
only tested and actively developed with version 10 and above.
only tested and actively developed with version 12 and above.

The daemon is implemented in Python and is tested and developed with version
3.8 and above. The following Python modules are required:
Expand Down Expand Up @@ -128,35 +128,35 @@ Vagrant
=======

The Vagrantfile can be used to setup a vagrant development environment. The vagrant environment has
python 3.8, 3.9 and 3.10 virtual environments and installations of postgresql 10, 11 and 12, 13 and 14.
python 3.8, 3.9, 3.10, 3.11 and 3.12 virtual environments and installations of postgresql 12, 13, 14, 15 and 16.

By default vagrant up will start a Virtualbox environment. The Vagrantfile will also work for libvirt, just prefix
``VAGRANT_DEFAULT_PROVIDER=libvirt`` to the ``vagrant up`` command.

Any combination of Python (3.8, 3.9 and 3.10) and Postgresql (10, 11, 12, 13 and 14)
Any combination of Python (3.8, 3.9, 3.10, 3.11 and 3.12) and Postgresql (12, 13, 14, 15 and 16)

Bring up vagrant instance and connect via ssh::

vagrant up
vagrant ssh
vagrant@ubuntu2004:~$ cd /vagrant

Test with Python 3.8 and Postgresql 11::
Test with Python 3.8 and Postgresql 12::

vagrant@ubuntu2004:~$ source ~/venv3.8/bin/activate
vagrant@ubuntu2004:~$ PG_VERSION=11 make unittest
vagrant@ubuntu2004:~$ PG_VERSION=12 make unittest
vagrant@ubuntu2004:~$ deactivate

Test with Python 3.9 and Postgresql 12::
Test with Python 3.9 and Postgresql 13::

vagrant@ubuntu2004:~$ source ~/venv3.9/bin/activate
vagrant@ubuntu2004:~$ PG_VERSION=12 make unittest
vagrant@ubuntu2004:~$ PG_VERSION=13 make unittest
vagrant@ubuntu2004:~$ deactivate

Test with Python 3.10 and Postgresql 13::
Test with Python 3.10 and Postgresql 14::

vagrant@ubuntu2004:~$ source ~/venv3.10/bin/activate
vagrant@ubuntu2004:~$ PG_VERSION=13 make unittest
vagrant@ubuntu2004:~$ PG_VERSION=14 make unittest
vagrant@ubuntu2004:~$ deactivate

And so on
Expand Down
10 changes: 5 additions & 5 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Vagrant.configure("2") do |config|
sed -i "s/^#start_conf.*/start_conf='manual'/g" /etc/postgresql-common/createcluster.conf
sed -i "s/^#create_main_cluster.*/create_main_cluster=false/g" /etc/postgresql-common/createcluster.conf
apt-get install -y python{3.8,3.9,3.10} python{3.8,3.9,3.10}-dev python{3.8,3.9,3.10}-venv
apt-get install -y postgresql-{11,12,13,14,15,16} postgresql-server-dev-{11,12,13,14,15,16}
apt-get install -y python{3.8,3.9,3.10,3.11,3.12} python{3.8,3.9,3.10,3.11,3.12}-dev python{3.8,3.9,3.10,3.11,3.12}-venv
apt-get install -y postgresql-{11,12,13,14,15,16} postgresql-server-dev-{12,13,14,15,16}
username="$(< /dev/urandom tr -dc a-z | head -c${1:-32};echo;)"
password=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;)
Expand Down Expand Up @@ -68,13 +68,13 @@ Vagrant.configure("2") do |config|
config.vm.provision "shell", inline: $script, privileged: true

$script = <<-SCRIPT
versions=(3.8 3.9 3.10)
versions=(3.8 3.9 3.10 3.11 3.12)
for version in "${versions[@]}"; do
python${version} -m venv venv${version}
source ~/venv${version}/bin/activate
pip install --upgrade pip
pip install -r /vagrant/requirements.txt
pip install --upgrade -r /vagrant/requirements.dev.txt
pip install "/vagrant/."
pip install --upgrade "/vagrant/.[dev]"
done
SCRIPT
config.vm.provision "shell", inline: $script, privileged: false
Expand Down
16 changes: 8 additions & 8 deletions docs/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ Vagrant
=======

The Vagrantfile can be used to setup a vagrant development environment. The vagrant environment has
python 3.8, 3.9 and 3.10 virtual environments and installations of postgresql 10, 11 and 12, 13 and 14.
python 3.8, 3.9, 3.10, 3.11 and 3.12 virtual environments and installations of postgresql 12, 13, 14, 15 and 16.

By default vagrant up will start a Virtualbox environment. The Vagrantfile will also work for libvirt, just prefix
``VAGRANT_DEFAULT_PROVIDER=libvirt`` to the ``vagrant up`` command.

Any combination of Python (3.8, 3.9 and 3.10) and Postgresql (10, 11, 12, 13 and 14)
Any combination of Python (3.8, 3.9, 3.10, 3.11 and 3.12) and Postgresql (12, 13, 14, 15 and 16)

Bring up vagrant instance and connect via ssh::

vagrant up
vagrant ssh
vagrant@ubuntu2004:~$ cd /vagrant

Test with Python 3.8 and Postgresql 11::
Test with Python 3.8 and Postgresql 12::

vagrant@ubuntu2004:~$ source ~/venv3.8/bin/activate
vagrant@ubuntu2004:~$ PG_VERSION=11 make unittest
vagrant@ubuntu2004:~$ PG_VERSION=12 make unittest
vagrant@ubuntu2004:~$ deactivate

Test with Python 3.9 and Postgresql 12::
Test with Python 3.9 and Postgresql 13::

vagrant@ubuntu2004:~$ source ~/venv3.9/bin/activate
vagrant@ubuntu2004:~$ PG_VERSION=12 make unittest
vagrant@ubuntu2004:~$ PG_VERSION=13 make unittest
vagrant@ubuntu2004:~$ deactivate

Test with Python 3.10 and Postgresql 13::
Test with Python 3.10 and Postgresql 14::

vagrant@ubuntu2004:~$ source ~/venv3.10/bin/activate
vagrant@ubuntu2004:~$ PG_VERSION=13 make unittest
vagrant@ubuntu2004:~$ PG_VERSION=14 make unittest
vagrant@ubuntu2004:~$ deactivate

And so on
Expand Down
4 changes: 2 additions & 2 deletions pghoard/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import time
from contextlib import suppress
from dataclasses import dataclass, field
from distutils.version import LooseVersion
from pathlib import Path
from queue import Queue
from threading import Thread
from typing import (TYPE_CHECKING, Any, BinaryIO, Callable, Dict, Final, Optional, Protocol, Tuple, cast)

from packaging.version import Version
from pydantic import BaseModel, Field
from rohmu import IO_BLOCK_SIZE, BaseTransfer, rohmufile
from rohmu.errors import Error, InvalidConfigurationError
Expand Down Expand Up @@ -415,7 +415,7 @@ def extract_pghoard_delta_metadata(fileobj: FileLike) -> Dict[str, Any]:


def get_pg_wal_directory(config):
if LooseVersion(config["pg_data_directory_version"]) >= "10":
if Version(config["pg_data_directory_version"]).major >= 10:
return os.path.join(config["pg_data_directory"], "pg_wal")
return os.path.join(config["pg_data_directory"], "pg_xlog")

Expand Down
14 changes: 7 additions & 7 deletions pghoard/restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
import uuid
# ignore pylint/distutils issue, https://github.com/PyCQA/pylint/issues/73
from dataclasses import dataclass, field
from distutils.version import \
LooseVersion # pylint: disable=no-name-in-module,import-error
from packaging.version import Version
from threading import RLock
from typing import Any, Dict, List, Optional, Set, Union

Expand Down Expand Up @@ -115,12 +114,13 @@ def create_recovery_conf(
"%f",
]
with open(os.path.join(dirpath, "PG_VERSION"), "r") as fp:
pg_version = LooseVersion(fp.read().strip())
v = Version(fp.read().strip())
pg_version = v.major if v.major >= 10 else float(f"{v.major}.{v.minor}")

trigger_file_setting = None
if pg_version < "12":
if pg_version < 12:
trigger_file_setting = "trigger_file"
elif pg_version < "16": # PG 16 has removed `promote_trigger_file` config param.
elif pg_version < 16: # PG 16 has removed `promote_trigger_file` config param.
trigger_file_setting = "promote_trigger_file"

lines = [
Expand All @@ -132,7 +132,7 @@ def create_recovery_conf(
if trigger_file_setting:
lines.append("{} = {}".format(trigger_file_setting, adapt("trigger_file")))

use_recovery_conf = (pg_version < "12") # no more recovery.conf in PG >= 12
use_recovery_conf = (pg_version < 12) # no more recovery.conf in PG >= 12
if not restore_to_primary:
if use_recovery_conf:
lines.append("standby_mode = 'on'")
Expand All @@ -145,7 +145,7 @@ def create_recovery_conf(
if recovery_end_command:
lines.append("recovery_end_command = {}".format(adapt(recovery_end_command)))
if recovery_target_action:
if pg_version >= "9.5":
if pg_version >= 9.5:
lines.append("recovery_target_action = '{}'".format(recovery_target_action))
elif recovery_target_action == "promote":
pass # default action
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ classifiers=[
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Database :: Database Engines/Servers",
"Topic :: Software Development :: Libraries",
]
Expand Down
4 changes: 2 additions & 2 deletions test/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import logging
import os
# pylint: disable=attribute-defined-outside-init
from distutils.version import LooseVersion
from shutil import rmtree
from tempfile import mkdtemp

import psycopg2.extras
from packaging.version import Version

from pghoard.config import find_pg_binary, set_and_check_config_defaults

Expand Down Expand Up @@ -84,7 +84,7 @@ def config_template(self, override=None):
"json_state_file_path": os.path.join(self.temp_dir, "state.json"),
"pg_basebackup_path": os.path.join(bindir, "pg_basebackup"),
}
if LooseVersion(ver) >= "10":
if Version(ver).major >= 10:
config["backup_sites"][self.test_site]["pg_receivexlog_path"] = os.path.join(bindir, "pg_receivewal")
if override:
all_site_overrides = override.pop("backup_sites", None)
Expand Down
6 changes: 3 additions & 3 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import time
from contextlib import suppress
from dataclasses import dataclass
from distutils.version import LooseVersion
from pathlib import Path
from typing import Callable, Dict, Iterator, Optional, Sequence, Union
from unittest import SkipTest

import psycopg2
import pytest
from packaging.version import Version
from py import path as py_path # pylint: disable=no-name-in-module
from rohmu.snappyfile import snappy

Expand All @@ -35,7 +35,7 @@

logutil.configure_logging()

DEFAULT_PG_VERSIONS = ["16", "15", "14", "13", "12", "11", "10"]
DEFAULT_PG_VERSIONS = ["16", "15", "14", "13", "12"]


def port_is_listening(hostname: str, port: int, timeout: float = 0.5) -> bool:
Expand Down Expand Up @@ -255,7 +255,7 @@ def fixture_recovery_db(pg_version: str) -> Iterator[PGTester]:
"recovery_target_timeline = 'latest'",
"restore_command = 'false'",
]
if LooseVersion(pg.pgver) >= "12":
if Version(pg.pgver).major >= 12:
with open(os.path.join(pg.pgdata, "standby.signal"), "w") as fp:
pass

Expand Down
4 changes: 2 additions & 2 deletions test/test_webserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
import threading
import time
from collections import deque
from distutils.version import LooseVersion
from http.client import HTTPConnection
from queue import Queue
from unittest import mock

import psycopg2
import pytest
from packaging.version import Version
from rohmu.encryptor import Encryptor

from pghoard import postgres_command, wal
Expand Down Expand Up @@ -314,7 +314,7 @@ def write_dummy_wal(inc):
"recovery_target_timeline = 'latest'",
"restore_command = 'false'",
]
if LooseVersion(db.pgver) >= "12":
if Version(db.pgver).major >= 12:
with open(os.path.join(db.pgdata, "standby.signal"), "w") as fp:
pass

Expand Down

0 comments on commit fa116a7

Please sign in to comment.