diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c80f5f7..cdabc6d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ name: unit tests -on: [push] +on: [push, pull_request] jobs: test: runs-on: ${{ matrix.os }} diff --git a/.github/workflows/docker-in-ci.yml b/.github/workflows/docker-in-ci.yml index 6154020..c6f66c6 100644 --- a/.github/workflows/docker-in-ci.yml +++ b/.github/workflows/docker-in-ci.yml @@ -2,6 +2,8 @@ name: docker on: pull_request: + branches: + - main push: branches: - main @@ -11,18 +13,18 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Build docker basic image run: | - docker build -t abcd-graph . + docker build --pull -t abcd-graph . - name: Inspect basic docker image run: | docker image inspect abcd-graph - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@0.31.0 + uses: aquasecurity/trivy-action@v0.36.0 with: image-ref: 'abcd-graph' format: 'table' @@ -41,18 +43,18 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v7 - name: Build docker full image run: | - docker build -t abcd-graph-full --build-arg INSTALL_TYPE=all . + docker build --pull -t abcd-graph-full --build-arg INSTALL_TYPE=all . - name: Inspect full docker image run: | docker image inspect abcd-graph-full - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@0.31.0 + uses: aquasecurity/trivy-action@v0.36.0 with: image-ref: 'abcd-graph-full' format: 'table' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b403c4..8cac50e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,7 +27,7 @@ repos: - id: flake8 args: [ --max-line-length, "120" ] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v2.3.1 hooks: - id: mypy args: [ --config-file, pyproject.toml ] diff --git a/Dockerfile b/Dockerfile index 566f62c..257d723 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,10 @@ FROM python:3.12-alpine AS build +# Upgrade apk package repo +RUN apk update && apk upgrade --no-cache + # Install build tools + curl -RUN apk add --no-cache \ +RUN apk add --no-cache --upgrade \ bash \ curl \ libffi-dev \ diff --git a/src/abcd_graph/callbacks/visualizer.py b/src/abcd_graph/callbacks/visualizer.py index b503617..03772b0 100644 --- a/src/abcd_graph/callbacks/visualizer.py +++ b/src/abcd_graph/callbacks/visualizer.py @@ -50,7 +50,7 @@ def after_build(self, graph: GraphImpl, context: BuildContext, exporter: GraphEx @require("matplotlib") def draw_community_cdf(self) -> None: - import matplotlib.pyplot as plt # type: ignore[import] + import matplotlib.pyplot as plt # type: ignore[import-not-found] assert self._graph is not None @@ -104,7 +104,7 @@ def draw_communities(self) -> None: if self._model_used is not None and self._model_used.__name__ != "configuration_model": raise NotImplementedError("Drawing communities is only supported for the configuration model") - import networkx as nx # type: ignore[import] + import networkx as nx from matplotlib import pyplot as plt assert self._exporter is not None diff --git a/src/abcd_graph/exporter.py b/src/abcd_graph/exporter.py index 52b4bbc..db26819 100644 --- a/src/abcd_graph/exporter.py +++ b/src/abcd_graph/exporter.py @@ -28,9 +28,9 @@ from abcd_graph.utils import require if TYPE_CHECKING: # pragma: no cover - from igraph import Graph as IGraph # type: ignore[import] - from networkx import Graph as NetworkXGraph # type: ignore[import] - from scipy.sparse import csr_matrix # type: ignore[import] + from igraph import Graph as IGraph # type: ignore[import-not-found] + from networkx import Graph as NetworkXGraph + from scipy.sparse import csr_matrix class GraphExporter: @@ -49,7 +49,7 @@ def to_adjacency_matrix(self) -> NDArray[np.bool_]: return self._graph.to_adj_matrix() @require("scipy") - def to_sparse_adjacency_matrix(self) -> "csr_matrix": # type: ignore[no-any-unimported] + def to_sparse_adjacency_matrix(self) -> "csr_matrix": from scipy.sparse import csr_matrix if not self.is_proper_abcd: @@ -69,9 +69,10 @@ def to_igraph(self) -> "IGraph": # type: ignore[no-any-unimported] return graph @require("networkx") - def to_networkx(self) -> "NetworkXGraph": # type: ignore[no-any-unimported] + def to_networkx(self) -> "NetworkXGraph": import networkx as nx + graph: nx.Graph = nx.Graph() graph = nx.Graph() graph.add_nodes_from(range(self._graph._params.vcount)) diff --git a/src/abcd_graph/graph/core/utils.py b/src/abcd_graph/graph/core/utils.py index 5e9c8e4..48a21f2 100644 --- a/src/abcd_graph/graph/core/utils.py +++ b/src/abcd_graph/graph/core/utils.py @@ -42,7 +42,7 @@ def powerlaw_distribution(choices: NDArray[np.float64], intensity: float) -> NDA def get_community_color_map(communities: list["Community"]) -> list[str]: - import matplotlib.colors as colors # type: ignore[import] + import matplotlib.colors as colors # type: ignore[import-not-found] colors_list = list(colors.BASE_COLORS.values())[: len(communities)]