|
1 | 1 | import re
|
| 2 | +import subprocess |
2 | 3 |
|
3 |
| -from setuptools import find_packages, setup |
| 4 | +from setuptools import Command, find_packages, setup |
4 | 5 |
|
5 | 6 | with open("requirements.txt") as f:
|
6 | 7 | requirements = f.read().splitlines()
|
|
9 | 10 | long_description = f.read()
|
10 | 11 | long_description = re.sub(r"\n!\[.*\]\(.*\)", "", long_description)
|
11 | 12 |
|
| 13 | + |
| 14 | +class BuildDockerImageCommand(Command): |
| 15 | + description = "Build Docker image for the project" |
| 16 | + user_options = [] |
| 17 | + |
| 18 | + def initialize_options(self): |
| 19 | + pass |
| 20 | + |
| 21 | + def finalize_options(self): |
| 22 | + pass |
| 23 | + |
| 24 | + def run(self): |
| 25 | + command = ["docker", "build", "--file", "docker/Dockerfile", "-t", "grep-ast-image", "."] |
| 26 | + subprocess.check_call(command) |
| 27 | + |
| 28 | + |
| 29 | +class DockerTestCommand(Command): |
| 30 | + description = "Build Docker image and run pytest inside it" |
| 31 | + user_options = [] |
| 32 | + |
| 33 | + def initialize_options(self): |
| 34 | + pass |
| 35 | + |
| 36 | + def finalize_options(self): |
| 37 | + pass |
| 38 | + |
| 39 | + def run(self): |
| 40 | + build_command = [ |
| 41 | + "docker", |
| 42 | + "build", |
| 43 | + "--file", |
| 44 | + "docker/Dockerfile", |
| 45 | + "-t", |
| 46 | + "grep-ast-image", |
| 47 | + ".", |
| 48 | + ] |
| 49 | + test_command = [ |
| 50 | + "docker", |
| 51 | + "run", |
| 52 | + "-it", |
| 53 | + "--entrypoint", |
| 54 | + "bash", |
| 55 | + "grep-ast-image", |
| 56 | + "-c", |
| 57 | + "cd /grep-ast; pytest", |
| 58 | + ] |
| 59 | + subprocess.check_call(build_command) |
| 60 | + subprocess.check_call(test_command) |
| 61 | + |
| 62 | + |
12 | 63 | setup(
|
| 64 | + cmdclass={ |
| 65 | + "build_docker": BuildDockerImageCommand, |
| 66 | + "docker_test": DockerTestCommand, |
| 67 | + }, |
13 | 68 | name="grep-ast",
|
14 | 69 | version="0.2.4",
|
15 | 70 | description="A tool to grep through the AST of a source file",
|
|
0 commit comments