Comments (13)
I kept digging in Twisted code and the culprit seems to be the class BaseConnector(ABC)
class at https://github.com/twisted/twisted/blob/1c80aad4c8fd2d0142433476bd5f6df5c511b4ba/src/twisted/internet/base.py#L1224
For some reason, the implementer
decorator adds __provides__
to both BaseConnector
and ABC
classes:
>>> from zope.interface import classImplements, implementer
>>> from twisted.internet.interfaces import IConnector
>>> from abc import ABC
>>> @implementer(IConnector)
... class Test2(ABC):
... pass
>>> import great_expectations
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/__init__.py", line 32, in <module>
register_core_expectations()
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/registry.py", line 187, in register_core_expectations
from great_expectations.expectations import core # noqa: F401
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/core/__init__.py", line 1, in <module>
from .expect_column_distinct_values_to_be_in_set import (
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/core/expect_column_distinct_values_to_be_in_set.py", line 12, in <module>
from great_expectations.expectations.expectation import (
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/expectation.py", line 2350, in <module>
class BatchExpectation(Expectation, ABC):
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/expectation.py", line 287, in __new__
newclass._register_renderer_functions()
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/expectation.py", line 369, in _register_renderer_functions
attr_obj: Callable = getattr(cls, candidate_renderer_fn_name)
AttributeError: __provides__. Did you mean: '__providedBy__'?```
from scrapy.
This was determined to be a great expectations - issue.
from scrapy.
Well, at least importing zope.interface
(and twisted
) instead of scrapy
doesn't reproduce the error (I really hoped that will be the problem).
from scrapy.
To be honest, I don't know if this is it a problem with Zope or a bad implementation by Twisted lib. @wRAR What do you think?
As a workaround for Scrapy, maybe could import from twisted.internet._sslverify import Certificate
in the meantime to avoid these side effects? There is some risk of this breaking in the future but I wouldn't expect great changes from Twisted at this point.
from scrapy.
Counthing great-expectations/great_expectations#9698 (comment) I think that this issue is not related to scrapy and it's root-cause is 100% in GreatExpectations codebase (it can be solved by adding simple try except block around line tha gave AttributeError
).
from scrapy.
the real question is why is the import modifying a dependency instead of making a duplicate
and modifying the copy
if thats whats going on i think its bad practice.
from scrapy.
I think this person might be on to something.
from scrapy.
I was able to reproduce this issue by importing twisted.ssl.Certificate
:
(great_expectations) ➜ scrapy git:(master) ✗ python
Python 3.10.14 (main, Mar 19 2024, 21:46:16) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted.internet.ssl
>>> import great_expectations
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/__init__.py", line 32, in <module>
register_core_expectations()
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/registry.py", line 187, in register_core_expectations
from great_expectations.expectations import core # noqa: F401
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/core/__init__.py", line 1, in <module>
from .expect_column_distinct_values_to_be_in_set import (
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/core/expect_column_distinct_values_to_be_in_set.py", line 12, in <module>
from great_expectations.expectations.expectation import (
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/expectation.py", line 2350, in <module>
class BatchExpectation(Expectation, ABC):
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/expectation.py", line 287, in __new__
newclass._register_renderer_functions()
File "/Users/zyte/workspace/opensource/scrapy/.tox/great_expectations/lib/python3.10/site-packages/great_expectations/expectations/expectation.py", line 369, in _register_renderer_functions
attr_obj: Callable = getattr(cls, candidate_renderer_fn_name)
AttributeError: __provides__. Did you mean: '__providedBy__'?
from scrapy.
Importing Certificate
directly from its internal package seems to work:
(great_expectations) ➜ scrapy git:(master) ✗ python
Python 3.10.14 (main, Mar 19 2024, 21:46:16) [Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.internet._sslverify import Certificate
>>> import great_expectations
So it must be related to twisted.internet.ssl
init code
from scrapy.
@VMRuiz Thank you for looking into this! Do you think I should create an issue with zope?
from scrapy.
My first thought was also "I don't know if this is it a problem with Zope or a bad implementation by Twisted lib", as I'm not familiar with the zope.interface internals.
from scrapy.
Steps to Reproduce
This does work:
import great_expectations
import scrapy
If this works. What prevent You to just use this import order in Your task?
from scrapy.
try...except Block: Wrap the import statements in a try...except block to gracefully handle the import error and provide informative messages:
try:
import great_expectations
import scrapy
except ImportError as e:
print(f"Error importing libraries: {e}")
If you don't need Great Expectations functionalities throughout your script, consider delaying the import until the point of use with a function
import scrapy
def use_great_expectations():
from great_expectations import some_great_expectations_function # Import only when needed
print("Great Expectations used")
use_great_expectations()
Make sure you're using a clean virtual environment to avoid conflicts with other installed packages. Reinstall Scrapy and Great Expectations in a fresh environment to see if it resolves the issue.
Check for version compatibility between Scrapy and Great Expectations
from scrapy.
Related Issues (20)
- SCRAPER_SLOT_MAX_ACTIVE_SIZE - documentations HOT 1
- CachingHostnameResolver with CONCURRENT_REQUESTS_PER_IP fails HOT 7
- Document stats produced by Scrapy
- AttributeError: 'SelectReactor' object has no attribute '_handleSignals' HOT 2
- Fails to fetch request with hyphens in 3rd and 4th position of domain
- is there any method can add decorator on parse function? HOT 5
- Remove top-level reactor imports from CrawlerProces/CrawlerRunner examples HOT 5
- Possible improvement: this check depends on scrapy response properly converted to XmlResponse instance HOT 3
- Undeprecate and add back to defaults the off-domain spider middleware HOT 2
- Fix overridable methods in MediaPipeline HOT 1
- Latest allowed_domains behavior breaks middlewares that rewrite urls HOT 4
- persist_file() can return a Deferred that is never awaited
- [DOC] [ENHANCEMENT] Enhance Tutorial Documentation for Improved Clarity and Usefulness
- Edit Contributing.rst document to specify how to propose documentation suggestions HOT 11
- Error handling in contract parsing HOT 2
- Response.json() method not fully documented HOT 2
- Custom Log Formatter doesn't override download_error method. HOT 18
- Improve the docs of the dont_filter parameter of Request
- .. _topics-contributing: HOT 1
- Documentation - specify how to propose non programming and programming changes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scrapy.