This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parallelize Py monorepo scripts (test, lint, etc)
- Loading branch information
Showing
7 changed files
with
63 additions
and
56 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env bash | ||
|
||
"""Script to run linters against local copy of all components.""" | ||
|
||
from os import path | ||
import subprocess | ||
|
||
subprocess.check_call( | ||
( | ||
f"{path.join('.', 'cmd_pkgs_in_dep_order.py')}" | ||
+ f" {path.join('.', 'setup.py')} build_sphinx" | ||
).split() | ||
) | ||
./parallel ./setup.py build_sphinx |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env bash | ||
|
||
"""Script to install all packages in editable mode (pip install -e .).""" | ||
|
||
from os import path | ||
import subprocess | ||
|
||
# install all packages | ||
subprocess.check_call( | ||
( | ||
path.join(".", "cmd_pkgs_in_dep_order.py") + " pip install -e .[dev]" | ||
).split() | ||
) | ||
./parallel pip install -e .[dev] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env bash | ||
|
||
"""Script to run linters against local copy of all components.""" | ||
|
||
from os import path | ||
import subprocess | ||
|
||
subprocess.check_call( | ||
( | ||
f"{path.join('.', 'cmd_pkgs_in_dep_order.py')}" | ||
+ f" {path.join('.', 'setup.py')} lint" | ||
).split() | ||
) | ||
./parallel ./setup.py lint |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env python | ||
|
||
"""Run the given command in all packages in parallel. | ||
Handy for quick verification test runs, but annoying in that all of the output | ||
is interleaved. | ||
$ ./parallel ./setup.py lint | ||
This will `cd` into each package, run `./setup.py lint`, then `cd ..`, all in | ||
parallel, in a separate process for each package. The number of processes is | ||
decided by ProcessPoolExecutor. Replace "lint" with any of "test", "clean", | ||
"build_sphinx" (for docs), etc. | ||
Also consider: | ||
$ ./parallel pip install -e .[dev] # install all the packages in editable mode | ||
$ ./parallel pip uninstall $(basename $(pwd)) | ||
>>>""" | ||
|
||
from concurrent.futures import ProcessPoolExecutor | ||
from os import chdir | ||
from subprocess import check_call | ||
from sys import argv | ||
|
||
PACKAGES = [ | ||
"contract_addresses", | ||
"contract_artifacts", | ||
"contract_wrappers", | ||
"json_schemas", | ||
"sra_client", | ||
"order_utils", | ||
"middlewares", | ||
] | ||
|
||
def run_cmd_on_package(package: str): | ||
"""cd to the package dir, ./setup.py lint, cd ..""" | ||
chdir(package) | ||
check_call(f"{' '.join(argv[1:])}".split()) | ||
chdir("..") | ||
|
||
ProcessPoolExecutor().map(run_cmd_on_package, PACKAGES) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,3 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env bash | ||
|
||
"""Script to run tests against local copy of all components.""" | ||
|
||
from os import path | ||
import subprocess | ||
|
||
subprocess.check_call( | ||
( | ||
f"{path.join('.', 'cmd_pkgs_in_dep_order.py')}" | ||
+ f" {path.join('.', 'setup.py')} test" | ||
).split() | ||
) | ||
./parallel ./setup.py test |