Skip to content

Commit

Permalink
Merge pull request #438 from takluyver/tomli
Browse files Browse the repository at this point in the history
Switch TOML library to tomli
  • Loading branch information
takluyver committed Aug 27, 2021
2 parents 301d447 + af7608c commit 9c56266
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 74 deletions.
23 changes: 1 addition & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ 3.5, 3.6, 3.7, 3.8, 3.9, ]
python-version: [ 3.6, 3.7, 3.8, 3.9, ]
steps:
- uses: actions/checkout@v2

Expand All @@ -26,24 +26,3 @@ jobs:

- name: Codecov upload
run: codecov

# tox-gh-actions requires Python >= 3.5, so test 3.4 separately
test-py34:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2

- name: Setup Python 3.4
uses: actions/setup-python@v2
with:
python-version: 3.4

- name: Install dependencies
run: |
pip install tox codecov
- name: Run tests
run: tox -e py34

- name: Codecov upload
run: codecov
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ environment:
matrix:
- TOXENV: "py37"
TOX_APPVEYOR_X64: "1"
- TOXENV: "py35"
- TOXENV: "py36"
TOX_APPVEYOR_X64: "0"

# The Python version here doesn't matter (except that the commands have the same),
Expand Down
10 changes: 7 additions & 3 deletions doc/pyproject_toml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Version constraints:
- :ref:`pyproject_toml_project` requires ``flit_core >=3.2``
- :ref:`pyproject_old_metadata` requires ``flit_core >=2,<4``
- The older :doc:`flit.ini file <flit_ini>` requires ``flit_core <3``.
- TOML features new in version 1.0 require ``flit_core >=3.4``.
- ``flit_core`` 3.3 is the last version supporting Python 3.4 & 3.5. Packages
supporting these Python versions can only use `TOML v0.5
<https://toml.io/en/v0.5.0>`_.
- Only ``flit_core`` 2.x can build packages on Python 2, so packages still
supporting Python 2 cannot use new-style metadata (the ``[project]`` table).

