Skip to content

Commit

Permalink
Merge pull request #23 from getslash/updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vmalloc authored Oct 4, 2024
2 parents 23b5600 + f1e47c3 commit 5505a72
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 134 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
pull_request:
workflow_dispatch:
# manually triggered

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
env:
UV_PYTHON: ${{ matrix.python-version }}

steps:
- name: Checkout the repository
uses: actions/checkout@main
- name: Install the default version of uv
id: setup-uv
uses: astral-sh/setup-uv@v3
- name: Print the installed version
run: echo "Installed uv version is ${{ steps.setup-uv.outputs.uv-version }}"
- name: Install Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Tests
run: |
uv venv
uv pip install ".[testing]"
uv run ruff format . --check
uv run ruff check .
.venv/bin/pytest -x tests --cov=confetti --cov-report=html
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

19 changes: 5 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@ detox-test:
detox

test: env
.env/bin/py.test tests
.venv/bin/pytest -x tests --cov=confetti --cov-report=html

coverage-test: env
.env/bin/coverage run .env/bin/py.test -w tests

env: .env/.up-to-date

.env/.up-to-date: setup.py Makefile
virtualenv .env
.env/bin/pip install -e .
.env/bin/pip install Sphinx==1.1.3 releases pytest
touch .env/.up-to-date
env:
uv venv
uv pip install -e ".[testing]"

doc: env
.env/bin/python setup.py build_sphinx

.PHONY: doc
.venv/bin/sphinx-build -a -W -E doc build/sphinx/html

4 changes: 3 additions & 1 deletion confetti/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
__version__ = "2.5.3"
from importlib.metadata import distribution

__version__ = distribution("confetti").version
20 changes: 9 additions & 11 deletions confetti/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sentinels import NOTHING

from . import exceptions
from .python3_compat import iteritems, string_types, itervalues
from .ref import Ref
from .utils import coerce_leaf_value

Expand Down Expand Up @@ -45,7 +44,7 @@ def mark_clean(self):
while stack:
root = stack.pop()
if isinstance(root, dict):
stack.extend(itervalues(root))
stack.extend(iter(root.values()))
elif isinstance(root, Config):
stack.extend(root.itervalues())

Expand All @@ -64,7 +63,7 @@ def _init_value(self, value):

def _fix_dictionary_value(self):
to_replace = []
for k, v in iteritems(self._value):
for k, v in self._value.items():
if isinstance(v, dict):
to_replace.append((k, Config(v, parent=self)))
for k, v in to_replace:
Expand Down Expand Up @@ -199,10 +198,10 @@ def extend(self, conf=None, **kw):

def _extend_from_conf(self, conf):
conf = dict((key, conf.get_config(key)) for key in conf.keys())
for key, value in iteritems(conf):
for key, value in conf.items():
if key in self._value:
self.get_config(key)._verify_config_paths(value)
for key, value in iteritems(conf):
for key, value in conf.items():
self._value[key] = value

def _verify_config_paths(self, conf):
Expand Down Expand Up @@ -233,7 +232,7 @@ def _verify_config_paths(self, conf):
self.get_config(k)._verify_config_paths(conf._value[k])

def _extend_from_dict(self, d):
for key, value in iteritems(d):
for key, value in d.items():
if isinstance(value, dict):
if key not in self._value:
self._value[key] = {}
Expand All @@ -243,7 +242,7 @@ def _extend_from_dict(self, d):

def update(self, conf):
conf = dict((key, conf.get_config(key)) for key in conf.keys())
for key, value in iteritems(conf):
for key, value in conf.items():
if not value.is_leaf():
if key not in self._value:
self._value[key] = {}
Expand All @@ -258,7 +257,7 @@ def keys(self):
return self._value.keys()

def itervalues(self):
return itervalues(self._value)
return iter(self._value.values())

