quantstack / memestra Goto Github PK
View Code? Open in Web Editor NEWPython checker for places where deprecated functions are called.
License: BSD 3-Clause "New" or "Revised" License
Python checker for places where deprecated functions are called.
License: BSD 3-Clause "New" or "Revised" License
The title might be confusing, but here is an example of what I mean:
│ File: some_rec_module.py
───────┼──────────────────────────────────────────────────────────────
1 │ import some_module
2 │
3 │ def foo():
4 │ return some_module.foo()
5 │
6 │ def bar():
7 │ return some_module.bar()
8 + │
9 + │ foo()
10 + │ bar()
This is deprecated, see https://setuptools.readthedocs.io/en/latest/setuptools.html#test.
More generally, should we switch to pytest?
When running tests for pythons 3.8 and 3.9 after running tests for python 3.7 without the necessary changes to gast
and beniget
, both to support NamedExpr
s, the tests pass. With a clean cache (rm -rf $XDG_CONFIG_HOME/memestra
) the tests fail as they ought to. Whatever is being stored in $XDG_CONFIG_HOME
isn't taking into account enough information to make the behavior of the tool the same as it would be without a cache.
Hi, I wonder how to use memestra to run through all files under a specific directory?
Thanks
I'm trying to make a conda package: conda-forge/staged-recipes#11964
But a license file is needed.
Just a quick question, when I try to run the example in the README, I get an error because import decorator
doesn't have a deprecated
that we expect. With the same code as the README, Python can't run the script and Memestra produces no output:
➜ cat test.py
import decorator
@decorator.deprecated
def foo(): pass
def bar():
foo()
foo()
➜ python test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
import decorator
ImportError: No module named decorator
➜ memestra test.py
However, if I install Deprecated and replace decorator
with deprecated
in the test, Python and Memestra work as expected:
➜ pip install Deprecated
### snip
Successfully installed Deprecated-1.2.11 wrapt-1.12.1
➜ cat test2.py
import deprecated
@deprecated.deprecated
def foo(): pass
def bar():
foo()
foo()
➜ python test2.py
test2.py:9: DeprecationWarning: Call to deprecated function (or staticmethod) foo.
foo()
➜ memestra test2.py
foo used at test2.py:7:5
foo used at test2.py:9:1
Just wanted to confirm this. Will be happy to put together a little PR to update README accordingly?
I found a case where memestra doesn't work, but I suppose we want it to work:
If you're importing something from init like in here:
https://github.com/numpy/numpy/blob/41e254f96e8d5bd558d2edbf8b198eb4143e8b74/numpy/__init__.py#L155
for example, memestra won't return anything.
A reproducible example of what I mean would be running a file init_test.py
with the command memestra init_test.py --decorator=decoratortest.deprecated
that contains:
from tests.misc import foo
foo()
in memestra home and adding this line from some_module import foo
to the __init__.py
in tests/misc
.
https://pypi.org/project/memestra/ offers release/0.2.0 as the "latest version", which users usually install by default, I assume. There cde5ef6 (#59 / #60) is missing. As a result using memestra results in PermissionError: [Errno 13] Permission denied: '/usr/share/memestra'
.
Edit: I see that 6165c64 would also be missing.
Was trying to write an example for the blogpost and got this:
import deprecated
@deprecated.deprecated('This function will be removed on Feb. 2100.')
def some_old_function(x, y):
return x + y
# You can also decorate a class or a method:
class SomeClass(object):
@deprecated.deprecated('kkkkk')
def some_old_method(self, x, y):
return x + y
@deprecated.deprecated('Use another class.')
class SomeOldClass(object):
pass
some_old_function(2, 3)
some_obj = SomeClass()
some_obj.some_old_method(4, 5)
SomeOldClass()
Everything is captured by memestra but some_obj.some_old_method(4, 5)
.
I checked our tests and we're actually not covering it at all. I think we forgot.
Can help on this fix after this hectic week.
I've created a test case: https://github.com/brendan0powers/memestra_testcase
it's a simple setup with two files, test.py
, and testimport.py
. In testimport.py
, I define a class Test
, that is deprecated. It's used in test.py
. Memestra correctly reports the usage of the deprecated Test
class but does not report the reason for the deprecation.
versions:
beniget 0.3.0
gast 0.4.0
memestra 0.0.6
nbconvert 5.6.0
nbformat 4.4.0
output:
$ memestra --recursive test.py
testimport.Test used at test.py:3:5
expected output:
$ memestra --recursive test.py
testimport.Test used at test.py:3:5 This is deprecated
$ pip install memestra
Collecting memestra
Downloading memestra-0.0.1.tar.gz (7.0 kB)
ERROR: Command errored out with exit status 1:
command: /home/david/miniforge3/envs/memestra-dev/bin/python3.8 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-4vt5ksze/memestra/setup.py'"'"'; __file__='"'"'/tmp/pip-install-4vt5ksze/memestra/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-93mls65p
cwd: /tmp/pip-install-4vt5ksze/memestra/
Complete output (5 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-4vt5ksze/memestra/setup.py", line 5, in <module>
dev_reqs = open("requirements-dev.txt").read().splitlines()
FileNotFoundError: [Errno 2] No such file or directory: 'requirements-dev.txt'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
When testing recursive mode in a "real world" scenario, memestra does not find any deprecations. I can reproduce this with a few different Python libraries. I've added steps to reproduce below. This isn't exactly what I'm doing, but it's pretty close.
Setup the environment
conda create -n memestra-import python=3.7.1 ipywidgets deprecated
conda activate memestra-import
Check out the master branch of memestra, and install it.
pip install -e .
Edit $CONDA_PREFIX/lib/python3.7/site-packages/ipywidgets/widgets/widget_button.py
and add this snippet before the declaration of Button
from deprecated import deprecated
@deprecated("Test")
Create a file button.py that contains
from ipywidgets import Button
b = Button()
Run memestra
memestra --recursive button.py
With these files:
# decoratortest.py
from decorator import decorate
def _deprecated(func, *args, **kw):
print('warning:', func.__name__, 'has been deprecated')
return func(*args, **kw)
def deprecated(func):
return decorate(func, _deprecated)
# some_module.py
from decoratortest import deprecated
@deprecated
def foo(): pass
def bar(): pass
# test.py
import some_module
from decoratortest import deprecated
@deprecated
def foo(): pass
def bar(): pass
some_module.foo()
some_module.foo()
some_module.bar()
some_module.foo()
foo()
foo()
bar()
foo()
memestra shows the deprecations only for foo()
, not for some_module.foo()
:
$ memestra --decorator=decoratortest.deprecated test.py
foo used at test_code.py:14:1
foo used at test_code.py:15:1
foo used at test_code.py:17:1
Although it seems to work on the CI. The tests show the same error when I run them locally.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.