Skip to content

Commit

Permalink
Merge pull request #116 from willmcgugan/dev
Browse files Browse the repository at this point in the history
Local development environment improvements
  • Loading branch information
willmcgugan committed Jun 21, 2020
2 parents fb1a69c + f1c335f commit 03a5213
Show file tree
Hide file tree
Showing 50 changed files with 160 additions and 129 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/pythonpackage.yml
Expand Up @@ -4,10 +4,11 @@ on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 4
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.6, 3.7, 3.8]

steps:
Expand All @@ -19,14 +20,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
poetry install
- name: Typecheck with mypy
run: |
pip install mypy==0.770
make typecheck
- name: Test with pytest
run: |
pip install poetry pytest
poetry install
pip install .
pytest tests/ -v
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.2.4] - 2020-06-21

### Added

- Added enable_link_path to RichHandler
- Added legacy_windows switch to Console contstructor

## [2.2.3] - 2020-06-15

### Fixed
Expand Down
48 changes: 48 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,48 @@
# Contributing to Rich

This project welcomes contributions in the form of Pull Requests. For clear bug-fixes / typos etc. just submit a PR. For new features or if there is any doubt in how to fix a bug, you might want to open an issue prior to starting work, or email willmcgugan+rich@gmail.com to discuss it first.

## Development Environment

To start developing with Rich, first create a _virtual environment_ then run the following to install development requirements:

```
pip install -r requirements-dev.txt
poetry install
```

### Tests

Run tests with the following command:

```
make test
```

Or if you don't have make, run the following:

```
pytest --cov-report term-missing --cov=rich tests/ -vv
```

New code should ideally have tests and not break existing tests.

### Type Checking

Rich uses type annotations throughout, and `mypy` to do the checking. Run the following to type check Rich:

```
make typecheck
```

Or if you don't have `make`:

```
mypy -p rich --ignore-missing-imports --warn-unreachable
```

Please add type annotations for all new code.

### Code Formatting

