From 7f61916202a1b23d3b04528631bf7ef2cf9e872c Mon Sep 17 00:00:00 2001 From: Oliver Berger Date: Mon, 13 May 2024 17:10:33 +0200 Subject: [PATCH] fix: remov loop from event also updated some deps --- .github/workflows/build.yaml | 38 ++++++ .gitignore | 11 ++ build_manylinux.sh | 7 +- devenv.lock | 227 +++++++++++++++++++++++++++++++++++ devenv.nix | 66 ++++++++++ docker-compose.yml | 3 + setup.py | 6 +- src/buvar/config.py | 59 --------- src/buvar/plugin.py | 4 +- tests/test_config.py | 4 +- 10 files changed, 357 insertions(+), 68 deletions(-) create mode 100644 .github/workflows/build.yaml create mode 100644 devenv.lock create mode 100644 devenv.nix diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..ab26b46 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,38 @@ +name: "Build and Tests" + +on: + push: + branches: + - "*" + # tag is already build in branch + tags-ignore: + - "*" + pull_request: + branches: ["master"] + +jobs: + pytest: + strategy: + fail-fast: false + matrix: + version: ["3.12", "3.11", "3.10", "3.9", "3.8", "3.7"] + + name: Testing ${{ matrix.version }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "{{ matrix.version }}" + + - name: Install + run: | + python -m pip install --upgrade pip + python -m pip install -e ".[tests]" + + - name: Run tests + run: | + pytest diff --git a/.gitignore b/.gitignore index 08740dc..3d6b7aa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,14 @@ c_di.c c_di.*.so c_components.c c_components.*.so +c_context.c +c_context.*.so +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml diff --git a/build_manylinux.sh b/build_manylinux.sh index 25f8030..76c9315 100755 --- a/build_manylinux.sh +++ b/build_manylinux.sh @@ -2,17 +2,22 @@ set -e -x # defaults -: ${PLATFORM:=manylinux1_x86_64} +: ${PLATFORM:=manylinux2014_x86_64} : ${PROJECT:=buvar} : ${PYTHON_VERSIONS:=$(cat < reqs.txt + # cat requirements.txt >> reqs.txt + ''; + + # https://devenv.sh/tests/ + enterTest = '' + echo "Running tests" + ''; + + # https://devenv.sh/services/ + # services.postgres.enable = true; + + # https://devenv.sh/languages/ + languages.python = { + enable = true; + version = "3.12.3"; + uv.enable = true; + venv = { + enable = true; + # requirements = ./requirements.txt; + }; + }; + # languages.javascript = { + # enable = true; # adds node LTS & npm + # corepack.enable = true; + # npm.install.enable = true; + # # package = pkgs.nodejs-18_x; # <- if you need to override npm version + # }; + + # https://devenv.sh/pre-commit-hooks/ + # pre-commit.hooks.shellcheck.enable = true; + + # https://devenv.sh/processes/ + # processes.ping.exec = "ping example.com"; + + # See full reference at https://devenv.sh/reference/options/ +} diff --git a/docker-compose.yml b/docker-compose.yml index ca06cdb..a65cbcf 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -34,6 +34,9 @@ services: environment: PLATFORM: manylinux2014_x86_64 PYTHON_VERSIONS: | + cp312-cp312 + cp311-cp311 + cp310-cp310 cp39-cp39 cp38-cp38 cp37-cp37m diff --git a/setup.py b/setup.py index 03c9b58..6a1d826 100644 --- a/setup.py +++ b/setup.py @@ -27,11 +27,9 @@ def finalize_options(self): install_requires = [ "attrs", - "cattrs<=1.10.0", - "multidict>=4.5,<5.0", + "cattrs<=22.1.0", "structlog>=20.1.0", "toml>=0.10", - "tomlkit>=0.5.3", "typing_inspect>=0.4.0", "cached_property", "uritools", @@ -69,7 +67,7 @@ def finalize_options(self): "long_description_content_type": "text/x-rst", "author": "Oliver Berger", "author_email": "diefans@gmail.com", - "url": "https://gitlab.com/diefans/buvar", + "url": "https://github.com/diefans/buvar", "package_dir": {"": "src"}, "packages": find_packages("src"), "include_package_data": True, diff --git a/src/buvar/config.py b/src/buvar/config.py index 50b3acc..d019ba3 100644 --- a/src/buvar/config.py +++ b/src/buvar/config.py @@ -6,7 +6,6 @@ import attr import cattr import structlog -import tomlkit import typing_inspect from . import di, util @@ -254,63 +253,5 @@ def generate_env_help(cls, env_prefix=""): return help -def generate_toml_help(config_cls, *, parent=None): - if parent is None: - parent = tomlkit.table() - doclines = trim(config_cls.__doc__).split("\n") - for line in doclines: - parent.add(tomlkit.comment(line)) - parent.add(tomlkit.nl()) - - for attrib in attr.fields(config_cls): - meta = attrib.metadata.get(CNF_KEY) - if attr.has(attrib.type): - # yield (attrib.name,), attrib - sub_doc = generate_toml_help(attrib.type) - parent.add(attrib.name, sub_doc) - else: - if meta: - parent.add(tomlkit.comment(meta.help)) - - if attrib.default in (missing, attr.NOTHING): - parent.add(tomlkit.comment(f"{attrib.name} =")) - else: - default = ( - attrib.default() if callable(attrib.default) else attrib.default - ) - parent.add(attrib.name, default) - - parent.add(tomlkit.nl()) - - return parent - - -def trim(docstring): - # https://www.python.org/dev/peps/pep-0257/ - if not docstring: - return "" - # Convert tabs to spaces (following the normal Python rules) - # and split into a list of lines: - lines = docstring.expandtabs().splitlines() - # Determine minimum indentation (first line doesn't count): - indent = sys.maxsize - for line in lines[1:]: - stripped = line.lstrip() - if stripped: - indent = min(indent, len(line) - len(stripped)) - # Remove indentation (first line is special): - trimmed = [lines[0].strip()] - if indent < sys.maxsize: - for line in lines[1:]: - trimmed.append(line[indent:].rstrip()) - # Strip off trailing and leading blank lines: - while trimmed and not trimmed[-1]: - trimmed.pop() - while trimmed and not trimmed[0]: - trimmed.pop(0) - # Return a single string: - return "\n".join(trimmed) - - async def prepare(): di.register(Config.adapt) diff --git a/src/buvar/plugin.py b/src/buvar/plugin.py index b20adc3..838bb6e 100644 --- a/src/buvar/plugin.py +++ b/src/buvar/plugin.py @@ -6,7 +6,6 @@ A py:obj:`buvar.components.Components` context is stacked in way, that plugins share the same context, while tasks don't, but may access the plugin context. - >>> loop = asyncio.get_event_loop() >>> state = {} >>> async def prepare(load: Loader): @@ -26,6 +25,7 @@ ['foo'] >>> assert state == {'task': True} """ +# XXX FIXME doctest sometime shows log messages import asyncio import collections.abc import inspect @@ -177,7 +177,7 @@ def __init__(self, components=None, loop=None, signals: t.Type[Signals] = None): .push() ) # provide basic components - self.cancel = self.context.add(Cancel(loop=self.loop)) + self.cancel = self.context.add(Cancel()) self.teardown = self.context.add(Teardown()) self.loader = self.context.add(Loader()) self.signals = self.context.add((signals or Signals)(self)) diff --git a/tests/test_config.py b/tests/test_config.py index 7646678..2b4b20f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -190,7 +190,7 @@ class BarConfig: assert ( help.as_string() == """# BarConfig. -# +# # bla bla # bli bli @@ -199,7 +199,7 @@ class BarConfig: [foo] # FooConfig. -# +# # bim bam # string