Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions deploy.py
Original file line number Diff line number Diff line change
@@ -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()
20 changes: 20 additions & 0 deletions tests/test_deploy_import.py
Original file line number Diff line number Diff line change
@@ -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)
Loading