|
| 1 | +from pathlib import Path |
| 2 | +import shutil |
| 3 | + |
1 | 4 | import nox |
2 | 5 |
|
3 | 6 | nox.options.stop_on_first_error = True |
|
7 | 10 |
|
8 | 11 | source_files = ("planet", "examples", "tests", "setup.py", "noxfile.py") |
9 | 12 |
|
| 13 | +BUILD_DIRS = ['build', 'dist'] |
| 14 | + |
10 | 15 |
|
11 | 16 | @nox.session |
12 | 17 | def analyze(session): |
@@ -91,3 +96,40 @@ def examples(session): |
91 | 96 | # Because these example scripts can be long-running, output the |
92 | 97 | # example's stdout so we know what's happening |
93 | 98 | session.run('pytest', '--no-cov', 'examples/', '-s', *options) |
| 99 | + |
| 100 | + |
| 101 | +@nox.session |
| 102 | +def build(session): |
| 103 | + # check preexisting |
| 104 | + exist_but_should_not = [p for p in BUILD_DIRS if Path(p).is_dir()] |
| 105 | + if exist_but_should_not: |
| 106 | + session.error( |
| 107 | + f"Pre-existing {', '.join(exist_but_should_not)}. Run clean session and try again" |
| 108 | + ) |
| 109 | + |
| 110 | + session.install('build', 'twine', 'check-wheel-contents') |
| 111 | + |
| 112 | + session.run(*'python -m build --sdist --wheel'.split()) |
| 113 | + session.run('check-wheel-contents', 'dist') |
| 114 | + |
| 115 | + |
| 116 | +@nox.session |
| 117 | +def clean(session): |
| 118 | + to_remove = [Path(d) for d in BUILD_DIRS if Path(d).is_dir()] |
| 119 | + for p in to_remove: |
| 120 | + shutil.rmtree(p) |
| 121 | + |
| 122 | + |
| 123 | +@nox.session |
| 124 | +def publish(session): |
| 125 | + missing = [p for p in BUILD_DIRS if not Path(p).is_dir()] |
| 126 | + if missing: |
| 127 | + session.error( |
| 128 | + f"Missing one or more build directories: {', '.join(missing)}. Run build session and try again" |
| 129 | + ) |
| 130 | + |
| 131 | + session.install('twine') |
| 132 | + |
| 133 | + files = [str(f) for f in Path('dist').iterdir()] |
| 134 | + session.run("twine", "check", *files) |
| 135 | + session.run("twine", "upload", "--repository=testpypi", *files) |
0 commit comments