Skip to content

Commit

Permalink
Add certifi dependency (#47)
Browse files Browse the repository at this point in the history
* 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:
    #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: #33
  • Loading branch information
robin-nitrokey authored Oct 27, 2023
1 parent 1bc938a commit bd090a7
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cd-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -76,4 +77,4 @@ jobs:
- name: Publish release
run: |
. venv/bin/activate
flit --repository pypi publish
flit --repository pypi publish
13 changes: 13 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
26 changes: 26 additions & 0 deletions ci-scripts/get_version.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion nethsm/VERSION

This file was deleted.

10 changes: 3 additions & 7 deletions nethsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit bd090a7

Please sign in to comment.