Skip to content

Commit

Permalink
Merge branch 'master' into fix_format_issues
Browse files Browse the repository at this point in the history
  • Loading branch information
astanin authored Sep 26, 2024
2 parents 218c324 + f660f66 commit f824851
Show file tree
Hide file tree
Showing 17 changed files with 583 additions and 170 deletions.
60 changes: 0 additions & 60 deletions .circleci/config.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .circleci/requirements.txt

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: lint

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh
- name: Run linters
run: |
tox -e lint
26 changes: 26 additions & 0 deletions .github/workflows/tabulate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: python-tabulate

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pytest numpy pandas
- name: Run tests
run: |
pytest -v --doctest-modules --ignore benchmark.py
2 changes: 1 addition & 1 deletion HOWTOPUBLISH
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# update contributors and CHANGELOG in README
# tag version release
python3 benchmark.py # then update README
tox -e py37-extra,py38-extra,py39-extra,py310-extra
tox -e py38-extra,py39-extra,py310-extra,py311-extra,py312-extra
python3 -m build -nswx .
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
twine upload dist/*
73 changes: 49 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pip install tabulate
Build status
------------

[![Build status](https://circleci.com/gh/astanin/python-tabulate.svg?style=svg)](https://circleci.com/gh/astanin/python-tabulate/tree/master) [![Build status](https://ci.appveyor.com/api/projects/status/8745yksvvol7h3d7/branch/master?svg=true)](https://ci.appveyor.com/project/astanin/python-tabulate/branch/master)
[![python-tabulate](https://github.com/astanin/python-tabulate/actions/workflows/tabulate.yml/badge.svg)](https://github.com/astanin/python-tabulate/actions/workflows/tabulate.yml) [![Build status](https://ci.appveyor.com/api/projects/status/8745yksvvol7h3d7/branch/master?svg=true)](https://ci.appveyor.com/project/astanin/python-tabulate/branch/master)

Library usage
-------------
Expand Down Expand Up @@ -81,7 +81,7 @@ The following tabular data types are supported:
- list of lists or another iterable of iterables
- list or another iterable of dicts (keys as columns)
- dict of iterables (keys as columns)
- list of dataclasses (Python 3.7+ only, field names as columns)
- list of dataclasses (field names as columns)
- two-dimensional NumPy array
- NumPy record arrays (names as columns)
- pandas.DataFrame
Expand Down Expand Up @@ -121,10 +121,22 @@ dictionaries or named tuples:
```pycon
>>> print(tabulate({"Name": ["Alice", "Bob"],
... "Age": [24, 19]}, headers="keys"))
Age Name
----- ------
24 Alice
19 Bob
Name Age
------ -----
Alice 24
Bob 19
```

When data is a list of dictionaries, a dictionary can be passed as `headers`
to replace the keys with other column labels:

```pycon
>>> print(tabulate([{1: "Alice", 2: 24}, {1: "Bob", 2: 19}],
... headers={1: "Name", 2: "Age"}))
Name Age
------ -----
Alice 24
Bob 19
```

### Row Indices
Expand Down Expand Up @@ -666,18 +678,31 @@ Ver2 19.2

### Custom column alignment

`tabulate` allows a custom column alignment to override the above. The
`colalign` argument can be a list or a tuple of `stralign` named
arguments. Possible column alignments are: `right`, `center`, `left`,
`decimal` (only for numbers), and `None` (to disable alignment).
Omitting an alignment uses the default. For example:
`tabulate` allows a custom column alignment to override the smart alignment described above.
Use `colglobalalign` to define a global setting. Possible alignments are: `right`, `center`, `left`, `decimal` (only for numbers).
Furthermore, you can define `colalign` for column-specific alignment as a list or a tuple. Possible values are `global` (keeps global setting), `right`, `center`, `left`, `decimal` (only for numbers), `None` (to disable alignment). Missing alignments are treated as `global`.

```pycon
>>> print(tabulate([["one", "two"], ["three", "four"]], colalign=("right",))
----- ----
one two
three four
----- ----
>>> print(tabulate([[1,2,3,4],[111,222,333,444]], colglobalalign='center', colalign = ('global','left','right')))
--- --- --- ---
1 2 3 4
111 222 333 444
--- --- --- ---
```

### Custom header alignment

Headers' alignment can be defined separately from columns'. Like for columns, you can use:
- `headersglobalalign` to define a header-specific global alignment setting. Possible values are `right`, `center`, `left`, `None` (to follow column alignment),
- `headersalign` list or tuple to further specify header-wise alignment. Possible values are `global` (keeps global setting), `same` (follow column alignment), `right`, `center`, `left`, `None` (to disable alignment). Missing alignments are treated as `global`.

```pycon
>>> print(tabulate([[1,2,3,4,5,6],[111,222,333,444,555,666]], colglobalalign = 'center', colalign = ('left',), headers = ['h','e','a','d','e','r'], headersglobalalign = 'right', headersalign = ('same','same','left','global','center')))

h e a d e r
--- --- --- --- --- ---
1 2 3 4 5 6
111 222 333 444 555 666
```

### Number formatting
Expand Down Expand Up @@ -1061,33 +1086,33 @@ To run tests on all supported Python versions, make sure all Python
interpreters, `pytest` and `tox` are installed, then run `tox` in the root
of the project source tree.

On Linux `tox` expects to find executables like `python3.7`, `python3.8` etc.
On Windows it looks for `C:\Python37\python.exe`, `C:\Python38\python.exe` etc. respectively.
On Linux `tox` expects to find executables like `python3.11`, `python3.12` etc.
On Windows it looks for `C:\Python311\python.exe`, `C:\Python312\python.exe` etc. respectively.

One way to install all the required versions of the Python interpreter is to use [pyenv](https://github.com/pyenv/pyenv).
All versions can then be easily installed with something like:

pyenv install 3.7.12
pyenv install 3.8.12
pyenv install 3.11.7
pyenv install 3.12.1
...

Don't forget to change your `PATH` so that `tox` knows how to find all the installed versions. Something like

export PATH="${PATH}:${HOME}/.pyenv/shims"

To test only some Python environments, use `-e` option. For example, to
test only against Python 3.7 and Python 3.10, run:
test only against Python 3.11 and Python 3.12, run:

```shell
tox -e py37,py310
tox -e py311,py312
```

in the root of the project source tree.

To enable NumPy and Pandas tests, run:

```shell
tox -e py37-extra,py310-extra
tox -e py311-extra,py312-extra
```

(this may take a long time the first time, because NumPy and Pandas will
Expand Down Expand Up @@ -1123,5 +1148,5 @@ Bart Broere, Vilhelm Prytz, Alexander Gažo, Hugo van Kemenade,
jamescooke, Matt Warner, Jérôme Provensal, Kevin Deldycke,
Kian-Meng Ang, Kevin Patterson, Shodhan Save, cleoold, KOLANICH,
Vijaya Krishna Kasula, Furcy Pin, Christian Fibich, Shaun Duncan,
Dimitri Papadopoulos.
Dimitri Papadopoulos, Élie Goudout.

17 changes: 6 additions & 11 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ environment:
# The list here is complete (excluding Python 2.6, which
# isn't covered by this document) at the time of writing.

- PYTHON: "C:\\Python37"
- PYTHON: "C:\\Python38"
- PYTHON: "C:\\Python39"
- PYTHON: "C:\\Python37-x64"
- PYTHON: "C:\\Python38-x64"
#- PYTHON: "C:\\Python39"
#- PYTHON: "C:\\Python310"
#- PYTHON: "C:\\Python311"
#- PYTHON: "C:\\Python312"
- PYTHON: "C:\\Python39-x64"
- PYTHON: "C:\\Python310-x64"
- PYTHON: "C:\\Python311-x64"
- PYTHON: "C:\\Python312-x64"

install:
# Newer setuptools is needed for proper support of pyproject.toml
Expand All @@ -29,9 +29,6 @@ build: off

test_script:
# Put your test command here.
# If you don't need to build C extensions on 64-bit Python 3.3 or 3.4,
# you can remove "build.cmd" from the front of the command, as it's
# only needed to support those cases.
# Note that you must use the environment variable %PYTHON% to refer to
# the interpreter you're using - Appveyor does not do anything special
# to put the Python version you want to use on PATH.
Expand All @@ -40,9 +37,7 @@ test_script:

after_test:
# This step builds your wheels.
# Again, you only need build.cmd if you're building C extensions for
# 64-bit Python 3.3/3.4. And you need to use %PYTHON% to get the correct
# interpreter
# Again, you need to use %PYTHON% to get the correct interpreter
#- "build.cmd %PYTHON%\\python.exe setup.py bdist_wheel"
- "%PYTHON%\\python.exe -m build -nswx ."

Expand Down
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"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",
"Topic :: Software Development :: Libraries",
]
requires-python = ">=3.7"
requires-python = ">=3.9"
dynamic = ["version"]

[project.urls]
Expand Down
Loading

0 comments on commit f824851

Please sign in to comment.