Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vendor tomli 1.2.3 in flit_core #492

Merged
merged 7 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[run]
omit = */tests/*
*/flit_core/vendor/*
12 changes: 2 additions & 10 deletions bootstrap_dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
os.chdir(str(my_dir))
sys.path.insert(0, 'flit_core')

from flit_core import build_thyself
from flit_core.config import LoadedConfig
from flit.install import Installer

ap = argparse.ArgumentParser()
Expand All @@ -24,20 +22,14 @@

logging.basicConfig(level=logging.INFO)

# Construct config for flit_core
core_config = LoadedConfig()
core_config.module = 'flit_core'
core_config.metadata = build_thyself.metadata_dict
core_config.reqs_by_extra['.none'] = build_thyself.metadata.requires_dist

install_kwargs = {'symlink': True}
if os.name == 'nt':
# Use .pth files instead of symlinking on Windows
install_kwargs = {'symlink': False, 'pth': True}

# Install flit_core
Installer(
my_dir / 'flit_core', core_config, user=args.user, **install_kwargs
Installer.from_ini_path(
my_dir / 'flit_core' / 'pyproject.toml', user=args.user, **install_kwargs
).install()
print("Linked flit_core into site-packages.")

Expand Down
12 changes: 5 additions & 7 deletions doc/bootstrap.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ The key piece is ``flit_core``. This is a package which can build itself using
nothing except Python and the standard library. From an unpacked source archive,
you can run ``python build_dists.py``, of which the crucial part is::

from flit_core import build_thyself
whl_fname = build_thyself.build_wheel('dist/')
from flit_core import buildapi
whl_fname = buildapi.build_wheel('dist/')
print(os.path.join('dist', whl_fname))

This produces a ``.whl`` wheel file, which you can unzip into your
Expand All @@ -25,11 +25,9 @@ building other packages. (You could also just copy ``flit_core`` from the
source directory, but without the ``.dist-info`` folder, tools like pip won't
know that it's installed.)

Note that although ``flit_core`` has no *build* dependencies, it has one runtime
dependency, `Tomli <https://pypi.org/project/tomli/>`_. Tomli is itself packaged
with Flit, so after building ``flit_core``, you will need to use that to build
Tomli, arranging for ``tomli`` to be importable directly from the source location
(e.g. using the ``PYTHONPATH`` environment variable).
As of version 3.6, flit_core bundles the ``tomli`` TOML parser, to avoid a
dependency cycle. If you need to unbundle it, you will need to special-case
installing flit_core and/or tomli to get around that cycle.

I recommend that you get the `build <https://pypi.org/project/build/>`_ and
`installer <https://pypi.org/project/installer/>`_ packages (and their
Expand Down
6 changes: 3 additions & 3 deletions flit_core/build_dists.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"""
import os

from flit_core import build_thyself
from flit_core import buildapi

os.chdir(os.path.dirname(os.path.abspath(__file__)))

print("Building sdist")
sdist_fname = build_thyself.build_sdist('dist/')
sdist_fname = buildapi.build_sdist('dist/')
print(os.path.join('dist', sdist_fname))

print("\nBuilding wheel")
whl_fname = build_thyself.build_wheel('dist/')
whl_fname = buildapi.build_wheel('dist/')
print(os.path.join('dist', whl_fname))
96 changes: 0 additions & 96 deletions flit_core/flit_core/build_thyself.py

This file was deleted.

2 changes: 1 addition & 1 deletion flit_core/flit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import os
import os.path as osp
from pathlib import Path
import tomli
import re

from .vendor import tomli
takluyver marked this conversation as resolved.
Show resolved Hide resolved
from .versionno import normalise_version

log = logging.getLogger(__name__)
Expand Down
13 changes: 7 additions & 6 deletions flit_core/flit_core/tests/test_build_thyself.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Tests of flit_core building itself"""
import os
import os.path as osp
import pytest
import tarfile
from testpath import assert_isdir, assert_isfile
import zipfile

from flit_core import build_thyself
from flit_core import buildapi

@pytest.fixture()
def cwd_project():
proj_dir = osp.dirname(osp.dirname(osp.abspath(build_thyself.__file__)))
proj_dir = osp.dirname(osp.dirname(osp.abspath(buildapi.__file__)))
if not osp.isfile(osp.join(proj_dir, 'pyproject.toml')):
pytest.skip("need flit_core source directory")

Expand All @@ -21,9 +22,9 @@ def cwd_project():
os.chdir(old_cwd)


def test_prepare_metadata(tmp_path):
def test_prepare_metadata(tmp_path, cwd_project):
tmp_path = str(tmp_path)
dist_info = build_thyself.prepare_metadata_for_build_wheel(tmp_path)
dist_info = buildapi.prepare_metadata_for_build_wheel(tmp_path)

assert dist_info.endswith('.dist-info')
assert dist_info.startswith('flit_core')
Expand All @@ -36,7 +37,7 @@ def test_prepare_metadata(tmp_path):

def test_wheel(tmp_path, cwd_project):
tmp_path = str(tmp_path)
filename = build_thyself.build_wheel(tmp_path)
filename = buildapi.build_wheel(tmp_path)

assert filename.endswith('.whl')
assert filename.startswith('flit_core')
Expand All @@ -47,7 +48,7 @@ def test_wheel(tmp_path, cwd_project):

def test_sdist(tmp_path, cwd_project):
tmp_path = str(tmp_path)
filename = build_thyself.build_sdist(tmp_path)
filename = buildapi.build_sdist(tmp_path)

assert filename.endswith('.tar.gz')
assert filename.startswith('flit_core')
Expand Down
13 changes: 13 additions & 0 deletions flit_core/flit_core/vendor/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
flit_core bundles the 'tomli' TOML parser, to avoid a bootstrapping problem.
tomli is packaged using Flit, so there would be a dependency cycle when building
from source. Vendoring a copy of tomli avoids this. The code in tomli is under
the MIT license, and the LICENSE file is in the .dist-info folder.

If you want to unbundle tomli and rely on it as a separate package, you can
replace the package with Python code doing 'from tomli import *'. You will
probably need to work around the dependency cycle between flit_core and tomli.

Bundling a TOML parser should be a special case - I don't plan on bundling
anything else in flit_core (or depending on any other packages).
I hope that a TOML parser will be added to the Python standard library, and then
this bundled parser will go away.
Empty file.
21 changes: 21 additions & 0 deletions flit_core/flit_core/vendor/tomli-1.2.3.dist-info/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Taneli Hukkinen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading