Blob Blame History Raw
From 9a62c484ca9360ea8dfca82b244589c733182449 Mon Sep 17 00:00:00 2001
From: Balint Csergo <deathowlzz@gmail.com>
Date: Sat, 2 Jan 2021 16:29:06 +0000
Subject: [PATCH] move dependency management to requirements.txt and
 requirements-dev.txt. Add dockerfile and Docker related make targets

---
 Dockerfile           | 31 +++++++++++++++++++++++++++++++
 MANIFEST.in          |  4 +++-
 Makefile             | 42 +++++++++++++++++++++++++++++++++++++++++-
 requirements-dev.txt | 11 +++++++++++
 requirements.txt     |  4 ++++
 setup.py             | 23 ++++-------------------
 6 files changed, 94 insertions(+), 21 deletions(-)
 create mode 100644 Dockerfile
 create mode 100644 requirements-dev.txt
 create mode 100644 requirements.txt

diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..5025a24
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,31 @@
+# set base image (host OS)
+FROM python:3.8
+
+# set the working directory in the container
+WORKDIR /code
+
+# install make 
+RUN apt-get update && apt-get install -y \
+  make \
+  && rm -rf /var/lib/apt/lists/*
+# copy the dependencies file to the working directory
+COPY requirements.txt .
+# copy the dev-dependencies file to the working directory
+
+COPY requirements-dev.txt .
+
+# install dependencies
+RUN pip install -r requirements.txt
+# install dev dependencies
+RUN pip install -r requirements-dev.txt
+
+
+# copy the source to container working directory
+COPY testslide ./testslide
+COPY tests ./tests
+COPY util ./util
+COPY Makefile .
+COPY mypy.ini .
+
+# command to run on container start
+CMD ["/usr/bin/make", "tests"]
\ No newline at end of file
diff --git a/MANIFEST.in b/MANIFEST.in
index fbc3a03..5967ac4 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -2,4 +2,6 @@ include CODE_OF_CONDUCT.md
 include CONTRIBUTING.md
 include LICENSE 
 include README.md
-include testslide/version
\ No newline at end of file
+include testslide/version
+include requirements.txt
+include requirements-dev.txt
\ No newline at end of file
diff --git a/Makefile b/Makefile
index ff80f52..9eeacdc 100644
--- a/Makefile
+++ b/Makefile
@@ -171,7 +171,12 @@ coveralls: coverage_combine
 .PHONY: install_build_deps
 install_build_deps:
 	@printf "${TERM_BRIGHT}INSTALL BUILD DEPS\n${TERM_NONE}"
-	${Q} pip install -e .[test,build]
+	${Q} pip install -r requirements-dev.txt
+
+.PHONY: install_deps
+install_deps:
+	@printf "${TERM_BRIGHT}INSTALL DEPS\n${TERM_NONE}"
+	${Q} pip install -r requirements.txt
 
 .PHONY: sdist
 sdist:
@@ -193,8 +198,43 @@ install_local: sdist
 	${Q} pip install $(DIST_TAR_GZ)
 	${Q} testslide --help
 
+.PHONY: build_dev_container
+dev_container: 
+	@printf "${TERM_BRIGHT}BUILDING DEV CONTAINER\n${TERM_NONE}"
+	${Q} docker build -t testslide-dev .
+
+.PHONY: run_tests_in_container
+run_tests_in_container: 
+	@printf "${TERM_BRIGHT}RUNNING CI IN DEV CONTAINER\n${TERM_NONE}"
+	${Q} docker run testslide-dev
+
+.PHONY: run_dev_container
+run_dev_container: build_dev_container
+	@printf "${TERM_BRIGHT}STARTING DEV CONTAINER WITH BIND-MOUNTED SOURCES\n${TERM_NONE}"
+	@docker run --rm -d --name testslide -v ${CURDIR}/testslide:/code/testslide -v ${CURDIR}/tests:/code/tests testslide-dev bash -c "while true; do sleep 30; done"
+	@printf "${TERM_BRIGHT}Container testslide is running.\n${TERM_NONE}"
+	@printf "${TERM_BRIGHT}Use make enter_dev_container to exec into it.\n${TERM_NONE}"
+	@printf "${TERM_BRIGHT}Use make kill_dev_container to terminate it.\n${TERM_NONE}"
+
+.PHONY: enter_dev_container
+enter_dev_container:
+	@printf "${TERM_BRIGHT}ENTERING DEV CONTAINER\n${TERM_NONE}"
+	@docker exec -it testslide bash
+
+
+.PHONY: kill_dev_container
+kill_dev_container:
+	@printf "${TERM_BRIGHT}KILLING DEV CONTAINER\n${TERM_NONE}"
+	@docker kill testslide
+
+.PHONY: clean_dev_container
+clean_dev_container:
+	@printf "${TERM_BRIGHT}KILLING DEV CONTAINER\n${TERM_NONE}"
+	@docker kill testslide
+
 .PHONY: ci
 ci: \
+	install_deps \
 	install_build_deps \
 	tests \
 	coverage_report \
diff --git a/requirements-dev.txt b/requirements-dev.txt
new file mode 100644
index 0000000..c84c95a
--- /dev/null
+++ b/requirements-dev.txt
@@ -0,0 +1,11 @@
+black
+coverage
+coveralls
+flake8
+isort~=5.1
+mypy==0.782
+ipython
+sphinx
+sphinx-autobuild
+sphinx-kr-theme
+twine
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..8d8242f
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,4 @@
+psutil>=5.6.7
+Pygments>=2.6.1
+typeguard>=2.10.0
+dataclasses==0.6; python_version < "3.7"
\ No newline at end of file
diff --git a/setup.py b/setup.py
index 0ea426d..36ba085 100644
--- a/setup.py
+++ b/setup.py
@@ -7,6 +7,8 @@
 
 version = open("testslide/version").read().rstrip()
 readme = open("README.md", encoding="utf8").read()
+requirements = open("requirements.txt", encoding="utf8").readlines()
+requirements_build = open("requirements-dev.txt", encoding="utf8").readlines()
 
 setup(
     name="TestSlide",
@@ -20,29 +22,12 @@
     long_description=readme,
     long_description_content_type="text/markdown",
     setup_requires=["setuptools>=38.6.0"],
-    install_requires=[
-        "psutil>=5.6.7",
-        "Pygments>=2.6.1",
-        "typeguard>=2.10.0",
-        'dataclasses==0.6; python_version < "3.7"',
-    ],
+    install_requires=requirements,
     package_data={
         'testslide': ['py.typed'],
     },
     extras_require={
-        "build": [
-            "black",
-            "coverage",
-            "coveralls",
-            "flake8",
-            "isort~=5.1",
-            "mypy==0.782",
-            "ipython",
-            "sphinx",
-            "sphinx-autobuild",
-            "sphinx-kr-theme",
-            "twine",
-        ]
+        "build": requirements_build
     },
     classifiers=[
         "Development Status :: 5 - Production/Stable",