Hello. This is my first blog post.
I have created a tool that combines Python packages that exist in separate files into a single source. This tool allows you to import and use libraries for competitive programming in the same way as common packages (like numpy).Similar tools are webpack and oj-bundle.
- github: https://github.com/bayashi-cl/expander
- Example of a submission using this tool(AtCoder): https://atcoder.jp/contests/abc238/submissions/29410034
By the way, in the code generated by this tool, the definitions of functions and classes in the library are expressed as "strings". I think that this may violate the rules against obfuscation (Can-do's and Can't-do's 4). Can the code generated by this tool be used in the contest? I would like to hear your opinions.
Thank you very much.








Auto comment: topic has been updated by bayashi_cl (previous revision, new revision, compare).
I tried out this, it literally pulls in the entire library. My 10 lines code got expanded to 400K lines. Am I using it correctly ?
This is my code test.py
And I ran.
python -m expander test.py -o test_expanded.py -m sympyIt generated close to 400K lines of code. Surely it must be more intelligent than this, it should only pull in the used function and its dependencies recursively and nothing more. If I have to write code in a way like changing the coding style from
import sympyto looking likefrom sympy import symbols, expandI am okay to make that adjustment.Thank you for using my tool.
I am sorry, but it is not possible to expand and submit a large module like
sympywith this tool.Currently, this tool recursively expands all "dependent" modules, such as the imported modules and their parent modules, and modules imported by that module... and so on. (In the case of
sympy, this is directly due to the fact that sympy/__init__.py imports many submodules.) This is because it is very difficult to identify which parts of the source code are really needed; even when Python imports modules, it should not be "loading only the necessary parts".I would like to see this tool used for smaller packages like PyRival or your own competitive programming libraries. (And I have submitted code expanded with this tool several times and never received a warning.)
I copy manually from sympy all the time, it takes only few hundred lines most of the times. My own libraries aren't going to be too simple either. What is the point of using library if you are having to write each library of just one or two files. I will try out pyrival and let you know. If it can't extract out code from complex packages then it woundn't be of much use yet, but with some improvement hopefully it will. If recursively pulling out library is going to be so difficult, I would suggest we can design alternative expander to extract code based on code coverage. Only the hot path of the code may be extracted and other paths may not(after running through a set of test data). There are lots of opensource code coverage tools to get started.
Anyways thanks for the quick reply. I wasn't able to get in touch with you on github.
I had not thought of using the code coverage tool. Thanks for giving me the idea.