Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logwrap breaks functions #35

Closed
drnextgis opened this issue Aug 14, 2018 · 7 comments
Closed

logwrap breaks functions #35

drnextgis opened this issue Aug 14, 2018 · 7 comments
Assignees
Labels

Comments

@drnextgis
Copy link

Using logwrap breaks functions. When I add @logwrap.logwrap to get_shape function it stops working:

In [1]: from telluric import GeoVector, constants
In [2]: from shapely import geometry
In [3]: from rasterio.crs import CRS
In [4]: poly = geometry.Polygon.from_bounds(4334065.7375318575650454, 5627100.9060072815045714, 4337359.6036174902692437,5630885.4445580849424005)
In [5]: roi = GeoVector(poly, crs=constants.WEB_MERCATOR_CRS)
In [6]: roi.get_shape(CRS({'init': 'epsg:3857'}))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-0be1dd22719f> in <module>()
----> 1 roi.get_shape(CRS({'init': 'epsg:3857'}))

~/sandbox/telluric/env/lib/python3.5/site-packages/logwrap/_log_wrap.cpython-35m-x86_64-linux-gnu.so in logwrap._log_wrap.LogWrap._get_function_wrapper.wrapper()

~/sandbox/telluric/env/lib/python3.5/site-packages/logwrap/_log_wrap.cpython-35m-x86_64-linux-gnu.so in bind_args_kwargs()

~/sandbox/telluric/telluric/telluric/vectors.py in __eq__(self, other)
    437         # otherwise the delegation won't happen
    438         return (
--> 439             self.crs == other.crs
    440             and self._shape.equals(other.get_shape(self.crs))
    441         )

AttributeError: type object '_empty' has no attribute 'crs'

Without @logwrap.logwrap all works as expected.

@penguinolog penguinolog self-assigned this Aug 14, 2018
@penguinolog
Copy link
Collaborator

Debugging...

@drnextgis
Copy link
Author

Thank you for quick response! All mentioned libraries you can find at PyPI. Decorated function is GeoVector.get_shape from telluric library. Should I provide anything else?

@penguinolog
Copy link
Collaborator

penguinolog commented Aug 14, 2018

No, I found place: __eq__ called for check, that default value not equals to set via parameter, default is signature.empty and __eq__ not check for type and fields:

            self.crs == other.crs
            and self._shape.equals(other.get_shape(self.crs))
        )

I'll make validation safer on logwrap side, but this error means, that GeoVector instances can not be compared with other types (int for example). Normally it should simply return False for any incompatible types.

@penguinolog
Copy link
Collaborator

Expect fix on evening

penguinolog added a commit that referenced this issue Aug 14, 2018
 (#36)

Fix legacy

Signed-off-by: Alexey Stepanov <penguinolog@gmail.com>
@penguinolog
Copy link
Collaborator

Done and released 4.0.2/5.0.1:

Test output at log:

'get_shape'(
    # POSITIONAL_OR_KEYWORD:
    'self'=GeoVector(shape=POLYGON ((4334065.737531858 5627100.906007282, 4334065.737531858 5630885.444558085, 4337359.60361749 5630885.444558085, 4337359.60361749 5627100.906007282, 4334065.737531858 5627100.906007282)), crs=+init=epsg:3857),
    'crs'=CRS({'init': 'epsg:3857'}),
)
DEBUG:logwrap:Done: 'get_shape' with result:
<shapely.geometry.polygon.Polygon object at 0x7f26e76abf60>```

@drnextgis
Copy link
Author

Thank you very much, Alexey!

I have one questions related to the library. Now it is not possible to bypass logwrap if current log level is higher then log_level, right? It would be handy if logwrap decorator be able to return original function in this case.

@penguinolog
Copy link
Collaborator

penguinolog commented Aug 14, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants