diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8b3b61b --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.pyc +*.egg-info +*.tar.gz +*.coverage +.output +/dist +/build diff --git a/README.md b/README.md index 548a313..2790003 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ -# tempypy -Quick and Easy Temporary python virtual environments +tempyenv +===================== + +Description +=========== + +tempyenv sets up a python environment in a temporary path. Quick way to create a throw away python environment. + +[![Build Status](https://app.travis-ci.com/outbit/tempyenv.svg?branch=develop "ansible-docs latest build")](http://travis-ci.org/outbit/tempyenv) +[![PIP Version](https://img.shields.io/pypi/v/tempyenv.svg "tempyenv PyPI version")](https://pypi.python.org/pypi/tempyenv) +[![Coverage Status](https://coveralls.io/repos/outbit/tempyenv/badge.svg?branch=develop&service=github)](https://coveralls.io/github/outbit/tempyenv?branch=develop) +[![Gitter IM](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/outbit/tempyenv) + + +Installation +=========== + +```shell +$ python -m pip install tempyenv +``` + +Usage +=========== + +```shell +$ tempyenv +``` + +License +======= + +tempyenv is released under the [MIT License](LICENSE.md). + +Author +====== + +David Whiteside () diff --git a/howto_publish_new_release.md b/howto_publish_new_release.md new file mode 100644 index 0000000..baa9ef6 --- /dev/null +++ b/howto_publish_new_release.md @@ -0,0 +1,40 @@ +Build new release +=== + +```bash +git checkout master +git merge develop --no-ff +git push +git tag vX.Y.Z +git push origin vX.Y.Z +``` + +- Publish a release on github.com + +Follow instructions to build and publish to pypi +=== + +```bash +# Setup your ~/.pypirc +[distutils] +index-servers = + tempyenv + tempyenv-test + +[tempyenv] +repository = https://upload.pypi.org/legacy/ +username = xyz +password = xyz + +[tempyenv-test] +repository = https://test.pypi.org/legacy/ +username = xyz +password = xyz + +# Build +python setup.py bdist_wheel --universal + +# Upload +rm -f dist/* +twine upload --repository-url https://upload.pypi.org/legacy/ dist/tempyenv-* +``` diff --git a/lib/tempyenv/__init__.py b/lib/tempyenv/__init__.py new file mode 100644 index 0000000..be3a6d3 --- /dev/null +++ b/lib/tempyenv/__init__.py @@ -0,0 +1,2 @@ +__version__ = '1.0.0' +__author__ = 'David Whiteside' diff --git a/lib/tempyenv/cli.py b/lib/tempyenv/cli.py new file mode 100644 index 0000000..8f9b8d0 --- /dev/null +++ b/lib/tempyenv/cli.py @@ -0,0 +1,41 @@ +import tempfile +import subprocess +import os +import sys + +class TemporaryVenvCreator: + def __init__(self): + self.temp_dir = None + self.venv_path = None + + def create_temporary_directory(self): + self.temp_dir = tempfile.TemporaryDirectory(delete=False) + self.venv_path = os.path.join(self.temp_dir.name, 'venv') + + def create_virtual_environment(self): + try: + subprocess.run(['python3', '-m', 'venv', self.venv_path], check=True) + print(f"Virtual environment created at {self.venv_path}") + except subprocess.CalledProcessError as e: + print(f"Error creating virtual environment: {e}") + + def load_virtual_environment(self): + try: + print(f"Virtual environment loading from {self.venv_path}") + #current_shell = os.environ.get("SHELL") # Currently just support bash + current_shell = "bash" + subprocess.run([f"{current_shell}", + "-c", + f"source {self.venv_path}/bin/activate && export PS1=\"(tempyenv)$PS1\\$ \" && {current_shell}"], + stdin=sys.stdin, + stdout=sys.stdout, + stderr=sys.stderr) + except subprocess.CalledProcessError as e: + print(f"Error loading virtual environment: {e}") + +if __name__ == "__main__": + venv_creator = TemporaryVenvCreator() + venv_creator.create_temporary_directory() + venv_creator.create_virtual_environment() + venv_creator.load_virtual_environment() + diff --git a/run_tests.sh b/run_tests.sh new file mode 100755 index 0000000..ff95c93 --- /dev/null +++ b/run_tests.sh @@ -0,0 +1,3 @@ +#!/bin/bash +export PYTHONPATH="${PYTHONPATH}:./lib" +coverage run --source=ansibledocgen -m unittest discover test/units/ diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..b88034e --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description-file = README.md diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..7847098 --- /dev/null +++ b/setup.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python + +import os +import sys + +sys.path.insert(0, os.path.abspath('lib')) +from tempyenv import __version__, __author__ + +from pathlib import Path +this_directory = Path(__file__).parent +long_description = (this_directory / "README.md").read_text() + +try: + from setuptools import setup, find_packages +except ImportError: + print("tempyenv needs setuptools in order to build. Install it using" + " your package manager (usually python-setuptools) or via pip (pip" + " install setuptools).") + sys.exit(1) + +setup( + name='tempyenv', + version=__version__, + description='Easiest and quickest way to setup a temporary python virtual environment', + long_description=long_description, + long_description_content_type='text/markdown', + author=__author__, + author_email='david@davidwhiteside.com', + url='https://github.com/outbit/tempyenv', + license='MIT', + install_requires=[ + 'setuptools'], + include_package_data=True, + package_dir={ + '': 'lib'}, + package_data = { '': ['*.j2']}, + packages=find_packages('lib'), + classifiers=[ + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Intended Audience :: Information Technology', + 'Intended Audience :: System Administrators', + 'License :: OSI Approved :: MIT License', + 'Natural Language :: English', + 'Operating System :: POSIX', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3 :: Only', + 'Topic :: System :: Installation/Setup', + 'Topic :: System :: Systems Administration', + 'Topic :: Utilities', + ], + python_requires='>=3.7', + entry_points={ + 'console_scripts': [ + 'tempyenv = tempyenv.cli:main' + ] + }, + data_files=[], +) diff --git a/test/units/test.py b/test/units/test.py new file mode 100644 index 0000000..e69de29