diff --git a/deploy.py b/deploy.py index a8ef735..eabf0e5 100755 --- a/deploy.py +++ b/deploy.py @@ -1,12 +1,24 @@ +"""Manual build-and-upload helper. Importing this module has no side effects. + +Run it explicitly (``python deploy.py``) to build and upload to PyPI. CI (wads) +normally publishes releases, so this is only a manual fallback. +""" + import subprocess +import sys + +BUILD_COMMAND = (sys.executable, "setup.py", "sdist", "bdist_wheel") +UPLOAD_COMMAND = (sys.executable, "-m", "twine", "upload", "dist/*") + + +def main(): + # TODO: Both of these are python. Change to use python objects directly. + print("--------------------------- setup_output ---------------------------") + subprocess.run(BUILD_COMMAND) -# # TODO: Both of these are python. Change to use python objects directly. -print("--------------------------- setup_output ---------------------------") -setup_output = subprocess.run("python setup.py sdist bdist_wheel".split(" ")) -# print(f"{setup_output}\n") + print("--------------------------- upload_output ---------------------------") + subprocess.run(UPLOAD_COMMAND) -print("--------------------------- upload_output ---------------------------") -upload_output = subprocess.run("python -m twine upload dist/*".split(" ")) -# print(f"{upload_output.decode()}\n") -# import twine +if __name__ == "__main__": + main() diff --git a/tests/test_deploy_import.py b/tests/test_deploy_import.py new file mode 100644 index 0000000..d6ba518 --- /dev/null +++ b/tests/test_deploy_import.py @@ -0,0 +1,20 @@ +"""Importing the repo-root ``deploy.py`` must not build or upload anything.""" + +import importlib.util +import subprocess +from pathlib import Path + +DEPLOY_PATH = Path(__file__).resolve().parent.parent / "deploy.py" + + +def test_importing_deploy_has_no_side_effects(monkeypatch): + calls = [] + monkeypatch.setattr(subprocess, "run", lambda *a, **kw: calls.append(a)) + monkeypatch.setattr(subprocess, "Popen", lambda *a, **kw: calls.append(a)) + + spec = importlib.util.spec_from_file_location("_deploy_under_test", DEPLOY_PATH) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + + assert calls == [] + assert callable(module.main)