@classmethod
def from_filename(cls, filename, namespace=None):
Expand Down Expand Up @@ -350,7 +349,7 @@ def assign_path(self, path, value, deduce_type=False, default_type=None):
3
"""
config = self.get_config(path)
if deduce_type and isinstance(value, string_types):
if deduce_type and isinstance(value, str):
leaf = self.get_path(path)
value = coerce_leaf_value(path, value, leaf, default_type)

Expand All @@ -375,7 +374,6 @@ def __repr__(self):


class ConfigProxy(object):

def __init__(self, conf):
super(ConfigProxy, self).__init__()
self._conf = conf
Expand Down Expand Up @@ -427,7 +425,7 @@ def _set_state(config, state):
assert isinstance(config, Config)
for key in set(config.keys()) - set(state):
config.pop(key)
for key, value in iteritems(state):
for key, value in state.items():
if isinstance(value, dict):
_set_state(config[key], value)
else:
Expand Down
1 change: 0 additions & 1 deletion confetti/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Metadata(object):

def __init__(self, **kwargs):
super(Metadata, self).__init__()
self.metadata = kwargs
Expand Down
27 changes: 0 additions & 27 deletions confetti/python3_compat.py

This file was deleted.

1 change: 0 additions & 1 deletion confetti/ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class Ref(object):

def __init__(self, target, filter=None):
super(Ref, self).__init__()
self._target = target
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
# import sys, os

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
37 changes: 37 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[build-system]
requires = ["hatchling>=0.25.1", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "confetti"
description = "Generic configuration mechanism"
readme = "README.rst"
requires-python = ">=3.8"
license = { text = "BSD 3-Clause License" }

classifiers = [
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
dependencies = ["sentinels>=0.0.5"]
dynamic = ["version"]

authors = [{ name = "Rotem Yaari", email = "[email protected]" }]

[project.urls]
"Homepage" = "https://github.com/getslash/confetti"

[project.optional-dependencies]
testing = ["pytest", "pytest-cov", "ruff"]

[tool.hatch.version]
source = "vcs"

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
35 changes: 0 additions & 35 deletions setup.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def checkpoint():


class Checkpoint(object):

called = False
args = kwargs = timestamp = None

Expand Down
9 changes: 1 addition & 8 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import tempfile

from .test_utils import TestCase
from unittest import TestCase
from confetti import Config
from confetti import get_config_object_from_proxy
from confetti import exceptions
Expand All @@ -10,7 +10,6 @@


class BasicUsageTest(TestCase):

def setUp(self):
super(BasicUsageTest, self).setUp()
self.conf = Config(dict(a=dict(b=2)))
Expand Down Expand Up @@ -84,7 +83,6 @@ def test_keys(self):


class ExtendingTest(TestCase):

def setUp(self):
super(ExtendingTest, self).setUp()
self.conf = Config({"a": 1})
Expand Down Expand Up @@ -151,7 +149,6 @@ def test_update_config_preserves_nodes(self):


class HelperMethodsTest(TestCase):

def setUp(self):
super(HelperMethodsTest, self).setUp()
self.config = Config(
Expand All @@ -175,7 +172,6 @@ def test_traverse_leaves(self):


class CopyingTest(TestCase):

def test_copying_nested_dictionaries(self):
raw_conf = {"a": {"b": 2}}
conf1 = Config(raw_conf)
Expand All @@ -185,7 +181,6 @@ def test_copying_nested_dictionaries(self):


class LinkedConfigurationTest(TestCase):

def setUp(self):
super(LinkedConfigurationTest, self).setUp()
self.conf1 = Config(dict(a=1))
Expand Down Expand Up @@ -217,7 +212,6 @@ def test_linked_backups_restore_parent_then_child(self):


class BackupTest(TestCase):

def setUp(self):
super(BackupTest, self).setUp()
self.conf = Config(dict(a=1, b=2, c=[]))
Expand Down Expand Up @@ -250,7 +244,6 @@ def test_backup_copy(self):


class SerializationTest(TestCase):

def setUp(self):
super(SerializationTest, self).setUp()
self.dict = dict(a=dict(b=dict(c=8)))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cross_references.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .test_utils import TestCase
from unittest import TestCase
from confetti import Config, Ref


Expand Down
1 change: 0 additions & 1 deletion tests/test_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class DocumentationTest(TestCase):

def test_doctests(self):
for p, _, filenames in os.walk(
os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "doc"))
Expand Down
Loading

0 comments on commit 5505a72

Please sign in to comment.