diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..7ca3f02 --- /dev/null +++ b/.coveralls.yml @@ -0,0 +1,2 @@ +service_name: travis-pro +repo_token: q6MDH1GuPSnyzcenp5tuFq3qO8rM5XiBm \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..776aeb9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ + +\.vscode/ + +\.DS_Store + +*/__pycache__/* +**/__pycache__/* \ No newline at end of file diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1ce80a0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,35 @@ +dist: trusty +sudo: false +git: + depth: false +env: + global: + - CC_TEST_REPORTER_ID=53eef44d00d3465aeaf806ea310cfc5497e7473d13ae05fbc753890c39712c60 +addons: + sonarcloud: + organization: "lucacappelletti94-github" + token: + secure: "VZoBh0CW+W8IP5f6yeTwYQ54R6Rth8asJaPcVK8xwdCH0C69/QXG1AwMn/B9ccUN0QpiMxcJp/fcYBHGmYaCzEKsXMxd7iL3CI3jn4CC7XpEN4qBzkMcxfp8mjMegkXAjXb6ZutTTZ+0F2I1SRHmgcDpyUHL7xdQEHNXu3EAj05+Ez3EtsEE2g7J3AhVXlDAI6CWxE0KoxRlTGpkOalsjdoh4wPDESJ1xQz5+BnbUCiACOCxC4nk9BU3Cs7FY5b3EakwyetoA/YcviItVzbKd5+Aq57KDKMpwwKQyazvxaJA8yjgkmCHq79NB2wzfCtN02uuCMrQqVfXUFDAKSJLkrKfl6h4bmhAPJ8HPt1oQo5FON2EHYX4qN/JOXV1viaqtMqBLz6QOHllXMNJrz0BuktjS7lsV6a/52OjDurVEc+DXHwwiJxg4nOCTjanqZm6OueZ/DUIIiSHmVcNz4BevHhXLf4c5TSUKdYVPz9+Zzg2tf/wa6IRpBVvq76dp+T65rDUQqU+NwpzQgT5cedFF/oh5Ciiu+FI7cHGXJtCSEu3mV90QfABbb5f3wE5sXIEUKVVm227Sh8xbD3Pd+rG/z6ty9Xr906qA45nsZrl/tmAtwjXfQ0vB+N+QsUFXrgCce8jWMIdqlU0uaVSSyljPRVwLQxYMIr4SuNuYTX8tlA=" +language: python +python: +- '3.6' +before_install: + - pip install --upgrade pytest +install: +- pip install .[test] +before_script: + - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + - chmod +x ./cc-test-reporter + - ./cc-test-reporter before-build +after_script: + - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT +script: +- rm -rf .coverage +- coverage erase +- pytest --cov=environments_utils --cov-report xml:coverage.xml +- coverage report +- coverage xml +- sonar-scanner + +after_success: + - coveralls \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 88e1708..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# environments_utils -Utilities to identify which environments is your python script running within. diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..cb118c1 --- /dev/null +++ b/README.rst @@ -0,0 +1,56 @@ +environments_utils +===================================================================================== +|travis| |sonar_quality| |sonar_maintainability| |sonar_coverage| |code_climate_maintainability| |pip| + +Utilities to identify which environments is your python script running within. + +How do I get this? +---------------------------------- +As usual, just run pip: + +.. code:: bash + + pip install environments_utils + + +is_tmux +----------------------------------- +Return a boolean representing if script is running within a TMUX-like terminal. + +.. code:: python + + from environments_utils import is_tmux + + if not is_tmux(): + print("This script is long running, consider starting it within a TMUX-like terminal.") + +is_notebook +----------------------------------- +Return a boolean representing if script is running within a jupyter notebook. + +.. code:: python + + from environments_utils import is_notebook + from tqdm import tqdm_notebook, tqdm as tqdm_cli + + tqdm = tqdm_notebook if is_notebook() else tqdm_cli + + +.. |travis| image:: https://travis-ci.org/LucaCappelletti94/environments_utils.png + :target: https://travis-ci.org/LucaCappelletti94/environments_utils + +.. |sonar_quality| image:: https://sonarcloud.io/api/project_badges/measure?project=LucaCappelletti94_environments_utils&metric=alert_status + :target: https://sonarcloud.io/dashboard/index/LucaCappelletti94_environments_utils + +.. |sonar_maintainability| image:: https://sonarcloud.io/api/project_badges/measure?project=LucaCappelletti94_environments_utils&metric=sqale_rating + :target: https://sonarcloud.io/dashboard/index/LucaCappelletti94_environments_utils + +.. |sonar_coverage| image:: https://sonarcloud.io/api/project_badges/measure?project=LucaCappelletti94_environments_utils&metric=coverage + :target: https://sonarcloud.io/dashboard/index/LucaCappelletti94_environments_utils + +.. |code_climate_maintainability| image:: https://api.codeclimate.com/v1/badges/25fb7c6119e188dbd12c/maintainability + :target: https://codeclimate.com/github/LucaCappelletti94/environments_utils/maintainability + :alt: Maintainability + +.. |pip| image:: https://badge.fury.io/py/environments_utils.svg + :target: https://badge.fury.io/py/environments_utils \ No newline at end of file diff --git a/environments_utils/__init__.py b/environments_utils/__init__.py new file mode 100644 index 0000000..52dc015 --- /dev/null +++ b/environments_utils/__init__.py @@ -0,0 +1,5 @@ +from .is_notebook import is_notebook +from .is_tmux import is_tmux + + +__all__ = ["is_notebook", "is_tmux"] \ No newline at end of file diff --git a/environments_utils/__version__.py b/environments_utils/__version__.py new file mode 100644 index 0000000..d538f87 --- /dev/null +++ b/environments_utils/__version__.py @@ -0,0 +1 @@ +__version__ = "1.0.0" \ No newline at end of file diff --git a/environments_utils/is_notebook.py b/environments_utils/is_notebook.py new file mode 100644 index 0000000..19f7d0f --- /dev/null +++ b/environments_utils/is_notebook.py @@ -0,0 +1,7 @@ +def is_notebook()->bool: + """Return a boolean representing if script is running within a jupyter notebook.""" + try: + return get_ipython().__class__.__name__ == 'ZMQInteractiveShell' + except NameError: + pass + return False \ No newline at end of file diff --git a/environments_utils/is_tmux.py b/environments_utils/is_tmux.py new file mode 100644 index 0000000..913c402 --- /dev/null +++ b/environments_utils/is_tmux.py @@ -0,0 +1,5 @@ +import os + +def is_tmux()->bool: + """Return a boolean representing if script is running within a TMUX-like terminal.""" + return "TMUX" in os.environ \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..e0ba303 --- /dev/null +++ b/setup.py @@ -0,0 +1,84 @@ +import os +import re +import sys +# To use a consistent encoding +from codecs import open +from os import path + +from setuptools import find_packages, setup + +here = path.abspath(path.dirname(__file__)) + +# Get the long description from the relevant file +with open(path.join(here, 'README.rst'), encoding='utf-8') as f: + long_description = f.read() + + +def read(*parts): + with open(os.path.join(here, *parts), 'r') as fp: + return fp.read() + + +def find_version(*file_paths): + version_file = read(*file_paths) + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + + +__version__ = find_version("environments_utils", "__version__.py") + +test_deps = ['pytest', 'pytest-cov', 'coveralls', 'validate_version_code'] + +extras = { + 'test': test_deps, +} + +setup( + name='environments_utils', + + # Versions should comply with PEP440. For a discussion on single-sourcing + # the version across setup.py and the project code, see + # https://packaging.python.org/en/latest/single_source_version.html + version=__version__, + + description='Utilities to identify which environments is your python script running within.', + long_description=long_description, + + # The project's main homepage. + url='https://github.com/LucaCappelletti94/environments_utils', + + # Author details + author='Luca Cappelletti', + author_email='cappelletti.luca94@gmail.com', + + # Choose your license + license='MIT', + + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + # How mature is this project? Common values are + # 3 - Alpha + # 4 - Beta + # 5 - Production/Stable + 'Development Status :: 5 - Production/Stable', + + # Pick your license as you wish (should match "license" above) + 'License :: OSI Approved :: MIT License', + + # Specify the Python versions you support here. In particular, ensure + # that you indicate whether you support Python 2, Python 3 or both. + 'Programming Language :: Python :: 3' + ], + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + packages=find_packages(exclude=['contrib', 'docs', 'tests*']), + + # List run-time dependencies here. These will be installed by pip when + # your project is installed. For an analysis of "install_requires" vs pip's + # requirements files see: + # https://packaging.python.org/en/latest/requirements.html + tests_require=test_deps, + extras_require=extras, +) \ No newline at end of file diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..e0ab9b7 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,23 @@ +# ===================================================== +# Meta-data for the project +# ===================================================== +sonar.projectName=environments_utils +sonar.projectKey=LucaCappelletti94_environments_utils +sonar.projectVersion=1.0.0 +sonar.organization=lucacappelletti94-github +sonar.host.url=https://sonarcloud.io +sonar.login=environments_utils + +sonar.links.homepage=https://github.com/LucaCappelletti94/environments_utils +sonar.links.ci=https://travis-ci.org/LucaCappelletti94/environments_utils +sonar.links.scm=https://github.com/LucaCappelletti94/environments_utils +sonar.links.issue=https://github.com/LucaCappelletti94/environments_utils/issues + +sonar.language=py + +sonar.sources=./environments_utils +sonar.tests=./tests + +sonar.exclusions=**/__pycache__/*,*/__pycache__/* + +sonar.python.coverage.reportPath=coverage.xml diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_is_notebook.py b/tests/test_is_notebook.py new file mode 100644 index 0000000..07a9464 --- /dev/null +++ b/tests/test_is_notebook.py @@ -0,0 +1,4 @@ +from environments_utils import is_notebook + +def test_is_notebook(): + is_notebook() \ No newline at end of file diff --git a/tests/test_is_tmux.py b/tests/test_is_tmux.py new file mode 100644 index 0000000..39016fe --- /dev/null +++ b/tests/test_is_tmux.py @@ -0,0 +1,4 @@ +from environments_utils import is_tmux + +def test_is_tmux(): + is_tmux() \ No newline at end of file diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..035401d --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,5 @@ +from validate_version_code import validate_version_code +from environments_utils.__version__ import __version__ + +def test_version(): + assert validate_version_code(__version__) \ No newline at end of file