Expand Down Expand Up @@ -333,10 +337,10 @@ Here's the full metadata section from flit itself:
"flit_core>=2.2.0",
"requests",
"docutils",
"toml",
"zipfile36; python_version in '3.3 3.4 3.5'",
"tomli",
"tomli-w",
]
requires-python=">=3.5"
requires-python=">=3.6"
description-file="README.rst"
classifiers=[
"Intended Audience :: Developers",
Expand Down
9 changes: 5 additions & 4 deletions flit/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
import re
import sys
import toml
import tomli_w

def get_data_dir():
"""Get the directory path for flit user data files.
Expand Down Expand Up @@ -223,13 +223,14 @@ def initialise(self):
name=json.dumps(module), authors=authors_list
))
if readme:
toml.dump({'readme': readme}, f)
f.write(tomli_w.dumps({'readme': readme}))
if classifiers:
f.write(f"classifiers = {json.dumps(classifiers)}\n")
f.write('dynamic = ["version", "description"]\n')
if home_page:
f.write("\n")
toml.dump({'project': {'urls': {'Home': home_page}}}, f)
f.write("\n" + tomli_w.dumps({
'project': {'urls': {'Home': home_page}}
}))

print()
print("Written pyproject.toml; edit that file to add optional extra info.")
Expand Down
8 changes: 4 additions & 4 deletions flit/tomlify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import configparser
import os
from pathlib import Path
import toml
import tomli_w

from .config import metadata_list_fields

Expand Down Expand Up @@ -49,11 +49,11 @@ def convert(path):

written_entrypoints = False
with Path('pyproject.toml').open('w', encoding='utf-8') as f:
f.write(TEMPLATE.format(metadata=toml.dumps(metadata)))
f.write(TEMPLATE.format(metadata=tomli_w.dumps(metadata)))

if scripts:
f.write('\n[tool.flit.scripts]\n')
toml.dump(scripts, f)
f.write(tomli_w.dumps(scripts))

for groupname, group in entrypoints.items():
if not dict(group):
Expand All @@ -62,7 +62,7 @@ def convert(path):
if '.' in groupname:
groupname = '"{}"'.format(groupname)
f.write('\n[tool.flit.entrypoints.{}]\n'.format(groupname))
toml.dump(OrderedDict(group), f)
f.write(tomli_w.dumps(OrderedDict(group)))
written_entrypoints = True

print("Written 'pyproject.toml'")
Expand Down
4 changes: 2 additions & 2 deletions flit_core/flit_core/build_thyself.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
'summary': ('Distribution-building parts of Flit. '
'See flit package for more information'),
'requires_dist': [
'toml',
'tomli',
],
'requires_python': '>=3.4',
'requires_python': '>=3.6',
'classifiers': [
"License :: OSI Approved :: BSD License",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand Down
5 changes: 2 additions & 3 deletions flit_core/flit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import os.path as osp
from pathlib import Path
import toml
import tomli
import re

from .versionno import normalise_version
Expand Down Expand Up @@ -66,8 +66,7 @@ class ConfigError(ValueError):
def read_flit_config(path):
"""Read and check the `pyproject.toml` file with data about the package.
"""
with path.open('r', encoding='utf-8') as f:
d = toml.load(f)
d = tomli.loads(path.read_text('utf-8'))
return prep_toml_config(d, path)


Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ dependencies = [
"flit_core >=3.3.0",
"requests",
"docutils",
"toml",
"zipfile36; python_version == '3.5'",
"tomli",
"tomli-w",
]
requires-python = ">=3.6"
readme = "README.rst"
Expand Down
22 changes: 11 additions & 11 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from unittest.mock import patch
import pytest

import toml
import tomli

from flit import init

Expand Down Expand Up @@ -106,8 +106,8 @@ def test_init():

generated = Path(td) / 'pyproject.toml'
assert_isfile(generated)
with generated.open() as f:
data = toml.load(f)
with generated.open('rb') as f:
data = tomli.load(f)
assert data['project']['authors'][0]['email'] == "test@example.com"
license = Path(td) / 'LICENSE'
assert_isfile(license)
Expand All @@ -129,8 +129,8 @@ def test_init_homepage_and_license_are_optional():
faking_input(responses):
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open() as f:
data = toml.load(f)
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)
assert not Path(td, 'LICENSE').exists()
assert data['project'] == {
'authors': [{'name': 'Test Author', 'email': 'test_email@example.com'}],
Expand All @@ -151,8 +151,8 @@ def test_init_homepage_validator():
faking_input(responses):
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open() as f:
data = toml.load(f)
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)
assert data['project'] == {
'authors': [{'name': 'Test Author', 'email': 'test_email@example.com'}],
'name': 'test_module_name',
Expand All @@ -172,8 +172,8 @@ def test_author_email_field_is_optional():
faking_input(responses):
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open() as f:
data = toml.load(f)
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)
assert not Path(td, 'LICENSE').exists()

assert data['project'] == {
Expand Down Expand Up @@ -213,8 +213,8 @@ def test_init_readme_found_yes_choosen():
faking_input(responses):
ti = init.TerminalIniter(td)
ti.initialise()
with Path(td, 'pyproject.toml').open() as f:
data = toml.load(f)
with Path(td, 'pyproject.toml').open('rb') as f:
data = tomli.load(f)

assert data['project'] == {
'authors': [{'name': 'Test Author', 'email': 'test_email@example.com'}],
Expand Down
6 changes: 3 additions & 3 deletions tests/test_tomlify.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
import toml
import tomli
from shutil import copy
from testpath import assert_isfile

Expand All @@ -17,8 +17,8 @@ def test_tomlify(copy_sample, monkeypatch):
pyproject_toml = (td / 'pyproject.toml')
assert_isfile(pyproject_toml)

with pyproject_toml.open(encoding='utf-8') as f:
content = toml.load(f)
with pyproject_toml.open('rb') as f:
content = tomli.load(f)

assert 'build-system' in content
assert 'tool' in content
Expand Down
22 changes: 3 additions & 19 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
[tox]
envlist = py{39,38,37,36,35,34},bootstrap
envlist = py{39,38,37,36},bootstrap
skip_missing_interpreters = true

[gh-actions]
python =
3.4: py34
3.5: py35
3.6: py36
3.7: py37
3.8: py38, bootstrap
Expand All @@ -18,16 +16,11 @@ deps =
testpath
responses
docutils
toml
tomli
tomli-w
pytest>=2.7.3
pytest-cov

py35: zipfile36
py34: zipfile36

# pytest requires attrs, and it now gets a version for Py >= 3.5 by default
py34: attrs <21

skip_install=true

setenv =
Expand All @@ -36,15 +29,6 @@ setenv =
commands =
python -m pytest --cov=flit --cov=flit_core/flit_core

# Python 3.4 & 3.5: only test flit_core
[testenv:py34]
commands =
python -m pytest --cov=flit_core/flit_core --pyargs flit_core

[testenv:py35]
commands =
python -m pytest --cov=flit_core/flit_core --pyargs flit_core

[testenv:bootstrap]
skip_install = true
# Make the install step a no-op, so nothing gets installed in the env
Expand Down

0 comments on commit 9c56266

Please sign in to comment.