Reproducing toolbox setup.py changes at engine template. Each engine … (#105)
* Reproducing toolbox setup.py changes at engine template. Each engine will install its own dependencies. close #104
* some adjustments in toolbox and template makefiles #104
* Removing some commands by install mode (dev and prod) #104
* Moving autocomplete and notebook extension from toolbox setup to engine template setup. Close #107
diff --git a/Makefile b/Makefile
index ce91362..84ce1ef 100644
--- a/Makefile
+++ b/Makefile
@@ -12,11 +12,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-.PHONY: help marvin update clean-pyc clean-build clean-reports clean-deps clean grpc distribution
+.PHONY: help marvin marvin-prod update clean-pyc clean-build clean-reports clean-deps clean grpc distribution
help:
@echo " marvin"
@echo " Prepare project to be used as a marvin package."
+ @echo " marvin-prod"
+ @echo " Prepare project to be used in production environment."
@echo " update"
@echo " Reinstall requirements and setup.py dependencies."
@echo " clean-all"
@@ -36,13 +38,15 @@
marvin:
pip install -e ".[testing]" --process-dependency-links
+ touch .dev
marvin --help
update:
pip install -e . --process-dependency-links -U
marvin-prod:
- pip install -e . --process-dependency-links
+ pip install . --process-dependency-links
+ rm -f .dev
marvin --help
clean-pyc:
@@ -51,6 +55,7 @@
find . -name '*~' -exec rm -f {} +
clean-build:
+ rm -f .prod
rm -rf *.egg-info
rm -rf .cache
rm -rf .eggs
diff --git a/marvin_python_toolbox/management/__init__.py b/marvin_python_toolbox/management/__init__.py
index b4bc5c9..a4ce0ca 100644
--- a/marvin_python_toolbox/management/__init__.py
+++ b/marvin_python_toolbox/management/__init__.py
@@ -38,9 +38,12 @@
logger = get_logger('management')
+TOOL_EXCLUDE = ['engine-server', 'engine-dryrun', 'engine-httpserver', 'engine-grpcserver', 'engine-deploy', 'engine-httpserver-remote', 'pkg-showversion']
+PROD_EXCLUDE = ['test', 'test-tdd', 'test-tox', 'test-checkpep8', 'lab', 'notebook', 'pkg-bumpversion', 'pkg-createtag', 'pkg-showchanges', 'pkg-showinfo', 'pkg-updatedeps']
+
EXCLUDE_BY_TYPE = {
'python-engine': ['engine-generate', 'engine-generateenv'],
- 'tool': ['engine-server', 'engine-dryrun', 'engine-httpserver', 'engine-grpcserver', 'engine-deploy', 'engine-httpserver-remote']
+ 'tool': TOOL_EXCLUDE
}
@@ -66,6 +69,10 @@
if exclude is None:
exclude = EXCLUDE_BY_TYPE.get(type_, [])
+ mode_file = os.path.join(base_path, '.dev')
+ if type_ == 'tool' and not os.path.exists(mode_file):
+ exclude = exclude + PROD_EXCLUDE
+
if config is None:
# Find the ini directory
inifilename = 'marvin.ini'
diff --git a/marvin_python_toolbox/management/templates/python-engine/Makefile b/marvin_python_toolbox/management/templates/python-engine/Makefile
index a12bc9c..ba3aac7 100644
--- a/marvin_python_toolbox/management/templates/python-engine/Makefile
+++ b/marvin_python_toolbox/management/templates/python-engine/Makefile
@@ -1,4 +1,4 @@
-.PHONY: help marvin update clean-pyc clean-build clean-reports clean-deps clean docker-build docker-push docker-run
+.PHONY: help marvin marvin-prod update clean-pyc clean-build clean-reports clean-deps clean docker-build docker-push docker-run
DOCKER_VERSION?=0.00.01
DOCKER_REGISTRY_ADRESS?=docker.registry.io
@@ -9,6 +9,8 @@
help:
@echo " marvin"
@echo " Prepare project to be used as a marvin package."
+ @echo " marvin-prod"
+ @echo " Prepare project to be used in production environment."
@echo " update"
@echo " Reinstall requirements and setup.py dependencies."
@echo " clean"
@@ -29,7 +31,11 @@
@echo " Runs the docker run command with marvin env default parameters."
marvin:
- pip install -e . --process-dependency-links
+ pip install -e ".[testing]" --process-dependency-links
+ marvin --help
+
+marvin-prod:
+ pip install . --process-dependency-links
marvin --help
update:
diff --git a/marvin_python_toolbox/management/templates/python-engine/setup.py b/marvin_python_toolbox/management/templates/python-engine/setup.py
index db98f7d..9cc229b 100644
--- a/marvin_python_toolbox/management/templates/python-engine/setup.py
+++ b/marvin_python_toolbox/management/templates/python-engine/setup.py
@@ -1,10 +1,22 @@
from __future__ import print_function
+import os
+import shutil
from os.path import dirname, join
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
+from setuptools.command.develop import develop as _develop
+from setuptools.command.install import install as _install
+REQUIREMENTS_TESTS = [
+ 'pytest>=2.6.4',
+ 'pytest-cov>=1.8.1',
+ 'mock>=2.0.0',
+ 'virtualenv>=15.0.1',
+ 'tox>=2.2.0',
+]
+
def _get_version():
"""Return the project version from VERSION file."""
@@ -13,6 +25,84 @@
return version
+def _hooks(dir):
+ _set_autocomplete()
+ _install_notebook_extension()
+
+
+def _set_autocomplete():
+ import marvin_python_toolbox as toolbox
+ virtualenv = os.environ.get('VIRTUAL_ENV', None)
+
+ if virtualenv:
+ postactivate = os.path.join(virtualenv, 'bin', 'postactivate')
+
+ if os.path.exists(postactivate):
+ shutil.copy(
+ os.path.join(toolbox.__path__[0], 'extras', 'marvin_bash_completion'),
+ os.path.join(virtualenv, 'marvin_bash_completion')
+ )
+
+ command = 'source "{}"'.format(os.path.join(virtualenv, 'marvin_bash_completion'))
+
+ with open(postactivate, 'r+') as fp:
+ lines = fp.readlines()
+ fp.seek(0)
+ configured = False
+ for line in lines:
+ if 'marvin_bash_completion' in line:
+ # Replacing old autocomplete configuration
+ fp.write(command)
+ configured = True
+ else:
+ fp.write(line)
+
+ if not configured:
+ fp.write(command)
+ # 'Autocomplete was successfully configured'
+ fp.write('\n')
+ fp.truncate()
+
+
+def _install_notebook_extension():
+ import marvin_python_toolbox as toolbox
+
+ install_command = [
+ "jupyter",
+ "nbextension",
+ "install",
+ os.path.join(toolbox.__path__[0], 'extras', 'notebook_extensions', 'main.js'),
+ "--destination",
+ "marvin.js",
+ "--sys-prefix",
+ "--overwrite"
+ ]
+
+ os.system(' '.join(install_command))
+
+ enable_command = [
+ "jupyter",
+ "nbextension",
+ "enable",
+ "marvin",
+ "--sys-prefix"
+ ]
+
+ os.system(' '.join(enable_command))
+
+
+class develop(_develop):
+ def run(self):
+ _develop.run(self)
+ self.execute(_hooks, (self.install_lib,), msg="Running develop preparation task")
+
+
+class install(_install):
+ def run(self):
+ _install.run(self)
+ self.execute(_hooks, (self.install_lib,), msg="Running install preparation task")
+
+
class Tox(TestCommand):
"""Run the test cases using TOX command."""
@@ -75,14 +165,11 @@
'marvin-python-toolbox==0.0.3',
'Fabric==1.14.0',
],
- tests_require=[
- 'pytest>=2.6.4',
- 'pytest-cov>=1.8.1',
- 'mock>=2.0.0',
- 'virtualenv>=15.0.1',
- 'tox>=2.2.0',
- ],
+ tests_require=REQUIREMENTS_TESTS,
+ extras_require={
+ 'testing': REQUIREMENTS_TESTS,
+ },
cmdclass={
- 'test': Tox,
+ 'test': Tox, 'develop': develop, 'install': install
},
)
diff --git a/setup.py b/setup.py
index 94e5efd..7c730ce 100644
--- a/setup.py
+++ b/setup.py
@@ -22,9 +22,6 @@
from setuptools import setup, find_packages
from setuptools.command.test import test as TestCommand
-from setuptools.command.develop import develop as _develop
-from setuptools.command.install import install as _install
-import shutil
# Package basic info
PACKAGE_NAME = 'marvin_python_toolbox'
@@ -110,83 +107,6 @@
return version
-def _hooks(dir):
- _set_autocomplete()
- _install_notebook_extension()
-
-
-def _set_autocomplete():
- virtualenv = os.environ.get('VIRTUAL_ENV', None)
-
- if virtualenv:
- postactivate = os.path.join(virtualenv, 'bin', 'postactivate')
-
- if os.path.exists(postactivate):
- shutil.copy(
- os.path.join('marvin_python_toolbox', 'extras', 'marvin_bash_completion'),
- os.path.join(virtualenv, 'marvin_bash_completion')
- )
-
- command = 'source "{}"'.format(os.path.join(virtualenv, 'marvin_bash_completion'))
-
- with open(postactivate, 'r+') as fp:
- lines = fp.readlines()
- fp.seek(0)
- configured = False
- for line in lines:
- if 'marvin_bash_completion' in line:
- # Replacing old autocomplete configuration
- fp.write(command)
- configured = True
- else:
- fp.write(line)
-
- if not configured:
- fp.write(command)
- # 'Autocomplete was successfully configured'
- fp.write('\n')
- fp.truncate()
-
-
-def _install_notebook_extension():
- import marvin_python_toolbox as toolbox
-
- install_command = [
- "jupyter",
- "nbextension",
- "install",
- os.path.join(toolbox.__path__[0], 'extras', 'notebook_extensions', 'main.js'),
- "--destination",
- "marvin.js",
- "--sys-prefix",
- "--overwrite"
- ]
-
- os.system(' '.join(install_command))
-
- enable_command = [
- "jupyter",
- "nbextension",
- "enable",
- "marvin",
- "--sys-prefix"
- ]
-
- os.system(' '.join(enable_command))
-
-
-class develop(_develop):
- def run(self):
- _develop.run(self)
- self.execute(_hooks, (self.install_lib,), msg="Running develop preparation task")
-
-
-class install(_install):
- def run(self):
- _install.run(self)
- self.execute(_hooks, (self.install_lib,), msg="Running install preparation task")
-
-
class Tox(TestCommand):
"""Run the test cases using TOX command."""
user_options = [('tox-args=', 'a', "Arguments to pass to tox")]
@@ -256,5 +176,5 @@
},
dependency_links=DEPENDENCY_LINKS_EXTERNAL,
scripts=SCRIPTS,
- cmdclass={'test': Tox, 'develop': develop, 'install': install},
+ cmdclass={'test': Tox},
)