Search code examples
pythonpycharmautomated-refactoring

Python: Good way to get function and all dependencies in a single file?


I'm working on a big Python code base that grows and grows and grows. It's not a single application - more of a bunch of experiments that share some common code.

Every so often, I want to make a public release of a given experiment. I don't want to release my entire awful codebase, just the parts required to run a given experiment. So basically I'd like something to crawl through all the imports and copy whatever functions are called (or at least all the modules imported) into a single file, which I can release as a demo. I'd of course like to only do this for files defined in the current project (not a dependent package like numpy).

I'm using PyCharm now, and haven't been able to find that functionality. Is there any tool that does this?

Edit: I created the public-release package to solve this problem. Given a main module, it crawls through dependent modules and copies them into a new repo.


Solution

  • So in the end, to solve our problem, I made a tool called public-release, which collects all the dependencies for the module you want to release, throws them into a separate repo with setup scripts and all, so that you code can be easily run later.