Skip to content

Commit

Permalink
#119: Refactored pkg_resources usage to importlib.resources (#419)
Browse files Browse the repository at this point in the history
* #119: Refactored pkg_resources usage to importlib.resources
* [run all tests]
  • Loading branch information
ckunki authored Oct 24, 2024
1 parent df7a272 commit fcf6b1f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_db_versions_all_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
echo "All tests activated"
exit 0
else
echo "Fail, because not all tests are deactivated"
echo "Fail, because not all tests are activated"
exit 1
fi
env:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test_python_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
exasol_version:
- "default"
python_version:
- 3.8
- 3.9
- "3.9"
- "3.10"
name: Run tests with Python ${{ matrix.python_version }} and Exasol ${{ matrix.exasol_version }}
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changes

* [3.3.0](changes_3.3.0.md)
* [3.2.0](changes_3.2.0.md)
* [3.1.0](changes_3.1.0.md)
* [3.0.0](changes_3.0.0.md)
Expand Down Expand Up @@ -34,6 +35,7 @@
hidden:
---
changes_3.2.0
changes_3.3.0
changes_3.1.0
changes_3.0.0
changes_2.1.0
Expand Down
10 changes: 10 additions & 0 deletions doc/changes/changes_3.3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Integration-Test-Docker-Environment 3.3.0, released 2024-??-??

Code name:

## Summary

## Refactorings

* #119: Refactored `pkg_resources` usage to `importlib.resources`
* #420: Added file `py.typed` to enable mypy to find project specific types
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import luigi
import netaddr
import pkg_resources
import importlib_resources

from docker.models.containers import Container
from docker.transport import unixconn

Expand Down Expand Up @@ -180,12 +181,17 @@ def _remove_container(self, container_name: str):
def register_certificates(self, test_container: Container):
if self.certificate_volume_name is not None:
script_name = "install_root_certificate.sh"
script_str = pkg_resources.resource_string(
PACKAGE_NAME,
f"certificate_resources/{script_name}") # type: bytes

script = (
importlib_resources.files(PACKAGE_NAME)
/ "certificate_resources"
/ script_name
)
script_location_in_container = f"scripts/{script_name}"
copy_script_to_container(script_str.decode("UTF-8"), script_location_in_container, test_container)
copy_script_to_container(
script.read_text(),
script_location_in_container,
test_container,
)

exit_code, output = test_container.exec_run(f"bash {script_location_in_container}")
if exit_code != 0:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import humanfriendly
import luigi
import netaddr
import pkg_resources
import importlib_resources

from docker.models.containers import Container
from docker.models.volumes import Volume
from docker.client import DockerClient
Expand Down Expand Up @@ -304,18 +305,22 @@ def _prepare_volume(
)
return volume, container

def _db_file(self, filename: str) -> str:
return (
importlib_resources.files(PACKAGE_NAME)
/ self.docker_db_config_resource_name
/ filename
)

def _upload_init_db_files(
self,
container: Container,
db_private_network: str,
authorized_keys: str,
):
copy = DockerContainerCopy(container)
init_db_script_str = pkg_resources.resource_string(
PACKAGE_NAME,
f"{self.docker_db_config_resource_name}/init_db.sh") # type: bytes

copy.add_string_to_file("init_db.sh", init_db_script_str.decode("utf-8"))
init_script = self._db_file("init_db.sh")
copy.add_string_to_file("init_db.sh", init_script.read_text())
self._add_exa_conf(copy, db_private_network, authorized_keys)
copy.copy("/")

Expand All @@ -330,10 +335,8 @@ def _add_exa_conf(
"""
certificate_dir = CERTIFICATES_MOUNT_DIR if self.certificate_volume_name is not None \
else CERTIFICATES_DEFAULT_DIR
template_str = pkg_resources.resource_string(
PACKAGE_NAME,
f"{self.docker_db_config_resource_name}/EXAConf") # type: bytes
template = Template(template_str.decode("utf-8"))
template_file = self._db_file("EXAConf")
template = Template(template_file.read_text())
additional_db_parameter_str = " ".join(self.additional_db_parameter)
rendered_template = template.render(private_network=db_private_network,
db_version=str(self.db_version),
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "exasol-integration-test-docker-environment"
packages = [
{ include = "exasol_integration_test_docker_environment" },
]
version = "3.2.0"
version = "3.3.0"
description = "Integration Test Docker Environment for Exasol"

license = "MIT"
Expand Down Expand Up @@ -44,7 +44,7 @@ fabric = "^3.0.1"
portalocker = "^2.7.0"
exasol-error-reporting = "^0.4.0"
# The current combination of dependencies for ITDE and Luigi is not compatible with projects that run on Python 3.8.
# The latest version of docutils, version 0.21.1, is required to run on Python 3.9 or higher.
# The latest version of docutils, version 0.21.1, is required to run on Python 3.9 or higher.
# As a temporary fix, until support for Python 3.8 is dropped (which is estimated to be around 6 months),
# we are explicitly requiring a version of docutils that is less than or equal to 0.20.1 in ITDE.
# Once support for Python 3.8 is dropped, this dependency can be removed as it is only needed as a transitive dependency.
Expand Down

0 comments on commit fcf6b1f

Please sign in to comment.