Rich uses `black` for code formatting. I recommend setting up black in your editor to format on save.
2 changes: 0 additions & 2 deletions Makefile
Expand Up @@ -4,8 +4,6 @@ typecheck:
mypy -p rich --ignore-missing-imports --warn-unreachable
typecheck-report:
mypy -p rich --ignore-missing-imports --warn-unreachable --html-report mypy_report
pytype:
pytype --config=pytype.cfg
.PHONY: docs
docs:
cd docs; make html
3 changes: 0 additions & 3 deletions README.md
@@ -1,8 +1,5 @@
[![PyPI version](https://badge.fury.io/py/rich.svg)](https://badge.fury.io/py/rich)
[![PyPI](https://img.shields.io/pypi/pyversions/rich.svg)](https://pypi.org/project/rich/)
[![Downloads](https://pepy.tech/badge/rich/month)](https://pepy.tech/project/rich/month)
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://awesome-python.com/#command-line-interface-development)

[![Rich blog](https://img.shields.io/badge/blog-rich%20news-yellowgreen)](https://www.willmcgugan.com/tag/rich/)
[![Twitter Follow](https://img.shields.io/twitter/follow/willmcgugan.svg?style=social)](https://twitter.com/willmcgugan)

Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Expand Up @@ -2,7 +2,7 @@
name = "rich"
homepage = "https://github.com/willmcgugan/rich"
documentation = "https://rich.readthedocs.io/en/latest/"
version = "2.2.3"
version = "2.2.4"
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
authors = ["Will McGugan <willmcgugan@gmail.com>"]
license = "MIT"
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
@@ -0,0 +1,4 @@
black==19.10b0
mypy==0.781
poetry==1.0.5
pytest==5.4.3
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion rich/_log_render.py
@@ -1,5 +1,5 @@
from datetime import datetime
from typing import Any, Iterable, List, Optional, TYPE_CHECKING, Union
from typing import Iterable, List, Optional, TYPE_CHECKING, Union


from .text import Text
Expand Down
2 changes: 1 addition & 1 deletion rich/_lru_cache.py
@@ -1,5 +1,5 @@
from collections import OrderedDict
from typing import Dict, Generic, Mapping, TypeVar
from typing import Dict, Generic, TypeVar


CacheKey = TypeVar("CacheKey")
Expand Down
1 change: 0 additions & 1 deletion rich/_ratio.py
@@ -1,4 +1,3 @@
from dataclasses import dataclass
from math import ceil
from typing import List

Expand Down
3 changes: 1 addition & 2 deletions rich/align.py
Expand Up @@ -2,9 +2,8 @@

from typing_extensions import Literal
from .jupyter import JupyterMixin
from .measure import Measurement
from .segment import Segment
from .style import StyleType


if TYPE_CHECKING:
from .console import Console, ConsoleOptions, RenderResult, RenderableType
Expand Down
2 changes: 1 addition & 1 deletion rich/bar.py
@@ -1,7 +1,7 @@
from functools import lru_cache
import math
from time import monotonic
from typing import Iterable, Optional, List, Union
from typing import Iterable, Optional, List

from .color import Color, blend_rgb
from .color_triplet import ColorTriplet
Expand Down
3 changes: 1 addition & 2 deletions rich/cells.py
@@ -1,6 +1,5 @@
from functools import lru_cache
from itertools import takewhile
from typing import Dict, List, Tuple
from typing import Dict, List

from ._cell_widths import CELL_WIDTHS
from ._lru_cache import LRUCache
Expand Down
4 changes: 1 addition & 3 deletions rich/color.py
@@ -1,11 +1,9 @@
import re
from colorsys import rgb_to_hls
from dataclasses import dataclass
from enum import IntEnum
from functools import lru_cache
from math import sqrt
import platform
from typing import Iterable, List, NamedTuple, Optional, Sequence, Tuple, TYPE_CHECKING
from typing import NamedTuple, Optional, Tuple, TYPE_CHECKING

from ._palettes import STANDARD_PALETTE, EIGHT_BIT_PALETTE
from .color_triplet import ColorTriplet
Expand Down
1 change: 0 additions & 1 deletion rich/columns.py
Expand Up @@ -8,7 +8,6 @@
from .measure import Measurement
from .padding import Padding, PaddingDimensions
from .table import Table
from .text import Text
from .jupyter import JupyterMixin


Expand Down
32 changes: 13 additions & 19 deletions rich/console.py
@@ -1,14 +1,14 @@
from collections.abc import Mapping, Sequence
from contextlib import contextmanager

from dataclasses import dataclass, field, replace
from enum import Enum

from functools import wraps
import inspect
from itertools import chain

import os
from operator import itemgetter

import platform
import re

import shutil
import sys
import threading
Expand All @@ -22,38 +22,28 @@
List,
Optional,
NamedTuple,
overload,
Tuple,
TYPE_CHECKING,
Union,
)
from typing_extensions import Protocol, runtime_checkable, Literal


from ._emoji_replace import _emoji_replace

from .align import Align, AlignValues
from .markup import render as render_markup
from .measure import measure_renderables, Measurement
from ._log_render import LogRender
from .default_styles import DEFAULT_STYLES
from . import errors
from .color import ColorSystem
from .control import Control
from .highlighter import NullHighlighter, ReprHighlighter
from .pretty import Pretty
from .style import Style
from .tabulate import tabulate_mapping
from . import highlighter
from . import themes
from .pretty import Pretty
from .terminal_theme import TerminalTheme, DEFAULT_TERMINAL_THEME
from .segment import Segment
from .text import Text
from .theme import Theme

if TYPE_CHECKING: # pragma: no cover
from .text import Text

WINDOWS = platform.system() == "Windows"

Expand Down Expand Up @@ -151,10 +141,10 @@ def __rich_console__(

class RenderGroup:
"""Takes a group of renderables and returns a renderable object that renders the group.
Args:
renderables (Iterable[RenderableType]): An iterable of renderable objects.
"""

def __init__(self, *renderables: RenderableType, fit: bool = True) -> None:
Expand Down Expand Up @@ -285,7 +275,8 @@ class Console:
log_time (bool, optional): Boolean to enable logging of time by :meth:`log` methods. Defaults to True.
log_path (bool, optional): Boolean to enable the logging of the caller by :meth:`log`. Defaults to True.
log_time_format (str, optional): Log time format if ``log_time`` is enabled. Defaults to "[%X] ".
highlighter(HighlighterType, optional): Default highlighter.
highlighter (HighlighterType, optional): Default highlighter.
legacy_windows (bool, optional): Enable legacy Windows mode, or ``None`` to auto detect. Defaults to ``None``.
"""

def __init__(
Expand All @@ -309,6 +300,7 @@ def __init__(
log_path: bool = True,
log_time_format: str = "[%X]",
highlighter: Optional["HighlighterType"] = ReprHighlighter(),
legacy_windows: bool = None,
):
self.is_jupyter = force_jupyter or _is_jupyter()
if self.is_jupyter:
Expand All @@ -322,7 +314,9 @@ def __init__(
self._markup = markup
self._emoji = emoji
self._highlight = highlight
self.legacy_windows: bool = detect_legacy_windows()
self.legacy_windows: bool = (
detect_legacy_windows() if legacy_windows is None else legacy_windows
)

self._color_system: Optional[ColorSystem]
self._force_terminal = force_terminal
Expand Down
5 changes: 0 additions & 5 deletions rich/containers.py
Expand Up @@ -3,22 +3,17 @@
Iterator,
Iterable,
List,
Optional,
overload,
TypeVar,
TYPE_CHECKING,
Union,
)
from typing_extensions import Literal

from .segment import Segment
from .style import Style

if TYPE_CHECKING:
from .console import (
Console,
ConsoleOptions,
ConsoleRenderable,
JustifyMethod,
OverflowMethod,
RenderResult,
Expand Down
2 changes: 1 addition & 1 deletion rich/control.py
@@ -1,4 +1,4 @@
from typing import NamedTuple, TYPE_CHECKING
from typing import TYPE_CHECKING

from .segment import Segment

Expand Down
3 changes: 1 addition & 2 deletions rich/emoji.py
@@ -1,7 +1,6 @@
import re
from typing import Match, Union

from .console import Console, ConsoleOptions, ConsoleRenderable, RenderResult
from .console import Console, ConsoleOptions, RenderResult
from .jupyter import JupyterMixin
from .segment import Segment
from .style import Style
Expand Down
2 changes: 1 addition & 1 deletion rich/filesize.py
Expand Up @@ -11,7 +11,7 @@
"""

__all__ = ["traditional", "decimal", "binary"]
__all__ = ["decimal"]

from typing import Iterable, List, Tuple

Expand Down
2 changes: 0 additions & 2 deletions rich/highlighter.py
@@ -1,8 +1,6 @@
from abc import ABC, abstractmethod
from re import finditer
from typing import List, Union


from .text import Text


Expand Down
6 changes: 2 additions & 4 deletions rich/jupyter.py
@@ -1,14 +1,12 @@
import io
from typing import Any, Iterable, IO, List, Optional, TYPE_CHECKING, Union
from typing import Iterable, List, TYPE_CHECKING

# from .console import Console as BaseConsole
from .__init__ import get_console
from .segment import Segment
from .style import Style
from .terminal_theme import DEFAULT_TERMINAL_THEME

if TYPE_CHECKING:
from .console import Console, RenderableType
from .console import RenderableType

JUPYTER_HTML_FORMAT = """\
<pre style="white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace">{code}</pre>
Expand Down

0 comments on commit 03a5213

Please sign in to comment.