A lot of my Python scripts interface with my C# code and when I make changes to my C# code, it breaks a ton of my Python scripts. I am running Visual Studio for all of my code and was wondering if there is a way to catch this during compilation? It's annoying to push changes and then someone complains that the script has broken because I changed my type or method header. Right now, I do a check where I make sure the method exists within the code before executing in Python but it would be nice to take one step further and have it be checked before I even push the code. We log an error when the method doesn't exist/has changed but having it taken a step further would be the goal.
-
So you are introducing breaking changes to an (internal) interface and you are surprised by client code actually breaking? Maybe version your C# code and deliver to yourself as if it were a 3rd party lib. Create UnitTests that represent your API Contract. So if you make changes and they break, you know you have breaking changes and need to release a new version of the C# part. While your Python part still uses the old version, it won't break. Then you can upgrade the python to your new C# API version.Fildor– Fildor2024-05-23 07:59:59 +00:00Commented May 23, 2024 at 7:59
Add a comment
|
1 Answer
There is no way to do this out-of-the-box. But there is a way I used in my career:
- Make C# API library (DTO, interfaces), without dependencies.
- On pre-compilation stage, generate Python hooks for those interfaces. Should be pretty straight-forward using reflection.
- Make some Python unit-tests, mocking C# interfaces, this will ensure integrity.