-
-
Save mattdee123/b23068d4933c4a2b09d25518b6bac18f to your computer and use it in GitHub Desktop.
gen_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
MAX_DEPTH = 11 | |
def gen_package(name, levels): | |
subpkgs = [name+'a', name+'b'] | |
if levels == 1: | |
subpkgs = [] | |
for subpkg in subpkgs: | |
gen_package(subpkg, levels-1) | |
imports = '\n'.join(f'\t"example.com/{x}"' for x in subpkgs) | |
expr = '1' | |
if subpkgs: | |
expr = ' + '.join(f'{x}.V' for x in subpkgs) | |
os.mkdir(name) | |
with open(name + '/pkg.go', 'w') as f: | |
f.write(f'''package {name} | |
import ( | |
{imports} | |
) | |
const V = {expr} | |
''') | |
return name | |
gen_package('pkg_', MAX_DEPTH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment