From bd090a79668c1f9ad9bba4ec0018eebeeb2fea8d Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Fri, 27 Oct 2023 18:55:42 +0200 Subject: [PATCH] Add certifi dependency (#47) * Move version into nethsm/__init__.py To make it possible to use `pip install .`, we have to change `__init__.py` so that it is possible to determine the version with static analysis. See this issue for more context: https://github.com/Nitrokey/nethsm-sdk-py/issues/33 * ci: Add clean-install job This patch adds a clean-install job to the CI that makes sure that installing the package with pip and using it works, i. e. we did not forget to specify a required dependency. * Add missing certifi dependency This patch adds certifi as a required dependency. Previously, we did not notice it was missing as it was installed together with flit in the CI and development setup. Fixes: https://github.com/Nitrokey/nethsm-sdk-py/issues/33 --- .github/workflows/cd-pypi.yaml | 5 +++-- .github/workflows/ci.yaml | 13 +++++++++++++ README.md | 2 +- ci-scripts/get_version.py | 26 ++++++++++++++++++++++++++ nethsm/VERSION | 1 - nethsm/__init__.py | 10 +++------- pyproject.toml | 5 +++-- 7 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 ci-scripts/get_version.py delete mode 100644 nethsm/VERSION diff --git a/.github/workflows/cd-pypi.yaml b/.github/workflows/cd-pypi.yaml index 38af806..769dc4a 100644 --- a/.github/workflows/cd-pypi.yaml +++ b/.github/workflows/cd-pypi.yaml @@ -21,7 +21,8 @@ jobs: - name: Check if version tag and package version are equal run: | TAG_VERSION="${{ github.event.release.tag_name }}" - if [ ${TAG_VERSION:1} == $(cat nethsm/VERSION) ]; then exit 0; else exit 1; fi + SOURCE_VERSION="$(python3 ci-scripts/get_version.py)" + if [ ${TAG_VERSION:1} == ${SOURCE_VERSION} ]; then exit 0; else exit 1; fi build: name: Build runs-on: ubuntu-latest @@ -76,4 +77,4 @@ jobs: - name: Publish release run: | . venv/bin/activate - flit --repository pypi publish \ No newline at end of file + flit --repository pypi publish diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 68ac69e..358a26e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -101,3 +101,16 @@ jobs: uses: codecov/codecov-action@v3 with: files: ./coverage.xml + clean-install: + name: Try a clean install with pip + runs-on: ubuntu-latest + container: python:3.9-slim + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Create virtual environment + run: python3 -m venv venv + - name: Install package + run: venv/bin/pip install . + - name: Use package + run: venv/bin/python3 -c "import nethsm" diff --git a/README.md b/README.md index 712a2ce..298e6ec 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ The current list of such functions is: ### Publishing a new version -- change the version in `nethsm/VERSION`. Example : 0.1.0 +- change `__version__` in `nethsm/__init__.py`. Example : 0.1.0 - create a new tag, prepending `v` to the version. Example : v0.1.0 - create a new release on GitHub to trigger the ci that will publish the new version. diff --git a/ci-scripts/get_version.py b/ci-scripts/get_version.py new file mode 100644 index 0000000..a00ae23 --- /dev/null +++ b/ci-scripts/get_version.py @@ -0,0 +1,26 @@ +import ast + +filename = "nethsm/__init__.py" +with open(filename) as f: + data = f.read() +module = ast.parse(data, filename) +assert isinstance(module, ast.Module) + +values = [] +for stmt in module.body: + if not isinstance(stmt, ast.Assign): + continue + + is_version = False + for target in stmt.targets: + if isinstance(target, ast.Name): + if target.id == "__version__": + is_version = True + if not is_version: + continue + + assert isinstance(stmt.value, ast.Constant) + values.append(stmt.value) + +assert len(values) == 1 +print(values[0].value) diff --git a/nethsm/VERSION b/nethsm/VERSION deleted file mode 100644 index 9fc80f9..0000000 --- a/nethsm/VERSION +++ /dev/null @@ -1 +0,0 @@ -0.3.2 \ No newline at end of file diff --git a/nethsm/__init__.py b/nethsm/__init__.py index 490069d..fdb30e1 100644 --- a/nethsm/__init__.py +++ b/nethsm/__init__.py @@ -8,24 +8,20 @@ # copied, modified, or distributed except according to those terms. """Python Library to manage NetHSM(s).""" -import pathlib -from base64 import b64encode - -import urllib3 - -__version_path__ = pathlib.Path(__file__).parent.resolve().absolute() / "VERSION" -__version__ = open(__version_path__).read().strip() +__version__ = "0.3.2" import contextlib import enum import json import re +from base64 import b64encode from dataclasses import dataclass from datetime import datetime from io import BufferedReader from typing import Any, Iterator, Literal, Optional, Union, cast from urllib.parse import urlencode +import urllib3 from urllib3 import HTTPResponse, _collections from urllib3._collections import HTTPHeaderDict diff --git a/pyproject.toml b/pyproject.toml index 1c999fd..483852c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,9 +11,10 @@ license = {file = "LICENSE"} classifiers = ["License :: OSI Approved :: Apache Software License"] dynamic = ["version", "description"] dependencies = [ - "urllib3 >=2.0,<2.1", - "typing_extensions ~= 4.3.0", + "certifi", "python-dateutil", + "typing_extensions ~= 4.3.0", + "urllib3 >=2.0,<2.1", ] [project.urls]