mmerickel / wired

A service locator implementation for Python.
https://wired.readthedocs.io
MIT License
17 stars 9 forks source link

DI system based on dataclasses #19

Closed pauleveritt closed 5 years ago

pauleveritt commented 5 years ago

This adds an optional sub "package" at wired.dataclasses. If you have Python 3.7 installed or the 3.6 backport of dataclasses, then wired.dataclasses gives you a convenient way to register singletons and factories.

If you have venusian installed, you can use decorators instead of imperatively registering dataclasses.

The injection system has some interesting features, such as picking an attribute or a key off the injected object.

pauleveritt commented 5 years ago

@mmerickel I believe I've addressed most of these points. There's still other work that can be done, but this might be a good checkpoint to decide if it does indeed go in the main package.

mmerickel commented 5 years ago

@mmerickel I believe I've addressed most of these points. There's still other work that can be done, but this might be a good checkpoint to decide if it does indeed go in the main package.

@pauleveritt I'm definitely on board with merging this. I think the only remaining sticking points for me are the two unresolved comments (plus the one tiny comment I just added).

mmerickel commented 5 years ago

@pauleveritt can you merge master into here and fix up the tests? There's some line warnings, 2 actual lines missing coverage and then a few in the tests.

pauleveritt commented 5 years ago

I see a complaint about venusian's use of imp but I'm not sure the right way to silence that. I fixed all the flake8 things and the coverage thing. The stuff about black...I'll have to do some work to get my editor's choices to match black's.

pauleveritt commented 5 years ago

@mmerickel Why does the coverage report look for coverage on stuff under /tests? The py37 Travis tox is failing because of that, for my Dummy fakes. What's the correct pattern, put those in a fixture so coverage will ignore them?

digitalresistor commented 5 years ago

There's a bug fix in venusian I need to review/pull and push a new version to fix that imp stuff. Ignore it for now IMHO.

Also, for some reason pytest under python 3.7 seems to find a lot more tests than pytest under other versions of python.

digitalresistor commented 5 years ago
platform darwin -- Python 3.5.6, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
cachedir: .tox/py35/.pytest_cache
rootdir: /Users/xistence/Projects/wired, inifile: setup.cfg, testpaths: src/wired, tests, docs
plugins: cov-2.7.1
collected 43 items

vs

platform darwin -- Python 3.7.0, pytest-5.0.1, py-1.8.0, pluggy-0.12.0
cachedir: .tox/py37/.pytest_cache
rootdir: /Users/xistence/Projects/wired, inifile: setup.cfg, testpaths: src/wired, tests, docs
plugins: cov-2.7.1
collected 106 items
digitalresistor commented 5 years ago

Oh, that's because of the conftest.py files...

/me shakes fist at @pauleveritt

digitalresistor commented 5 years ago

@pauleveritt in the Pylons Project at least, we make sure that all of our Dummy fixtures all have coverage as well, so if there is code that is not covered in your dummy objects, remove the code.

pauleveritt commented 5 years ago

I pushed tests for the dummies, back to 100% coverage.

mmerickel commented 5 years ago

The docs are going to need a venusian dependency as well. That'll be a new extra and RTD as well as [testenv:docs] in tox.ini needs to be configured to install it.

pauleveritt commented 5 years ago

Travis now passes. I made a new issue in #28 to remind us to fix Sphinx autodoc and the __mro__ issue.

mmerickel commented 5 years ago

thanks again @pauleveritt !