From 612caab2c544957801057065c2e7a4e265edc792 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 7 Oct 2021 15:53:01 -0700 Subject: [PATCH] Move package to a top-level "src" directory This helps ensure that tox tests the colorama installed to the virtualenv and not otherwise working due to the current working directory. The tests directory was moved out of the source directory to the top level. Test files don't need to be included in the installed package. They exists for developers, not end users. They still ship with the sdist so downstream packages can run the tests when re-packaging Colorama. The demos directory has been updated to work with the new directory structure. Its use is now documented in README.rst. Switch test runner to pytest in tox.ini. pytest has been moved out of the lint_python GitHub workflow as it is now covered by the test workflow. Fixes #278 --- .github/workflows/lint_python.yml | 3 +-- MANIFEST.in | 1 + README.rst | 9 +++++++++ demos/fixpath.py | 2 +- setup.py | 3 ++- {colorama => src/colorama}/__init__.py | 0 {colorama => src/colorama}/ansi.py | 0 {colorama => src/colorama}/ansitowin32.py | 0 {colorama => src/colorama}/initialise.py | 0 {colorama => src/colorama}/win32.py | 0 {colorama => src/colorama}/winterm.py | 0 {colorama/tests => tests}/__init__.py | 0 {colorama/tests => tests}/ansi_test.py | 4 ++-- {colorama/tests => tests}/ansitowin32_test.py | 2 +- {colorama/tests => tests}/initialise_test.py | 4 ++-- {colorama/tests => tests}/isatty_test.py | 2 +- {colorama/tests => tests}/utils.py | 0 {colorama/tests => tests}/winterm_test.py | 2 +- tox.ini | 6 ++++-- 19 files changed, 25 insertions(+), 13 deletions(-) rename {colorama => src/colorama}/__init__.py (100%) rename {colorama => src/colorama}/ansi.py (100%) rename {colorama => src/colorama}/ansitowin32.py (100%) rename {colorama => src/colorama}/initialise.py (100%) rename {colorama => src/colorama}/win32.py (100%) rename {colorama => src/colorama}/winterm.py (100%) rename {colorama/tests => tests}/__init__.py (100%) rename {colorama/tests => tests}/ansi_test.py (96%) rename {colorama/tests => tests}/ansitowin32_test.py (99%) rename {colorama/tests => tests}/initialise_test.py (98%) rename {colorama/tests => tests}/isatty_test.py (96%) rename {colorama/tests => tests}/utils.py (100%) rename {colorama/tests => tests}/winterm_test.py (98%) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index fb218d8..689c8c6 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -8,7 +8,7 @@ jobs: - uses: actions/setup-python@v2 - run: pip install --upgrade pip wheel - run: pip install bandit black codespell flake8 flake8-bugbear - flake8-comprehensions isort mypy pytest pyupgrade safety + flake8-comprehensions isort mypy pyupgrade safety - run: bandit --recursive --skip B311 . - run: black --check . || true - run: codespell # --ignore-words-list="" --skip="*.css,*.js,*.lock" @@ -19,6 +19,5 @@ jobs: - run: pip install -r requirements.txt - run: mkdir --parents --verbose .mypy_cache - run: mypy --ignore-missing-imports --install-types --non-interactive . || true - - run: pytest . - run: shopt -s globstar && pyupgrade --py36-plus **/*.py || true - run: safety check diff --git a/MANIFEST.in b/MANIFEST.in index 016aa76..768b83c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include LICENSE.txt CHANGELOG.rst recursive-include demos *.py *.bat *.sh +recursive-include tests *.py diff --git a/README.rst b/README.rst index 9a349ac..bc62b1a 100644 --- a/README.rst +++ b/README.rst @@ -297,6 +297,15 @@ them though. Let me know if it would be useful for you, via the Issues on GitHub. +Demos +----- + +Colorama ships with several demos that show its features. Run them the same as +any Python script:: + + $ python demos/demo01.py + + Status & Known Problems ----------------------- diff --git a/demos/fixpath.py b/demos/fixpath.py index 2df28f5..79b91e4 100644 --- a/demos/fixpath.py +++ b/demos/fixpath.py @@ -4,5 +4,5 @@ # the local source in preference to any installed version of colorama. import sys from os.path import normpath, dirname, join -local_colorama_module = normpath(join(dirname(__file__), '..')) +local_colorama_module = normpath(join(dirname(__file__), '..', 'src')) sys.path.insert(0, local_colorama_module) diff --git a/setup.py b/setup.py index 4221fe1..ad1d7ea 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ def get_version(path): setup( name=NAME, - version=get_version(os.path.join('colorama', '__init__.py')), + version=get_version(os.path.join('src', 'colorama', '__init__.py')), description='Cross-platform colored terminal text.', long_description=read_file('README.rst'), keywords='color colour terminal text ansi windows crossplatform xplatform', @@ -43,6 +43,7 @@ def get_version(path): url='https://github.com/tartley/colorama', license='BSD', packages=[NAME], + package_dir={"": "src"}, python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*', # see classifiers https://pypi.org/pypi?%3Aaction=list_classifiers classifiers=[ diff --git a/colorama/__init__.py b/src/colorama/__init__.py similarity index 100% rename from colorama/__init__.py rename to src/colorama/__init__.py diff --git a/colorama/ansi.py b/src/colorama/ansi.py similarity index 100% rename from colorama/ansi.py rename to src/colorama/ansi.py diff --git a/colorama/ansitowin32.py b/src/colorama/ansitowin32.py similarity index 100% rename from colorama/ansitowin32.py rename to src/colorama/ansitowin32.py diff --git a/colorama/initialise.py b/src/colorama/initialise.py similarity index 100% rename from colorama/initialise.py rename to src/colorama/initialise.py diff --git a/colorama/win32.py b/src/colorama/win32.py similarity index 100% rename from colorama/win32.py rename to src/colorama/win32.py diff --git a/colorama/winterm.py b/src/colorama/winterm.py similarity index 100% rename from colorama/winterm.py rename to src/colorama/winterm.py diff --git a/colorama/tests/__init__.py b/tests/__init__.py similarity index 100% rename from colorama/tests/__init__.py rename to tests/__init__.py diff --git a/colorama/tests/ansi_test.py b/tests/ansi_test.py similarity index 96% rename from colorama/tests/ansi_test.py rename to tests/ansi_test.py index 0a20c80..d2ec1cc 100644 --- a/colorama/tests/ansi_test.py +++ b/tests/ansi_test.py @@ -2,8 +2,8 @@ import sys from unittest import TestCase, main -from ..ansi import Back, Fore, Style -from ..ansitowin32 import AnsiToWin32 +from colorama.ansi import Back, Fore, Style +from colorama.ansitowin32 import AnsiToWin32 stdout_orig = sys.stdout stderr_orig = sys.stderr diff --git a/colorama/tests/ansitowin32_test.py b/tests/ansitowin32_test.py similarity index 99% rename from colorama/tests/ansitowin32_test.py rename to tests/ansitowin32_test.py index bbe99f4..c7012f4 100644 --- a/colorama/tests/ansitowin32_test.py +++ b/tests/ansitowin32_test.py @@ -7,7 +7,7 @@ except ImportError: from mock import MagicMock, Mock, patch -from ..ansitowin32 import AnsiToWin32, StreamWrapper +from colorama.ansitowin32 import AnsiToWin32, StreamWrapper from .utils import osname diff --git a/colorama/tests/initialise_test.py b/tests/initialise_test.py similarity index 98% rename from colorama/tests/initialise_test.py rename to tests/initialise_test.py index 7bbd18f..626db06 100644 --- a/colorama/tests/initialise_test.py +++ b/tests/initialise_test.py @@ -7,8 +7,8 @@ except ImportError: from mock import patch -from ..ansitowin32 import StreamWrapper -from ..initialise import init +from colorama.ansitowin32 import StreamWrapper +from colorama.initialise import init from .utils import osname, replace_by orig_stdout = sys.stdout diff --git a/colorama/tests/isatty_test.py b/tests/isatty_test.py similarity index 96% rename from colorama/tests/isatty_test.py rename to tests/isatty_test.py index 0f84e4b..82bfee0 100644 --- a/colorama/tests/isatty_test.py +++ b/tests/isatty_test.py @@ -2,7 +2,7 @@ import sys from unittest import TestCase, main -from ..ansitowin32 import StreamWrapper, AnsiToWin32 +from colorama.ansitowin32 import StreamWrapper, AnsiToWin32 from .utils import pycharm, replace_by, replace_original_by, StreamTTY, StreamNonTTY diff --git a/colorama/tests/utils.py b/tests/utils.py similarity index 100% rename from colorama/tests/utils.py rename to tests/utils.py diff --git a/colorama/tests/winterm_test.py b/tests/winterm_test.py similarity index 98% rename from colorama/tests/winterm_test.py rename to tests/winterm_test.py index d0955f9..378e967 100644 --- a/colorama/tests/winterm_test.py +++ b/tests/winterm_test.py @@ -7,7 +7,7 @@ except ImportError: from mock import Mock, patch -from ..winterm import WinColor, WinStyle, WinTerm +from colorama.winterm import WinColor, WinStyle, WinTerm class WinTermTest(TestCase): diff --git a/tox.ini b/tox.ini index 721d811..313e5a1 100644 --- a/tox.ini +++ b/tox.ini @@ -2,5 +2,7 @@ envlist = py27, py35, py36, py37, py38, py39, py310, pypy, pypy3 [testenv] -deps = py27,pypy: mock -commands = python -m unittest discover -p *_test.py +deps = + pytest + py27,pypy: mock +commands = pytest