VSCode: How would I implement a deprecation system that allows me to scan my code base without running scripts?

Perhaps a bit of broad question, my apologies in advance. I’m willing to accept any inputs on this matter though, so feel free to point me in a direction.

I’m developing a project in vscode, and i’ve got a project setup like this.
vscode project:
----myLibrary.lib
----STRU.extension
----MEP.extension
----etc…

In order to get intellisense to work i’ve added my lib, pyrevitlib, and revitstubs to my extraPythonPaths
I need to start refactoring my code a bit, move functions around perhaps etc…

I’ve created a simple ‘@deprecated’ decorator that will log a warning when said decorated function is called. But in the end, this is not really what I want, because these warnings will only get triggered if the code is run by a user.

I want to be able to scan my project for any invocations of functions with ‘deprecated’ without having to manually run every script I’ve created. I don’t want our modellers to get annoyed/scared by deprecation warnings.

I’ve looked a bit into unittesting, and using the ‘inspect’ module in a sort of ‘global deprecation test file’, but these all start raising exceptions on imports, and some exceptions in the pyRevit files because of undefined variables. (figures, since pyrevit isn’t actually running.

I’m thinking I need to look into other ways of getting this to work…
Does anyone have any suggestions?

Right now I could ofcourse do the following:
find every @deprecated line in my code, and find all references using VSCode’s refactoring.
But it’s kinda tedious.

@GertjanVDB Not sure of the python language server in vscode supports “Finding References” of all these functions. This is usually a job for unit testing/code coverage testing frameworks.

Thanks for answering.
Yes vscode supports refactoring luckily. So I can rename symbols as well as find all references.

I guess I can work with that for the time being.

I’ve also looked into unit testing. I presumed unit testing would also trigger my deprecation warnings. But I’m running into some troubles getting that to work as well. It just throws me importerrors concerning pyevent Even tried creating a pyrevit pushbutton with a script that should start the unittesting module. Same deal.
Dunno.

Wondered if anyone knew something about that.

1 Like