Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
141 changes: 141 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
name: publish

on:
push:
branches:
- main
- master
tags:
- '*'

jobs:

build:
name: Build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Install requirements
run: |
pip install --upgrade build
pip install --upgrade setuptools wheel setuptools-scm[toml] importlib-metadata
pip install git+https://github.com/jic-dtool/dtool-annotation.git@main
pip list

- name: Package distribution
run: |
python -m build

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/


publish-to-testpypi:
name: Publish to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/dtool-annotation

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
skip-existing: true


publish-to-pypi:
name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/dtool-annotation # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
verbose: true


github-release:
name: >-
Make github release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/

- name: Sign with Sigstore
uses: sigstore/gh-action-sigstore-python@v2.1.1
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl

- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""

- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
45 changes: 45 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: test

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:

jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- name: Git checkout
uses: actions/checkout@v4

- name: Set up python3 ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install requirements
run: |
python -m pip install --upgrade pip
pip install .[test]
pip install flake8
pip list

- name: Test with pytest
run: |
pytest -sv

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=12 --max-line-length=127 --statistics
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ This change log uses principles from `keep a changelog <http://keepachangelog.co
Added
^^^^^

- The CLI command 'dtool annotation delete'
- github CI test workflow
- github CI publication workflow
- Activated dependabot

Changed
^^^^^^^

- Moved from ``setup.py`` to ``pyproject.toml``
- Dynamic versioning

Deprecated
^^^^^^^^^^
Expand Down
11 changes: 10 additions & 1 deletion dtool_annotation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""dtool_annotation package."""

__version__ = "0.1.1"
try:
from importlib.metadata import version, PackageNotFoundError
except ModuleNotFoundError:
from importlib_metadata import version, PackageNotFoundError

try:
__version__ = version(__name__)
except PackageNotFoundError:
# package is not installed
pass
18 changes: 18 additions & 0 deletions dtool_annotation/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@ def list_annotations(dataset_uri):
for name in sorted(dataset.list_annotation_names()):
value = str(dataset.get_annotation(name))
click.secho("{}\t{}".format(name, value))


@annotation.command(name="delete")
@base_dataset_uri_argument
@click.argument("key")
def delete_annotation(dataset_uri, key):
"""Delete dataset annotation."""
try:
dataset = dtoolcore.ProtoDataSet.from_uri(
uri=dataset_uri,
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
)
except dtoolcore.DtoolCoreTypeError:
dataset = dtoolcore.DataSet.from_uri(
uri=dataset_uri,
config_path=dtoolcore.utils.DEFAULT_CONFIG_PATH
)
dataset.delete_annotation(key)
47 changes: 47 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[build-system]
requires = ["setuptools>=42", "setuptools_scm[toml]>=6.3"]
build-backend = "setuptools.build_meta"

[project]
name = "dtool-annotation"
description = "Add ability to annotate datasets using the dtool CLI"
authors = [
{name = "Tjelvar Olsson", email = "tjelvar.olsson@gmail.com"},
{name = "Johannes L. Hörmann", email = "johannes.laurin@gmail.com"},
]
readme = "README.rst"
requires-python = ">=3.7"
license = {file = "LICENSE"}
dynamic = ["version"]
dependencies = [
"click",
"dtoolcore>=3.19.0",
"dtool-cli",
]

[project.optional-dependencies]
test = [
"pytest",
"pytest-cov"
]
docs = [
"sphinx",
"sphinx_rtd_theme",
"sphinxcontrib-spelling"
]

[project.urls]
Repository = "https://github.com/jic-dtool/dtool-annotation"
Documentation = "https://github.com/jic-dtool/dtool-annotation/blob/master/README.rst"
Changelog = "https://github.com/jic-dtool/dtool-annotation/blob/master/CHANGELOG.rst"

[tool.setuptools_scm]
version_scheme = "guess-next-dev"
local_scheme = "no-local-version"
write_to = "dtool_annotation/version.py"

[tool.setuptools]
packages = ["dtool_annotation"]

[project.entry-points."dtool.cli"]
annotation = "dtool_annotation.cli:annotation"
29 changes: 0 additions & 29 deletions setup.py

This file was deleted.

31 changes: 31 additions & 0 deletions tests/test_annotation_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ def test_annotation_basic(tmp_dataset_fixture): # NOQA
actual = result.output.strip()
assert actual == expected

result = runner.invoke(annotation, [
"delete",
tmp_dataset_fixture.uri,
"project"
])
assert result.exit_code == 0

result = runner.invoke(annotation, [
"get",
tmp_dataset_fixture.uri,
"project"
])
assert result.exit_code != 0
expected = "No annotation named: 'project'"
actual = result.output.strip()
assert actual == expected


def test_annotation_invalid_name(tmp_dataset_fixture): # NOQA

Expand Down Expand Up @@ -72,6 +89,20 @@ def test_get_non_existing_annotation(tmp_dataset_fixture): # NOQA
assert result.output.strip() == expected


def test_delete_non_existing_annotation(tmp_dataset_fixture): # NOQA

from dtool_annotation.cli import annotation

runner = CliRunner()

result = runner.invoke(annotation, [
"delete",
tmp_dataset_fixture.uri,
"project",
])
assert result.exit_code == 0


def test_annotation_types(tmp_dataset_fixture): # NOQA

from dtool_annotation.cli import annotation
Expand Down