Import Upstream version 3.7.1

This commit is contained in:
Lu zhiping 2022-09-06 17:47:45 +08:00
commit 9f73cb96fd
237 changed files with 11868 additions and 0 deletions

14
.bumpversion.cfg Normal file
View File

@ -0,0 +1,14 @@
[bumpversion]
current_version = 3.7.1
commit = True
tag = False
[bumpversion:file:pyproject.toml]
search = flit_core >={current_version}
replace = flit_core >={new_version}
[bumpversion:file:flit/__init__.py]
[bumpversion:file:flit_core/flit_core/__init__.py]
[bumpversion:file:doc/conf.py]

3
.coveragerc Normal file
View File

@ -0,0 +1,3 @@
[run]
omit = */tests/*
*/flit_core/vendor/*

40
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,40 @@
name: Test
on:
push:
branches:
- main
pull_request:
concurrency:
group: >-
${{ github.workflow }}-
${{ github.ref_type }}-
${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
test:
runs-on: ${{ matrix.platform }}
strategy:
matrix:
platform: ["ubuntu-latest", "windows-latest"]
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ]
steps:
- uses: actions/checkout@v2
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions codecov
- name: Run tests
run: tox
- name: Codecov upload
run: codecov

16
.gitignore vendored Normal file
View File

@ -0,0 +1,16 @@
/build/
/dist/
/flit_core/dist/
__pycache__/
/doc/_build/
/tests/samples/build/
/tests/samples/dist/
/tests/samples/ns1-pkg/dist/
/htmlcov/
/.coverage
/.pytest_cache
/.tox
.idea/
venv/
*.pyc
.python-version

29
LICENSE Normal file
View File

@ -0,0 +1,29 @@
Copyright (c) 2015, Thomas Kluyver and contributors
All rights reserved.
BSD 3-clause license:
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

110
PKG-INFO Normal file
View File

@ -0,0 +1,110 @@
Metadata-Version: 2.1
Name: flit
Version: 3.7.1
Summary: A simple packaging tool for simple packages.
Author-email: Thomas Kluyver <thomas@kluyver.me.uk>
Requires-Python: >=3.6
Description-Content-Type: text/x-rst
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: flit_core >=3.7.1
Requires-Dist: requests
Requires-Dist: docutils
Requires-Dist: tomli
Requires-Dist: tomli-w
Requires-Dist: sphinx ; extra == "doc"
Requires-Dist: sphinxcontrib_github_alt ; extra == "doc"
Requires-Dist: pygments-github-lexers ; extra == "doc"
Requires-Dist: testpath ; extra == "test"
Requires-Dist: responses ; extra == "test"
Requires-Dist: pytest>=2.7.3 ; extra == "test"
Requires-Dist: pytest-cov ; extra == "test"
Project-URL: Changelog, https://flit.readthedocs.io/en/latest/history.html
Project-URL: Documentation, https://flit.readthedocs.io/en/latest/
Project-URL: Source, https://github.com/pypa/flit
Provides-Extra: doc
Provides-Extra: test
**Flit** is a simple way to put Python packages and modules on PyPI.
It tries to require less thought about packaging and help you avoid common
mistakes.
See `Why use Flit? <https://flit.readthedocs.io/en/latest/rationale.html>`_ for
more about how it compares to other Python packaging tools.
Install
-------
::
$ python3 -m pip install flit
Flit requires Python 3 and therefore needs to be installed using the Python 3
version of pip.
Python 2 modules can be distributed using Flit, but need to be importable on
Python 3 without errors.
Usage
-----
Say you're writing a module ``foobar`` — either as a single file ``foobar.py``,
or as a directory — and you want to distribute it.
1. Make sure that foobar's docstring starts with a one-line summary of what
the module is, and that it has a ``__version__``:
.. code-block:: python
"""An amazing sample package!"""
__version__ = "0.1"
2. Install flit if you don't already have it::
python3 -m pip install flit
3. Run ``flit init`` in the directory containing the module to create a
``pyproject.toml`` file. It will look something like this:
.. code-block:: ini
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[project]
name = "foobar"
authors = [{name = "Sir Robin", email = "robin@camelot.uk"}]
dynamic = ["version", "description"]
[project.urls]
Home = "https://github.com/sirrobin/foobar"
You can edit this file to add other metadata, for example to set up
command line scripts. See the
`pyproject.toml page <https://flit.readthedocs.io/en/latest/pyproject_toml.html#scripts-section>`_
of the documentation.
If you have already got a ``flit.ini`` file to use with older versions of
Flit, convert it to ``pyproject.toml`` by running ``python3 -m flit.tomlify``.
4. Run this command to upload your code to PyPI::
flit publish
Once your package is published, people can install it using *pip* just like
any other package. In most cases, pip will download a 'wheel' package, a
standard format it knows how to install. If you specifically ask pip to install
an 'sdist' package, it will install and use Flit in a temporary environment.
To install a package locally for development, run::
flit install [--symlink] [--python path/to/python]
Flit packages a single importable module or package at a time, using the import
name as the name on PyPI. All subpackages and data files within a package are
included automatically.

80
README.rst Normal file
View File

@ -0,0 +1,80 @@
**Flit** is a simple way to put Python packages and modules on PyPI.
It tries to require less thought about packaging and help you avoid common
mistakes.
See `Why use Flit? <https://flit.readthedocs.io/en/latest/rationale.html>`_ for
more about how it compares to other Python packaging tools.
Install
-------
::
$ python3 -m pip install flit
Flit requires Python 3 and therefore needs to be installed using the Python 3
version of pip.
Python 2 modules can be distributed using Flit, but need to be importable on
Python 3 without errors.
Usage
-----
Say you're writing a module ``foobar`` — either as a single file ``foobar.py``,
or as a directory — and you want to distribute it.
1. Make sure that foobar's docstring starts with a one-line summary of what
the module is, and that it has a ``__version__``:
.. code-block:: python
"""An amazing sample package!"""
__version__ = "0.1"
2. Install flit if you don't already have it::
python3 -m pip install flit
3. Run ``flit init`` in the directory containing the module to create a
``pyproject.toml`` file. It will look something like this:
.. code-block:: ini
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[project]
name = "foobar"
authors = [{name = "Sir Robin", email = "robin@camelot.uk"}]
dynamic = ["version", "description"]
[project.urls]
Home = "https://github.com/sirrobin/foobar"
You can edit this file to add other metadata, for example to set up
command line scripts. See the
`pyproject.toml page <https://flit.readthedocs.io/en/latest/pyproject_toml.html#scripts-section>`_
of the documentation.
If you have already got a ``flit.ini`` file to use with older versions of
Flit, convert it to ``pyproject.toml`` by running ``python3 -m flit.tomlify``.
4. Run this command to upload your code to PyPI::
flit publish
Once your package is published, people can install it using *pip* just like
any other package. In most cases, pip will download a 'wheel' package, a
standard format it knows how to install. If you specifically ask pip to install
an 'sdist' package, it will install and use Flit in a temporary environment.
To install a package locally for development, run::
flit install [--symlink] [--python path/to/python]
Flit packages a single importable module or package at a time, using the import
name as the name on PyPI. All subpackages and data files within a package are
included automatically.

40
bootstrap_dev.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
# Symlink install flit & flit_core for development.
# Most projects can do the same with 'flit install --symlink'.
# But that doesn't work until Flit is installed, so we need some bootstrapping.
import argparse
import logging
import os
from pathlib import Path
import sys
my_dir = Path(__file__).parent
os.chdir(str(my_dir))
sys.path.insert(0, 'flit_core')
from flit.install import Installer
ap = argparse.ArgumentParser()
ap.add_argument('--user')
args = ap.parse_args()
logging.basicConfig(level=logging.INFO)
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.from_ini_path(
my_dir / 'flit_core' / 'pyproject.toml', user=args.user, **install_kwargs
).install()
print("Linked flit_core into site-packages.")
# Install flit
Installer.from_ini_path(
my_dir / 'pyproject.toml', user=args.user, **install_kwargs
).install()
print("Linked flit into site-packages.")

1
codecov.yml Normal file
View File

@ -0,0 +1 @@
comment: off

177
doc/Makefile Normal file
View File

@ -0,0 +1,177 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/Flit.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Flit.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/Flit"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Flit"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."

149
doc/_static/flit_logo_nobg.svg vendored Normal file
View File

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="293.71423"
height="293.71423"
id="svg3116"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="New document 2">
<defs
id="defs3118">
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4452"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.0646126,0,0,2.0646126,2131.1883,-505.68517)"
x1="294.93112"
y1="187.01703"
x2="536.55017"
y2="453.6973" />
<linearGradient
inkscape:collect="always"
id="linearGradient4432">
<stop
style="stop-color:#00c48a;stop-opacity:1"
offset="0"
id="stop4434" />
<stop
style="stop-color:#00cbff;stop-opacity:1"
offset="1"
id="stop4436" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4460"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4454"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4456"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4458"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.98994949"
inkscape:cx="421.10472"
inkscape:cy="117.57302"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1680"
inkscape:window-height="987"
inkscape:window-x="1680"
inkscape:window-y="27"
inkscape:window-maximized="1" />
<metadata
id="metadata3121">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-204.57382,-259.79316)">
<g
transform="matrix(0.24278029,0,0,0.24278029,-425.3047,353.61591)"
id="g4440">
<path
id="path4442"
style="fill:url(#linearGradient4452);fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 3027.3295,254.07953 c -13.7048,13.09172 -26.0357,28.06465 -37.0176,44.61328 l 0,41.02539 c 0,5.00744 1.7866,9.29826 5.3633,12.875 3.5768,3.57674 7.8695,5.36524 12.877,5.36524 5.3651,0 9.8353,-1.7885 13.4121,-5.36524 3.5767,-3.57674 5.3652,-7.86756 5.3652,-12.875 l 0,-85.63867 z m 40.2012,-35.61328 -40.2012,0 0,35.61328 c 2.8934,-2.76398 5.8436,-5.45128 8.8594,-8.04492 11.4454,-9.57254 21.8635,-18.67845 31.3418,-27.56836 z m 34.6465,-37.01953 c -9.7805,12.36045 -21.2701,24.47349 -34.6465,37.01953 l 46.7148,0 c 5.0075,0 9.2983,-1.78849 12.875,-5.36524 3.5768,-3.57674 5.3653,-7.86951 5.3653,-12.87695 0,-5.36511 -1.7885,-9.83537 -5.3653,-13.41211 -3.5767,-3.57674 -7.8675,-5.36523 -12.875,-5.36523 l -12.0683,0 z m 33.4824,-60.625 -108.3301,0 0,60.625 74.8477,0 c 14.8892,-18.81683 25.825,-38.22167 33.4824,-60.625 z m 9.5449,-37.019527 c -1.2585,5.3045 -2.516,10.94337 -3.7636,17.044917 -1.6666,6.94336 -3.5949,13.57773 -5.7813,19.97461 l 23.6523,0 c 5.0075,0 9.3003,-1.78849 12.877,-5.36524 3.5767,-3.93441 5.3652,-8.40662 5.3652,-13.41406 0,-5.007437 -1.7885,-9.298257 -5.3652,-12.874997 -3.5767,-3.57674 -7.8695,-5.36523 -12.877,-5.36523 l -14.1074,0 z m -476.3222,-177.33008 c -2.0115,-10e-4 -4.0205,0.0285 -6.0352,0.0957 -32.2353,1.07179 -39.6278,16.38542 -12.3691,36.69141 27.2586,20.30597 67.4768,42.69338 95.8925,62.71679 28.4157,20.02339 35.7846,52.54784 62.5118,70.95899 26.7272,18.41115 54.3969,37.466677 74.8691,57.441407 20.4723,19.97478 42.8139,29.80954 62.9473,12.42382 -41.9066,63.48263 12.2332,134.84987 -173.1446,298.5918 29.2843,16.0722 57.5499,-20.52973 74.8907,-31.10547 2.5476,26.72831 -25.0012,91.1355 -29.2129,135.5625 21.025,-46.6543 56.9285,-120.22794 63.457,-115.36328 9.8881,7.3681 14.1396,135.40743 24.3965,116.33203 21.0116,-25.8867 22.3263,-107.36363 34.0937,-138.89062 11.2667,-42.29933 27.605,-80.7941 49.1328,-113.23438 l 0,-196.65039 c 0,-5.007437 1.7866,-9.298257 5.3633,-12.874997 3.5768,-3.57674 7.8695,-5.36523 12.877,-5.36523 l 136.6523,0 c 15.517,-65.40122 31.2666,-72.74791 32.5215,-83.04883003 13.2678,-9.65059997 122.3748,-33.57495997 180.1094,-40.48437997 -50.3218,-5.57548 -143.4532,11.69044 -195.586,7.36328 -73.7651,-34.78206 -111.4896,10.40375 -121.4531,64.52149 -83.501,33.35098 -204.8488,-83.78957 -259.7637,-101.41602 -51.4826,-16.52477 -81.9782,-24.2477 -112.1503,-24.26562 z m 83.1191,-45.779303 c -0.8667,-0.008 -1.7091,4.6e-4 -2.5293,0.0254 -22.9645,0.69796 -27.5787,14.12698 -6.4688,35.07813 7.5478,7.490993 16.3801,15.378493 25.6504,23.388673 3.4327,1.07931 6.7052,2.08334 10.3399,3.25 54.6631,17.54562 175.142,133.67703 258.6035,101.84765 -64.3681,-33.00238 -126.9043,-104.68293 -163.5801,-122.48828 -48.6408,-23.613873 -77.7408,-35.557113 -107.6094,-39.826173 -1.9912,-0.28458 -3.988,-0.53646 -5.9921,-0.7539 -3.0061,-0.32634 -5.8141,-0.49799 -8.4141,-0.52149 z"
inkscape:connector-curvature="0" />
<g
id="g4444"
style="fill:url(#linearGradient4460);fill-opacity:1"
transform="translate(-52.527932,-383.85797)">
<path
id="path4446"
d="m 3295.8047,467.66016 c -5.0075,0 -9.3002,1.78849 -12.877,5.36523 -3.5767,3.57674 -5.3652,7.86756 -5.3652,12.875 l 0,237.67578 c 0,5.00744 1.7885,9.29826 5.3652,12.875 3.5768,3.57674 7.8695,5.36524 12.877,5.36524 l 150.7598,0 c 5.0074,0 9.2982,-1.7885 12.875,-5.36524 3.5767,-3.57674 5.3652,-7.86756 5.3652,-12.875 0,-5.36511 -1.7885,-9.83732 -5.3652,-13.41406 -3.5768,-3.57674 -7.8676,-5.36328 -12.875,-5.36328 l -131.9825,0 0,-218.89844 c 0,-5.00744 -1.7885,-9.29826 -5.3652,-12.875 -3.5767,-3.57674 -8.047,-5.36523 -13.4121,-5.36523 z"
style="fill:url(#linearGradient4454);fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
<path
id="path4448"
d="m 3532.623,467.66016 c -5.0074,0 -9.2982,1.78849 -12.875,5.36523 -3.5767,3.57674 -5.3652,7.86756 -5.3652,12.875 l 0,237.67578 c 0,5.00744 1.7885,9.29826 5.3652,12.875 3.5768,3.57674 7.8676,5.36524 12.875,5.36524 5.3652,0 9.8374,-1.7885 13.4141,-5.36524 3.5768,-3.57674 5.3652,-7.86756 5.3652,-12.875 l 0,-237.67578 c 0,-5.00744 -1.7884,-9.29826 -5.3652,-12.875 -3.5767,-3.57674 -8.0489,-5.36523 -13.4141,-5.36523 z"
style="fill:url(#linearGradient4456);fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
<path
id="path4450"
d="m 3617.123,467.66016 c -5.0074,0 -9.2982,1.78849 -12.875,5.36523 -3.5767,3.57674 -5.3652,7.86756 -5.3652,12.875 0,5.00744 1.7885,9.47965 5.3652,13.41406 3.5768,3.57675 7.8676,5.36524 12.875,5.36524 l 56.8711,0 0,218.89648 c 0,5.00744 1.7885,9.29826 5.3653,12.875 3.5767,3.57674 7.8695,5.36524 12.8769,5.36524 5.3651,0 9.8354,-1.7885 13.4121,-5.36524 3.5768,-3.57674 5.3653,-7.86756 5.3653,-12.875 l 0,-218.89648 56.8691,0 c 5.0075,0 9.3002,-1.78849 12.877,-5.36524 3.5767,-3.93441 5.3652,-8.40662 5.3652,-13.41406 0,-5.00744 -1.7885,-9.29826 -5.3652,-12.875 -3.5768,-3.57674 -7.8695,-5.36523 -12.877,-5.36523 l -150.7598,0 z"
style="fill:url(#linearGradient4458);fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.7 KiB

BIN
doc/_static/flit_logo_nobg_cropped.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

158
doc/_static/flit_logo_nobg_cropped.svg vendored Normal file
View File

@ -0,0 +1,158 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="293.54721"
height="194.0495"
id="svg3116"
version="1.1"
inkscape:version="0.48.5 r10040"
sodipodi:docname="flit_logo_nobg.svg">
<defs
id="defs3118">
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4452"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(2.0646126,0,0,2.0646126,2131.1883,-505.68517)"
x1="294.93112"
y1="187.01703"
x2="536.55017"
y2="453.6973" />
<linearGradient
inkscape:collect="always"
id="linearGradient4432">
<stop
style="stop-color:#00c48a;stop-opacity:1"
offset="0"
id="stop4434" />
<stop
style="stop-color:#00cbff;stop-opacity:1"
offset="1"
id="stop4436" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4460"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4454"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4456"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient4458"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4432"
id="linearGradient3991"
gradientUnits="userSpaceOnUse"
x1="3277.5625"
y1="604.73828"
x2="3786.125"
y2="604.73828" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.4"
inkscape:cx="221.08413"
inkscape:cy="35.027636"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
inkscape:window-width="1680"
inkscape:window-height="987"
inkscape:window-x="1680"
inkscape:window-y="27"
inkscape:window-maximized="1" />
<metadata
id="metadata3121">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-204.65524,-306.77908)">
<g
transform="matrix(0.24278029,0,0,0.24278029,-425.3047,353.61591)"
id="g4440">
<path
id="path4442"
style="fill:url(#linearGradient4452);fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 3027.3295,254.07953 c -13.7048,13.09172 -26.0357,28.06465 -37.0176,44.61328 l 0,41.02539 c 0,5.00744 1.7866,9.29826 5.3633,12.875 3.5768,3.57674 7.8695,5.36524 12.877,5.36524 5.3651,0 9.8353,-1.7885 13.4121,-5.36524 3.5767,-3.57674 5.3652,-7.86756 5.3652,-12.875 l 0,-85.63867 z m 40.2012,-35.61328 -40.2012,0 0,35.61328 c 2.8934,-2.76398 5.8436,-5.45128 8.8594,-8.04492 11.4454,-9.57254 21.8635,-18.67845 31.3418,-27.56836 z m 34.6465,-37.01953 c -9.7805,12.36045 -21.2701,24.47349 -34.6465,37.01953 l 46.7148,0 c 5.0075,0 9.2983,-1.78849 12.875,-5.36524 3.5768,-3.57674 5.3653,-7.86951 5.3653,-12.87695 0,-5.36511 -1.7885,-9.83537 -5.3653,-13.41211 -3.5767,-3.57674 -7.8675,-5.36523 -12.875,-5.36523 l -12.0683,0 z m 33.4824,-60.625 -108.3301,0 0,60.625 74.8477,0 c 14.8892,-18.81683 25.825,-38.22167 33.4824,-60.625 z m 9.5449,-37.019527 c -1.2585,5.3045 -2.516,10.94337 -3.7636,17.044917 -1.6666,6.94336 -3.5949,13.57773 -5.7813,19.97461 l 23.6523,0 c 5.0075,0 9.3003,-1.78849 12.877,-5.36524 3.5767,-3.93441 5.3652,-8.40662 5.3652,-13.41406 0,-5.007437 -1.7885,-9.298257 -5.3652,-12.874997 -3.5767,-3.57674 -7.8695,-5.36523 -12.877,-5.36523 l -14.1074,0 z m -476.3222,-177.33008 c -2.0115,-10e-4 -4.0205,0.0285 -6.0352,0.0957 -32.2353,1.07179 -39.6278,16.38542 -12.3691,36.69141 27.2586,20.30597 67.4768,42.69338 95.8925,62.71679 28.4157,20.02339 35.7846,52.54784 62.5118,70.95899 26.7272,18.41115 54.3969,37.466677 74.8691,57.441407 20.4723,19.97478 42.8139,29.80954 62.9473,12.42382 -41.9066,63.48263 12.2332,134.84987 -173.1446,298.5918 29.2843,16.0722 57.5499,-20.52973 74.8907,-31.10547 2.5476,26.72831 -25.0012,91.1355 -29.2129,135.5625 21.025,-46.6543 56.9285,-120.22794 63.457,-115.36328 9.8881,7.3681 14.1396,135.40743 24.3965,116.33203 21.0116,-25.8867 22.3263,-107.36363 34.0937,-138.89062 11.2667,-42.29933 27.605,-80.7941 49.1328,-113.23438 l 0,-196.65039 c 0,-5.007437 1.7866,-9.298257 5.3633,-12.874997 3.5768,-3.57674 7.8695,-5.36523 12.877,-5.36523 l 136.6523,0 c 15.517,-65.40122 31.2666,-72.74791 32.5215,-83.04883003 13.2678,-9.65059997 122.3748,-33.57495997 180.1094,-40.48437997 -50.3218,-5.57548 -143.4532,11.69044 -195.586,7.36328 -73.7651,-34.78206 -111.4896,10.40375 -121.4531,64.52149 -83.501,33.35098 -204.8488,-83.78957 -259.7637,-101.41602 -51.4826,-16.52477 -81.9782,-24.2477 -112.1503,-24.26562 z m 83.1191,-45.779303 c -0.8667,-0.008 -1.7091,4.6e-4 -2.5293,0.0254 -22.9645,0.69796 -27.5787,14.12698 -6.4688,35.07813 7.5478,7.490993 16.3801,15.378493 25.6504,23.388673 3.4327,1.07931 6.7052,2.08334 10.3399,3.25 54.6631,17.54562 175.142,133.67703 258.6035,101.84765 -64.3681,-33.00238 -126.9043,-104.68293 -163.5801,-122.48828 -48.6408,-23.613873 -77.7408,-35.557113 -107.6094,-39.826173 -1.9912,-0.28458 -3.988,-0.53646 -5.9921,-0.7539 -3.0061,-0.32634 -5.8141,-0.49799 -8.4141,-0.52149 z"
inkscape:connector-curvature="0" />
<g
id="g4444"
style="fill:url(#linearGradient3991);fill-opacity:1"
transform="translate(-52.527932,-383.85797)">
<path
id="path4446"
d="m 3295.8047,467.66016 c -5.0075,0 -9.3002,1.78849 -12.877,5.36523 -3.5767,3.57674 -5.3652,7.86756 -5.3652,12.875 l 0,237.67578 c 0,5.00744 1.7885,9.29826 5.3652,12.875 3.5768,3.57674 7.8695,5.36524 12.877,5.36524 l 150.7598,0 c 5.0074,0 9.2982,-1.7885 12.875,-5.36524 3.5767,-3.57674 5.3652,-7.86756 5.3652,-12.875 0,-5.36511 -1.7885,-9.83732 -5.3652,-13.41406 -3.5768,-3.57674 -7.8676,-5.36328 -12.875,-5.36328 l -131.9825,0 0,-218.89844 c 0,-5.00744 -1.7885,-9.29826 -5.3652,-12.875 -3.5767,-3.57674 -8.047,-5.36523 -13.4121,-5.36523 z"
style="fill:url(#linearGradient4454);fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
<path
id="path4448"
d="m 3532.623,467.66016 c -5.0074,0 -9.2982,1.78849 -12.875,5.36523 -3.5767,3.57674 -5.3652,7.86756 -5.3652,12.875 l 0,237.67578 c 0,5.00744 1.7885,9.29826 5.3652,12.875 3.5768,3.57674 7.8676,5.36524 12.875,5.36524 5.3652,0 9.8374,-1.7885 13.4141,-5.36524 3.5768,-3.57674 5.3652,-7.86756 5.3652,-12.875 l 0,-237.67578 c 0,-5.00744 -1.7884,-9.29826 -5.3652,-12.875 -3.5767,-3.57674 -8.0489,-5.36523 -13.4141,-5.36523 z"
style="fill:url(#linearGradient4456);fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
<path
id="path4450"
d="m 3617.123,467.66016 c -5.0074,0 -9.2982,1.78849 -12.875,5.36523 -3.5767,3.57674 -5.3652,7.86756 -5.3652,12.875 0,5.00744 1.7885,9.47965 5.3652,13.41406 3.5768,3.57675 7.8676,5.36524 12.875,5.36524 l 56.8711,0 0,218.89648 c 0,5.00744 1.7885,9.29826 5.3653,12.875 3.5767,3.57674 7.8695,5.36524 12.8769,5.36524 5.3651,0 9.8354,-1.7885 13.4121,-5.36524 3.5768,-3.57674 5.3653,-7.86756 5.3653,-12.875 l 0,-218.89648 56.8691,0 c 5.0075,0 9.3002,-1.78849 12.877,-5.36524 3.5767,-3.93441 5.3652,-8.40662 5.3652,-13.41406 0,-5.00744 -1.7885,-9.29826 -5.3652,-12.875 -3.5768,-3.57674 -7.8695,-5.36523 -12.877,-5.36523 l -150.7598,0 z"
style="fill:url(#linearGradient4458);fill-opacity:1;fill-rule:evenodd;stroke:none"
inkscape:connector-curvature="0" />
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 8.9 KiB

41
doc/bootstrap.rst Normal file
View File

@ -0,0 +1,41 @@
Bootstrapping
=============
Flit is itself packaged using Flit, as are some foundational packaging tools
such as ``pep517``. So where can you start if you need to install everything
from source?
.. note::
For most users, ``pip`` handles all this automatically. You should only need
to deal with this if you're building things entirely from scratch, such as
putting Python packages into another package format.
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 make a wheel by running::
python -m flit_core.wheel
And then you can install this wheel with the ``bootstrap_install.py`` script
included in the sdist (or by unzipping it to the correct directory)::
# Install to site-packages for this Python:
python bootstrap_install.py dist/flit_core-*.whl
# Install somewhere else:
python bootstrap_install.py --installdir /path/to/site-packages dist/flit_core-*.whl
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.
After ``flit_core``, I recommend that you get `installer
<https://pypi.org/project/installer/>`_ set up. You can use
``python -m flit_core.wheel`` again to make a wheel, and then use installer
itself (from the source directory) to install it.
After that, you probably want to get `build <https://pypi.org/project/build/>`_
and its dependencies installed as the goal of the bootstrapping phase. You can
then use ``build`` to create wheels of any other Python packages, and
``installer`` to install them.

249
doc/cmdline.rst Normal file
View File

@ -0,0 +1,249 @@
Flit command line interface
===========================
All operations use the ``flit`` command, followed by one of a number of
subcommands.
Common options
--------------
.. program:: flit
.. option:: -f <path>, --ini-file <path>
Path to a config file specifying the module to build. The default is
``pyproject.toml``.
.. option:: --version
Show the version of Flit in use.
.. option:: --help
Show help on the command-line interface.
.. option:: --debug
Show more detailed logs about what flit is doing.
.. _build_cmd:
``flit build``
--------------
.. program:: flit build
Build a wheel and an sdist (tarball) from the package.
.. option:: --format <format>
Limit to building either ``wheel`` or ``sdist``.
.. option:: --setup-py
Generate a ``setup.py`` file in the sdist, so it can be installed by older
versions of pip.
.. option:: --no-setup-py
Don't generate a setup.py file in the sdist. This is the default.
An sdist built without this will only work with tools that support PEP 517,
but the wheel will still be usable by any compatible tool.
.. versionchanged:: 3.5
Generating ``setup.py`` disabled by default.
.. _publish_cmd:
``flit publish``
----------------
.. program:: flit publish
Build a wheel and an sdist (tarball) from the package, and upload them to PyPI
or another repository.
.. option:: --format <format>
Limit to publishing either ``wheel`` or ``sdist``.
You should normally publish the two formats together.
.. option:: --setup-py
Generate a ``setup.py`` file in the sdist, so it can be installed by older
versions of pip.
.. option:: --no-setup-py
Don't generate a setup.py file in the sdist. This is the default.
An sdist built without this will only work with tools that support PEP 517,
but the wheel will still be usable by any compatible tool.
.. versionchanged:: 3.5
Generating ``setup.py`` disabled by default.
.. option:: --repository <repository>
Name of a repository to upload packages to. Should match a section in
``~/.pypirc``. The default is ``pypi``.
.. option:: --pypirc <pypirc>
The .pypirc config file to be used. The default is ``~/.pypirc``.
.. seealso:: :doc:`upload`
.. _install_cmd:
``flit install``
----------------
.. program:: flit install
Install the package on your system.
By default, the package is installed to the same Python environment that Flit
itself is installed in; use :option:`--python` or :envvar:`FLIT_INSTALL_PYTHON`
to override this.
If you don't have permission to modify the environment (e.g. the system Python
on Linux), Flit may do a user install instead. Use the :option:`--user` or
:option:`--env` flags to force this one way or the other, rather than letting
Flit guess.
.. option:: -s, --symlink
Symlink the module into site-packages rather than copying it, so that you
can test changes without reinstalling the module.
.. option:: --pth-file
Create a ``.pth`` file in site-packages rather than copying the module, so
you can test changes without reinstalling. This is a less elegant alternative
to ``--symlink``, but it works on Windows, which typically doesn't allow
symlinks.
.. option:: --deps <dependency option>
Which dependencies to install. One of ``all``, ``production``, ``develop``,
or ``none``. ``all`` and ``develop`` install the extras ``test``, ``doc``,
and ``dev``. Default ``all``.
.. option:: --extras <extra[,extra,...]>
Which named extra features to install dependencies for. Specify ``all`` to
install all optional dependencies, or a comma-separated list of extras.
Default depends on ``--deps``.
.. option:: --user
Do a user-local installation. This is the default if flit is not in a
virtualenv or conda env (if the environment's library directory is
read-only and ``site.ENABLE_USER_SITE`` is true).
.. option:: --env
Install into the environment - the opposite of :option:`--user`.
This is the default in a virtualenv or conda env (if the environment's
library directory is writable or ``site.ENABLE_USER_SITE`` is false).
.. option:: --python <path to python>
Install for another Python, identified by the path of the python
executable. Using this option, you can install a module for Python 2, for
instance. See :envvar:`FLIT_INSTALL_PYTHON` if this option is not given.
.. versionchanged:: 2.1
Added :envvar:`FLIT_INSTALL_PYTHON` and use its value over the Python
running Flit when an explicit :option:`--python` option is not given.
.. note::
Flit calls pip to do the installation. You can set any of pip's options
`using its environment variables
<https://pip.pypa.io/en/stable/user_guide/#environment-variables>`__.
When you use the :option:`--symlink` or :option:`--pth-file` options, pip
is used to install dependencies. Otherwise, Flit builds a wheel and then
calls pip to install that.
.. _init_cmd:
``flit init``
-------------
.. program:: flit init
Create a new ``pyproject.toml`` config file by prompting for information about
the module in the current directory.
Environment variables
---------------------
.. envvar:: FLIT_NO_NETWORK
.. versionadded:: 0.10
Setting this to any non-empty value will stop flit from making network
connections (unless you explicitly ask to upload a package). This
is intended for downstream packagers, so if you use this, it's up to you to
ensure any necessary dependencies are installed.
.. envvar:: FLIT_ROOT_INSTALL
By default, ``flit install`` will fail when run as root on POSIX systems,
because installing Python modules systemwide is not recommended. Setting
this to any non-empty value allows installation as root. It has no effect on
Windows.
.. envvar:: FLIT_USERNAME
FLIT_PASSWORD
FLIT_INDEX_URL
.. versionadded:: 0.11
Set a username, password, and index URL for uploading packages.
See :ref:`uploading packages with environment variables <upload_envvars>`
for more information.
.. envvar:: FLIT_ALLOW_INVALID
.. versionadded:: 0.13
Setting this to any non-empty value tells Flit to continue if it detects
invalid metadata, instead of failing with an error. Problems will still be
reported in the logs, but won't cause Flit to stop.
If the metadata is invalid, uploading the package to PyPI may fail. This
environment variable provides an escape hatch in case Flit incorrectly
rejects your valid metadata. If you need to use it and you believe your
metadata is valid, please `open an issue <https://github.com/pypa/flit/issues>`__.
.. envvar:: FLIT_INSTALL_PYTHON
.. versionadded:: 2.1
.. program:: flit install
Set a default Python interpreter for :ref:`install_cmd` to use when
:option:`--python` is not specified. The value can be either an absolute
path, or a command name (which will be found in ``PATH``). If this is unset
or empty, the module is installed for the copy of Python that is running
Flit.
.. envvar:: SOURCE_DATE_EPOCH
To make reproducible builds, set this to a timestamp as a number of seconds
since the start of the year 1970 in UTC, and document the value you used.
On Unix systems, you can get a value for the current time by running::
date +%s
.. seealso::
`The SOURCE_DATE_EPOCH specification
<https://reproducible-builds.org/specs/source-date-epoch/>`__

264
doc/conf.py Normal file
View File

@ -0,0 +1,264 @@
# -*- coding: utf-8 -*-
#
# Flit documentation build configuration file, created by
# sphinx-quickstart on Sun Mar 15 19:16:41 2015.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys
import os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration ------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinxcontrib_github_alt',
'sphinx_rtd_theme',
]
github_project_url = "https://github.com/pypa/flit"
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'Flit'
copyright = u'2015, Thomas Kluyver'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '3.7.1'
# The full version, including alpha/beta/rc tags.
release = version #+ '.1'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all
# documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = '_static/flit_logo_nobg_cropped.svg'
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
# directly to the root of the documentation.
#html_extra_path = []
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'Flitdoc'
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
('index', 'Flit.tex', u'Flit Documentation',
u'Thomas Kluyver', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output ---------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'flit', u'Flit Documentation',
[u'Thomas Kluyver'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output -------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'Flit', u'Flit Documentation',
u'Thomas Kluyver', 'Flit', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# If true, do not generate a @detailmenu in the "Top" node's menu.
#texinfo_no_detailmenu = False

26
doc/development.rst Normal file
View File

@ -0,0 +1,26 @@
Developing Flit
===============
To get a development installation of Flit itself::
git clone https://github.com/pypa/flit.git
cd flit
python3 -m pip install docutils requests toml
python3 bootstrap_dev.py
This links Flit into the current Python environment, so you can make changes
and try them without having to reinstall each time.
Testing
-------
To run the tests in separate environments for each available Python version::
tox
`tox <https://tox.readthedocs.io/en/latest/>`_ has many options.
To run the tests in your current environment, run::
pytest

113
doc/flit_ini.rst Normal file
View File

@ -0,0 +1,113 @@
:orphan:
The flit.ini config file
========================
This file lives next to the module or package.
.. note::
Flit 0.12 and above uses a :doc:`pyproject.toml file <pyproject_toml>` file
to store this information. Run ``python3 -m flit.tomlify`` to convert a
``flit.ini`` file to ``pyproject.toml``.
Metadata section
----------------
There are four required fields:
module
The name of the module/package, as you'd use in an import statement.
author
Your name
author-email
Your email address
home-page
A URL for the project, such as its Github repository.
e.g. for flit itself
.. code-block:: ini
[metadata]
module=flit
author=Thomas Kluyver
author-email=thomas@kluyver.me.uk
home-page=https://github.com/pypa/flit
The remaining fields are optional:
requires
A list of other packages from PyPI that this package needs. Each package
should be on its own line, and may be followed by a version specifier in
parentheses, like ``(>=4.1)``, and/or an `environment marker
<https://www.python.org/dev/peps/pep-0345/#environment-markers>`_
after a semicolon. For example:
.. code-block:: ini
requires = requests (>=2.6)
configparser; python_version == '2.7'
dev-requires
Packages that are required for development. This field is in the same format
as ``requires``.
These are not (yet) encoded in the wheel, but are used when doing
``flit install``.
description-file
A path (relative to the .ini file) to a file containing a longer description
of your package to show on PyPI. This should be written in `reStructuredText
<http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_, if your long
description is not valid reStructuredText, a warning will be printed,
and it will be interpreted as plain text on PyPI.
classifiers
A list of `Trove classifiers <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_,
one per line, indented.
requires-python
A version specifier for the versions of Python this requires, e.g. ``~=3.3`` or
``>=3.3,<4`` which are equivalents.
dist-name
If you want your package's name on PyPI to be different from the importable
module name, set this to the PyPI name.
keywords
Comma separated list of words to help with searching for your package.
license
The name of a license, if you're using one for which there isn't a Trove
classifier. It's recommended to use Trove classifiers instead of this in
most cases.
maintainer, maintainer-email
Like author, for if you've taken over a project from someone else.
Here's the full example from flit itself:
.. code-block:: ini
[metadata]
author=Thomas Kluyver
author-email=thomas@kluyver.me.uk
home-page=https://github.com/pypa/flit
requires=requests
requires-python= >=3
description-file=README.rst
classifiers=Intended Audience :: Developers
License :: OSI Approved :: BSD License
Programming Language :: Python :: 3
Topic :: Software Development :: Libraries :: Python Modules
.. _flit_ini_scripts:
Scripts section
---------------
Each key and value in this describes a shell command to be installed along with
your package. These work like setuptools 'entry points'. Here's the section
for flit:
.. code-block:: ini
[scripts]
flit = flit:main
This will create a ``flit`` command, which will call the function ``main()``
imported from :mod:`flit`.

470
doc/history.rst Normal file
View File

@ -0,0 +1,470 @@
Release history
===============
Version 3.7.1
-------------
- Fix building packages which need execution to get the version number,
and have a relative import in ``__init__.py`` (:ghpull:`531`).
Version 3.7
-----------
- Support for :ref:`external data files <pyproject_toml_external_data>` such
as man pages or Jupyter extension support files (:ghpull:`510`).
- Project names are now lowercase in wheel filenames and ``.dist-info`` folder
names, in line with the specifications (:ghpull:`498`).
- Improved support for :doc:`bootstrapping <bootstrap>` a Python environment,
e.g. for downstream packagers (:ghpull:`511`). ``flit_core.wheel`` is usable
with ``python -m`` to create wheels before the `build <https://pypi.org/project/build/>`_
tool is available, and ``flit_core`` sdists also include a script to install
itself from a wheel before `installer <https://pypi.org/project/installer/>`_
is available.
- Use newer importlib APIs, fixing some deprecation warnings (:ghpull:`499`).
Version 3.6
-----------
- ``flit_core`` now bundles the `tomli <https://pypi.org/project/tomli/>`_ TOML
parser library (version 1.2.3) to avoid a circular dependency between
``flit_core`` and ``tomli`` (:ghpull:`492`). This means ``flit_core`` now has
no dependencies except Python itself, both at build time and at runtime,
simplifying :doc:`bootstrapping <bootstrap>`.
Version 3.5.1
-------------
- Fix development installs with ``flit install --symlink`` and ``--pth-file``,
which were broken in 3.5.0, especially for packages using a ``src`` folder
(:ghpull:`472`).
Version 3.5
-----------
- You can now use Flit to distribute a module or package inside a namespace
package (as defined by :pep:`420`). To do this, specify the import name of the
concrete, inner module you are packaging - e.g. ``name = "sphinxcontrib.foo"``
- either in the ``[project]`` table, or under ``[tool.flit.module]`` if you
want to use a different name on PyPI (:ghpull:`468`).
- Flit no longer generates a ``setup.py`` file in sdists (``.tar.gz`` packages)
by default (:ghpull:`462`). Modern packaging tools don't need this. You can
use the ``--setup-py`` flag to keep adding it for now, but this will probably
be removed at some point in the future.
- Fixed how ``flit init`` handles authors' names with non-ASCII characters
(:ghpull:`460`).
- When ``flit init`` generates a LICENSE file, the new ``pyproject.toml`` now
references it (:ghpull:`467`).
Version 3.4
-----------
- Python 3.6 or above is now required, both for ``flit`` and ``flit_core``.
- Add a ``--setup-py`` option to ``flit build`` and ``flit publish``, and a
warning when neither this nor ``--no-setup-py`` are specified (:ghpull:`431`).
A future version will stop generating ``setup.py`` files in sdists by default.
- Add support for standardised editable installs - ``pip install -e`` -
according to :pep:`660` (:ghpull:`400`).
- Add a ``--pypirc`` option for ``flit publish`` to specify an alternative path
to a ``.pypirc`` config file describing package indexes (:ghpull:`434`).
- Fix installing dependencies specified in a ``[project]`` table (:ghpull:`433`).
- Fix building wheels when ``SOURCE_DATE_EPOCH`` (see :doc:`reproducible`) is
set to a date before 1980 (:ghpull:`448`).
- Switch to using the `tomli <https://pypi.org/project/tomli/>`_ TOML parser,
in common with other packaging projects (:ghpull:`438`).
This supports TOML version 1.0.
- Add a document on :doc:`bootstrap` (:ghpull:`441`).
Version 3.3
-----------
- ``PKG-INFO`` files in sdists are now generated the same way as ``METADATA`` in
wheels, fixing some issues with sdists (:ghpull:`410`).
- ``flit publish`` now sends SHA-256 hashes, fixing uploads to GitLab package
repositories (:ghpull:`416`).
- The ``[project]`` metadata table from :pep:`621` is now fully supported and
:ref:`documented <pyproject_toml_project>`. Projects using this can now
specify ``requires = ["flit_core >=3.2,<4"]`` in the ``[build-system]`` table.
Version 3.2
-----------
- Experimental support for specifying metadata in a ``[project]`` table in
``pyproject.toml`` as specified by :pep:`621` (:ghpull:`393`). If you try
using this, please specify ``requires = ["flit_core >=3.2.0,<3.3"]`` in the
``[build-system]`` table for now, in case it needs to change for the next
release.
- Fix writing METADATA file with multi-line information in certain fields
such as ``Author`` (:ghpull:`402`).
- Fix building wheel when a directory such as LICENSES appears in the project
root directory (:ghpull:`401`).
Version 3.1
-----------
- Update handling of names & version numbers in wheel filenames and
``.dist-info`` folders in line with changes in the specs (:ghpull:`395`).
- Switch from the deprecated ``pytoml`` package to ``toml`` (:ghpull:`378`).
- Fix specifying backend-path in ``pyproject.toml`` for flit-core (as a list
instead of a string).
Version 3.0
-----------
Breaking changes:
- Projects must now provide Flit with information in ``pyproject.toml`` files,
not the older ``flit.ini`` format (:ghpull:`338`).
- ``flit_core`` once again requires Python 3 (>=3.4). Packages that support
Python 2 can still be built by ``flit_core`` 2.x, but can't rely on new
features (:ghpull:`342`).
- The deprecated ``flit installfrom`` command was removed (:ghpull:`334`).
You can use ``pip install git+https://github.com/...`` instead.
Features and fixes:
- Fix building sdists from a git repository with non-ASCII characters in
filenames (:ghpull:`346`).
- Fix identifying the version number when the code contains a subscript
assignment before ``__version__ =`` (:ghpull:`348`).
- Script entry points can now use a class method (:ghpull:`359`).
- Set suitable permission bits on metadata files in wheels (:ghpull:`256`).
- Fixed line endings in the ``RECORD`` file when installing on Windows
(:ghpull:`368`).
- Support for recording the source of local installations, as in :pep:`610`
(:ghpull:`335`).
- ``flit init`` will check for a README in the root of the project and
automatically set it as ``description-file`` (:ghpull:`337`).
- Pygments is not required for checking reStructuredText READMEs (:ghpull:`357`).
- Packages where the version number can be recognised without executing their
code don't need their dependencies installed to build, which should make them
build faster (:ghpull:`361`).
- Ensure the installed ``RECORD`` file is predictably ordered (:ghpull:`366`).
Version 2.3
-----------
- New projects created with :ref:`init_cmd` now declare that they require
``flit_core >=2,<4`` (:ghpull:`328`). Any projects using ``pyproject.toml``
(not ``flit.ini``) should be compatible with flit 3.x.
- Fix selecting files from a git submodule to include in an sdist
(:ghpull:`324`).
- Fix checking classifiers when no writeable cache directory is available
(:ghpull:`319`).
- Better errors when trying to install to a mis-spelled or missing Python
interpreter (:ghpull:`331`).
- Fix specifying ``--repository`` before ``upload`` (:ghpull:`322`). Passing the
option like this is deprecated, and you should now pass it after ``upload``.
- Documentation improvements (:ghpull:`327`, :ghpull:`318`, :ghpull:`314`)
Version 2.2
-----------
- Allow underscores in package names with Python 2 (:ghpull:`305`).
- Add a ``--no-setup-py`` option to build sdists without a backwards-compatible
``setup.py`` file (:ghpull:`311`).
- Fix the generated ``setup.py`` file for packages using a ``src/`` layout
(:ghpull:`303`).
- Fix detecting when more than one file matches the module name specified
(:ghpull:`307`).
- Fix installing to a venv on Windows with the ``--python`` option
(:ghpull:`300`).
- Don't echo the command in scripts installed with ``--symlink`` or
``--pth-file`` on Windows (:ghpull:`310`).
- New ``bootstrap_dev.py`` script to set up a development installation of Flit
from the repository (:ghpull:`301`, :ghpull:`306`).
Version 2.1
-----------
- Use compression when adding files to wheels.
- Added the :envvar:`FLIT_INSTALL_PYTHON` environment variable (:ghpull:`295`),
to configure flit to always install into a Python other than the one it's
running on.
- ``flit_core`` uses the ``intreehooks`` shim package to load its bootstrapping
backend, until a released version of pip supports the standard
``backend-path`` mechanism.
Version 2.0
-----------
Flit 2 is a major architecture change. The ``flit_core`` package now provides
a :pep:`517` backend for building packages, while ``flit`` is a
:doc:`command line interface <cmdline>` extending that.
The build backend works on Python 2, so tools like pip should be able to install
packages built with flit from source on Python 2.
The ``flit`` command requires Python 3.5 or above.
You will need to change the build-system table in your ``pyproject.toml`` file
to look like this:
.. code-block:: toml
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
Other changes include:
- Support for storing your code under a ``src/`` folder (:ghpull:`260`).
You don't need to change any configuration if you do this.
- Options to control what files are included in an sdist - see
:ref:`pyproject_toml_sdist` for the details.
- Requirements can specify a URL 'direct reference', as an alternative to a
version number, with the syntax defined in :pep:`440`:
``requests @ https://example.com/requests-2.22.0.tar.gz``.
- Fix the shebang of scripts installed with the ``--python`` option and the
``--symlink`` flag (:ghpull:`286`).
- Installing with ``--deps develop`` now installs normal dependencies
as well as development dependencies.
- Author email is no longer required in the metadata table (:ghpull:`289`).
- More error messages are now shown without a traceback (:ghpull:`254`)
Version 1.3
-----------
- Fix for building sdists from a subdirectory in a Mercurial repository
(:ghpull:`233`).
- Fix for getting the docstring and version from modules defining their encoding
(:ghpull:`239`).
- Fix for installing packages with ``flit installfrom`` (:ghpull:`221`).
- Packages with requirements no longer get a spurious ``Provides-Extra: .none``
metadata entry (:ghissue:`228`).
- Better check of whether ``python-requires`` includes any Python 2 version
(:ghpull:`232`).
- Better check of home page URLs in ``flit init`` (:ghpull:`230`).
- Better error message when the description file is not found (:ghpull:`234`).
- Updated a help message to refer to ``pyproject.toml`` (:ghpull:`240`).
- Improve tests of ``flit init`` (:ghpull:`229`).
Version 1.2.1
-------------
- Fix for installing packages with ``flit install``.
- Make ``requests_download`` an extra dependency, to avoid a circular build
dependency. To use ``flit installfrom``, you can install with
``pip install flit[installfrom]``. Note that the ``installfrom`` subcommand
is deprecated, as it will soon be possible to use pip to install Flit projects
directly from a VCS URL.
Version 1.2
-----------
- Fixes for packages specifying ``requires-extra``: sdists should now work, and
environment markers can be used together with ``requires-extra``.
- Fix running ``flit installfrom`` without a config file present in the
working directory.
- The error message for a missing or empty docstring tells you what file
the docstring should be in.
- Improvements to documentation on version selectors for requirements.
Version 1.1
-----------
- Packages can now have 'extras', specified as ``requires-extra`` in the
:doc:`pyproject.toml file <pyproject_toml>`. These are additional dependencies
for optional features.
- The ``home-page`` metadata field is no longer required.
- Additional project URLs are now validated.
- ``flit -V`` is now equivalent to ``flit --version``.
- Various improvements to documentation.
Version 1.0
-----------
- The description file may now be written in reStructuredText, Markdown or
plain text. The file extension should indicate which of these formats it is
(``.rst``, ``.md`` or ``.txt``). Previously, only reStructuredText was
officially supported.
- Multiple links (e.g. documentation, bug tracker) can now be specified in a
new :ref:`[tool.flit.metadata.urls] section <pyproject_toml_urls>` of
``pyproject.toml``.
- Dependencies are now correctly installed to the target Python when you use
the ``--symlink`` or ``--pth-file`` options.
- Dependencies are only installed to the Python where Flit is running if
it fails to get the docstring and version number without them.
- The commands deprecated in 0.13—``flit wheel``, ``flit sdist`` and
``flit register``—have been removed.
Although version 1.0 sounds like a milestone, there's nothing that makes this
release especially significant. It doesn't represent a step change in stability
or completeness. Flit has been gradually maturing for some time, and I chose
this point to end the series of 0.x version numbers.
Version 0.13
------------
- Better validation of several metadata fields (``dist-name``, ``requires``,
``requires-python``, ``home-page``), and of the version number.
- New :envvar:`FLIT_ALLOW_INVALID` environment variable to ignore validation
failures in case they go wrong.
- The list of valid classifiers is now fetched from Warehouse (https://pypi.org),
rather than the older https://pypi.python.org site.
- Deprecated ``flit wheel`` and ``flit sdist`` subcommands: use
:ref:`build_cmd`.
- Deprecated ``flit register``: you can no longer register a package separately
from uploading it.
Version 0.12.3
--------------
- Fix building and installing packages with a ``-`` in the distribution name.
- Fix numbering in README.
Version 0.12.2
--------------
- New tool to convert ``flit.ini`` to ``pyproject.toml``::
python3 -m flit.tomlify
- Use the PAX tar format for sdists, as specified by PEP 517.
Version 0.12.1
--------------
- Restore dependency on ``zipfile36`` backport package.
- Add some missing options to documentation of ``flit install`` subcommand.
- Rearrange environment variables in the docs.
Version 0.12
------------
- Switch the config to ``pyproject.toml`` by default instead of ``flit.ini``,
and implement the PEP 517 API.
- A new option ``--pth-file`` allows for development installation on Windows
(where ``--symlink`` usually won't work).
- Normalise file permissions in the zip file, making builds more reproducible
across different systems.
- Sdists (.tar.gz packages) can now also be reproducibly built by setting
:envvar:`SOURCE_DATE_EPOCH`.
- For most modules, Flit can now extract the version number and docstring
without importing it. It will still fall back to importing where getting
these from the AST fails.
- ``flit build`` will build the wheel from the sdist, helping to ensure that
files aren't left out of the sdist.
- All list fields in the INI file now ignore blank lines (``requires``,
``dev-requires``, ``classifiers``).
- Fix the path separator in the ``RECORD`` file of a wheel built on Windows.
- Some minor fixes to building reproducible wheels.
- If building a wheel fails, the temporary file created will be cleaned up.
- Various improvements to docs and README.
Version 0.11.4
--------------
- Explicitly open various files as UTF-8, rather than relying on locale
encoding.
- Link to docs from README.
- Better test coverage, and a few minor fixes for problems revealed by tests.
Version 0.11.3
--------------
- Fixed a bug causing failed uploads when the password is entered in the
terminal.
Version 0.11.2
--------------
- A couple of behaviour changes when uploading to warehouse.
Version 0.11.1
--------------
- Fixed a bug when you use flit to build an sdist from a subdirectory inside a
VCS checkout. The VCS is now correctly detected.
- Fix the rst checker for newer versions of docutils, by upgrading the bundled
copy of readme_renderer.
Version 0.11
------------
- Flit can now build sdists (tarballs) and upload them to PyPI, if your code is
in a git or mercurial repository. There are new commands:
- ``flit build`` builds both a wheel and an sdist.
- ``flit publish`` builds and uploads a wheel and an sdist.
- Smarter ways of getting the information needed for upload:
- If you have the `keyring <https://github.com/jaraco/keyring>`_ package
installed, flit can use it to store your password, rather than keeping it
in plain text in ``~/.pypirc``.
- If ``~/.pypirc`` does not already exist, and you are prompted for your
username, flit will write it into that file.
- You can provide the information as environment variables:
:envvar:`FLIT_USERNAME`, :envvar:`FLIT_PASSWORD` and :envvar:`FLIT_INDEX_URL`.
Use this to upload packages from a CI service, for instance.
- Include 'LICENSE' or 'COPYING' files in wheels.
- Fix for ``flit install --symlink`` inside a virtualenv.
Version 0.10
------------
- Downstream packagers can use the :envvar:`FLIT_NO_NETWORK` environment
variable to stop flit downloading data from the network.
Version 0.9
-----------
- ``flit install`` and ``flit installfrom`` now take an optional ``--python`` argument,
with the path to the Python executable you want to install it for.
Using this, you can install modules to Python 2.
- Installing a module normally (without ``--symlink``) builds a wheel and uses
pip to install it, which should work better in some corner cases.
Version 0.8
-----------
- A new ``flit installfrom`` subcommand to install a project from a source
archive, such as from Github.
- :doc:`Reproducible builds <reproducible>` - you can produce byte-for-byte
identical wheels.
- A warning for non-canonical version numbers according to `PEP 440
<https://www.python.org/dev/peps/pep-0440/>`__.
- Fix for installing projects on Windows.
- Better error message when module docstring is only whitespace.
Version 0.7
-----------
- A new ``dev-requires`` field in the config file for development requirements,
used when doing ``flit install``.
- Added a ``--deps`` option for ``flit install`` to control which dependencies
are installed.
- Flit can now be invoked with ``python -m flit``.
Version 0.6
-----------
- ``flit install`` now ensures requirements specified in ``flit.ini`` are
installed, using pip.
- If you specify a description file, flit now warns you if it's not valid
reStructuredText (since invalid reStructuredText is treated as plain text on
PyPI).
- Improved the error message for mis-spelled keys in ``flit.ini``.
Version 0.5
-----------
- A new ``flit init`` command to quickly define the essential basic metadata
for a package.
- Support for entry points.
- A new ``flit register`` command to register a package without uploading it,
for when you want to claim a name before you're ready to release.
- Added a ``--repository`` option for specifying an alternative PyPI instance.
- Added a ``--debug`` flag to show debug-level log messages.
- Better error messages when the module docstring or ``__version__`` is missing.
Version 0.4
-----------
- Users can now specify ``dist-name`` in the config file if they need to use
different names on PyPI and for imports.
- Classifiers are now checked against a locally cached list of valid
classifiers.
- Packages can be locally installed into environments for development.
- Local installation now creates a PEP 376 ``.dist-info`` folder instead of
``.egg-info``.

34
doc/index.rst Normal file
View File

@ -0,0 +1,34 @@
Flit |version|
==============
.. raw:: html
<img src="_static/flit_logo_nobg_cropped.svg" width="200px" style="float: right"/>
.. include:: ../README.rst
Documentation contents
----------------------
.. toctree::
:maxdepth: 2
pyproject_toml
cmdline
upload
reproducible
rationale
bootstrap
.. toctree::
:maxdepth: 1
development
history
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`

242
doc/make.bat Normal file
View File

@ -0,0 +1,242 @@
@ECHO OFF
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set BUILDDIR=_build
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
set I18NSPHINXOPTS=%SPHINXOPTS% .
if NOT "%PAPER%" == "" (
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
)
if "%1" == "" goto help
if "%1" == "help" (
:help
echo.Please use `make ^<target^>` where ^<target^> is one of
echo. html to make standalone HTML files
echo. dirhtml to make HTML files named index.html in directories
echo. singlehtml to make a single large HTML file
echo. pickle to make pickle files
echo. json to make JSON files
echo. htmlhelp to make HTML files and a HTML help project
echo. qthelp to make HTML files and a qthelp project
echo. devhelp to make HTML files and a Devhelp project
echo. epub to make an epub
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
echo. text to make text files
echo. man to make manual pages
echo. texinfo to make Texinfo files
echo. gettext to make PO message catalogs
echo. changes to make an overview over all changed/added/deprecated items
echo. xml to make Docutils-native XML files
echo. pseudoxml to make pseudoxml-XML files for display purposes
echo. linkcheck to check all external links for integrity
echo. doctest to run all doctests embedded in the documentation if enabled
goto end
)
if "%1" == "clean" (
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
del /q /s %BUILDDIR%\*
goto end
)
%SPHINXBUILD% 2> nul
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
if "%1" == "html" (
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
goto end
)
if "%1" == "dirhtml" (
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
goto end
)
if "%1" == "singlehtml" (
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
goto end
)
if "%1" == "pickle" (
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the pickle files.
goto end
)
if "%1" == "json" (
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can process the JSON files.
goto end
)
if "%1" == "htmlhelp" (
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run HTML Help Workshop with the ^
.hhp project file in %BUILDDIR%/htmlhelp.
goto end
)
if "%1" == "qthelp" (
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished; now you can run "qcollectiongenerator" with the ^
.qhcp project file in %BUILDDIR%/qthelp, like this:
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\Flit.qhcp
echo.To view the help file:
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\Flit.ghc
goto end
)
if "%1" == "devhelp" (
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
if errorlevel 1 exit /b 1
echo.
echo.Build finished.
goto end
)
if "%1" == "epub" (
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The epub file is in %BUILDDIR%/epub.
goto end
)
if "%1" == "latex" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
if errorlevel 1 exit /b 1
echo.
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdf" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf
cd %BUILDDIR%/..
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "latexpdfja" (
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
cd %BUILDDIR%/latex
make all-pdf-ja
cd %BUILDDIR%/..
echo.
echo.Build finished; the PDF files are in %BUILDDIR%/latex.
goto end
)
if "%1" == "text" (
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The text files are in %BUILDDIR%/text.
goto end
)
if "%1" == "man" (
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The manual pages are in %BUILDDIR%/man.
goto end
)
if "%1" == "texinfo" (
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
goto end
)
if "%1" == "gettext" (
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
goto end
)
if "%1" == "changes" (
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
if errorlevel 1 exit /b 1
echo.
echo.The overview file is in %BUILDDIR%/changes.
goto end
)
if "%1" == "linkcheck" (
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
if errorlevel 1 exit /b 1
echo.
echo.Link check complete; look for any errors in the above output ^
or in %BUILDDIR%/linkcheck/output.txt.
goto end
)
if "%1" == "doctest" (
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
if errorlevel 1 exit /b 1
echo.
echo.Testing of doctests in the sources finished, look at the ^
results in %BUILDDIR%/doctest/output.txt.
goto end
)
if "%1" == "xml" (
%SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The XML files are in %BUILDDIR%/xml.
goto end
)
if "%1" == "pseudoxml" (
%SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
if errorlevel 1 exit /b 1
echo.
echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
goto end
)
:end

468
doc/pyproject_toml.rst Normal file
View File

@ -0,0 +1,468 @@
The pyproject.toml config file
==============================
This file lives next to the module or package.
.. note::
Older version of Flit (up to 0.11) used a :doc:`flit.ini file <flit_ini>` for
similar information. These files no longer work with Flit 3 and above.
Run ``python3 -m flit.tomlify`` to convert a ``flit.ini`` file to
``pyproject.toml``.
Build system section
--------------------
This tells tools like pip to build your project with flit. It's a standard
defined by PEP 517. For any new project using Flit, it will look like this:
.. code-block:: toml
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
Version constraints:
- For now, all packages should specify ``<4``, so they won't be impacted by
changes in the next major version.
- :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).
.. _pyproject_toml_project:
New style metadata
------------------
.. versionadded:: 3.2
The new standard way to specify project metadata is in a ``[project]`` table,
as defined by :pep:`621`. Flit works for now with either this or the older
``[tool.flit.metadata]`` table (:ref:`described below <pyproject_old_metadata>`),
but it won't allow you to mix them.
A simple ``[project]`` table might look like this:
.. code-block:: toml
[project]
name = "astcheck"
authors = [
{name = "Thomas Kluyver", email = "thomas@kluyver.me.uk"},
]
readme = "README.rst"
classifiers = [
"License :: OSI Approved :: MIT License",
]
requires-python = ">=3.5"
dynamic = ["version", "description"]
The allowed fields are:
name
The name your package will have on PyPI. This field is required. For Flit,
this also points to your package as an import name by default (see
:ref:`pyproject_module` if that needs to be different).
version
Version number as a string. If you want Flit to get this from a
``__version__`` attribute, leave it out of the TOML config and include
"version" in the ``dynamic`` field.
description
A one-line description of your project. If you want Flit to get this from
the module docstring, leave it out of the TOML config and include
"description" in the ``dynamic`` field.
readme
A path (relative to the .toml file) to a file containing a longer description
of your package to show on PyPI. This should be written in `reStructuredText
<http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_, Markdown or
plain text, and the filename should have the appropriate extension
(``.rst``, ``.md`` or ``.txt``). Alternatively, ``readme`` can be a table with
either a ``file`` key (a relative path) or a ``text`` key (literal text), and
an optional ``content-type`` key (e.g. ``text/x-rst``).
requires-python
A version specifier for the versions of Python this requires, e.g. ``~=3.3`` or
``>=3.3,<4``, which are equivalents.
license
A table with either a ``file`` key (a relative path to a license file) or a
``text`` key (the license text).
authors
A list of tables with ``name`` and ``email`` keys (both optional) describing
the authors of the project.
maintainers
Same format as authors.
keywords
A list of words to help with searching for your package.
classifiers
A list of `Trove classifiers <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_.
Add ``Private :: Do Not Upload`` into the list to prevent a private package
from being uploaded to PyPI by accident.
dependencies & optional-dependencies
See :ref:`pyproject_project_dependencies`.
urls
See :ref:`pyproject_project_urls`.
scripts & gui-scripts
See :ref:`pyproject_project_scripts`.
entry-points
See :ref:`pyproject_project_entrypoints`.
dynamic
A list of field names which aren't specified here, for which Flit should
find a value at build time. Only "version" and "description" are accepted.
.. _pyproject_project_dependencies:
Dependencies
~~~~~~~~~~~~
The ``dependencies`` field is a list of other packages from PyPI that this
package needs. Each package may be followed by a version specifier like
``>=4.1``, and/or an `environment marker`_
after a semicolon. For example:
.. code-block:: toml
dependencies = [
"requests >=2.6",
"configparser; python_version == '2.7'",
]
The ``[project.optional-dependencies]`` table contains lists of packages needed
for every optional feature. The requirements are specified in the same format as
for ``dependencies``. For example:
.. code-block:: toml
[project.optional-dependencies]
test = [
"pytest >=2.7.3",
"pytest-cov",
]
doc = ["sphinx"]
You can call these optional features anything you want, although ``test`` and
``doc`` are common ones. You specify them for installation in square brackets
after the package name or directory, e.g. ``pip install '.[test]'``.
.. _pyproject_project_urls:
URLs table
~~~~~~~~~~
Your project's page on `pypi.org <https://pypi.org/>`_ can show a number of
links. You can point people to documentation or a bug tracker, for example.
This section is called ``[project.urls]`` in the file. You can use
any names inside it. Here it is for flit:
.. code-block:: toml
[project.urls]
Documentation = "https://flit.readthedocs.io/en/latest/"
Source = "https://github.com/pypa/flit"
.. _pyproject_project_scripts:
Scripts section
~~~~~~~~~~~~~~~
This section is called ``[project.scripts]`` in the file.
Each key and value describes a shell command to be installed along with
your package. These work like setuptools 'entry points'. Here's the section
for flit:
.. code-block:: toml
[project.scripts]
flit = "flit:main"
This will create a ``flit`` command, which will call the function ``main()``
imported from :mod:`flit`.
A similar table called ``[project.gui-scripts]`` defines commands which launch
a GUI. This only makes a difference on Windows, where GUI scripts are run
without a console.
.. _pyproject_project_entrypoints:
Entry points sections
~~~~~~~~~~~~~~~~~~~~~
You can declare `entry points <http://entrypoints.readthedocs.io/en/latest/>`_
using sections named :samp:`[project.entry-points.{groupname}]`. E.g. to
provide a pygments lexer from your package:
.. code-block:: toml
[project.entry-points."pygments.lexers"]
dogelang = "dogelang.lexer:DogeLexer"
In each ``package:name`` value, the part before the colon should be an
importable module name, and the latter part should be the name of an object
accessible within that module. The details of what object to expose depend on
the application you're extending.
If the group name contains a dot, it must be quoted (``"pygments.lexers"``
above). Script entry points are defined in :ref:`scripts tables
<pyproject_project_scripts>`, so you can't use the group names
``console_scripts`` or ``gui_scripts`` here.
.. _pyproject_module:
Module section
~~~~~~~~~~~~~~
If your package will have different names for installation and import,
you should specify the install (PyPI) name in the ``[project]`` table
(:ref:`see above <pyproject_toml_project>`), and the import name in a
``[tool.flit.module]`` table:
.. code-block:: toml
[project]
name = "pynsist"
# ...
[tool.flit.module]
name = "nsist"
.. _pyproject_old_metadata:
Old style metadata
------------------
Flit's older way to specify metadata is in a ``[tool.flit.metadata]`` table,
along with ``[tool.flit.scripts]`` and ``[tool.flit.entrypoints]``, described
below. This is still recognised for now, but you can't mix it with
:ref:`pyproject_toml_project`.
There are three required fields:
module
The name of the module/package, as you'd use in an import statement.
author
Your name
author-email
Your email address
e.g. for flit itself
.. code-block:: toml
[tool.flit.metadata]
module = "flit"
author = "Thomas Kluyver"
author-email = "thomas@kluyver.me.uk"
.. versionchanged:: 1.1
``home-page`` was previously required.
The remaining fields are optional:
home-page
A URL for the project, such as its Github repository.
requires
A list of other packages from PyPI that this package needs. Each package may
be followed by a version specifier like ``(>=4.1)`` or ``>=4.1``, and/or an
`environment marker`_
after a semicolon. For example:
.. code-block:: toml
requires = [
"requests >=2.6",
"configparser; python_version == '2.7'",
]
requires-extra
Lists of packages needed for every optional feature. The requirements
are specified in the same format as for ``requires``. The requirements of
the two reserved extras ``test`` and ``doc`` as well as the extra ``dev``
are installed by ``flit install``. For example:
.. code-block:: toml
[tool.flit.metadata.requires-extra]
test = [
"pytest >=2.7.3",
"pytest-cov",
]
doc = ["sphinx"]
.. versionadded:: 1.1
description-file
A path (relative to the .toml file) to a file containing a longer description
of your package to show on PyPI. This should be written in `reStructuredText
<http://docutils.sourceforge.net/docs/user/rst/quickref.html>`_, Markdown or
plain text, and the filename should have the appropriate extension
(``.rst``, ``.md`` or ``.txt``).
classifiers
A list of `Trove classifiers <https://pypi.python.org/pypi?%3Aaction=list_classifiers>`_.
Add ``Private :: Do Not Upload`` into the list to prevent a private package
from uploading on PyPI by accident.
requires-python
A version specifier for the versions of Python this requires, e.g. ``~=3.3`` or
``>=3.3,<4`` which are equivalents.
dist-name
If you want your package's name on PyPI to be different from the importable
module name, set this to the PyPI name.
keywords
Comma separated list of words to help with searching for your package.
license
The name of a license, if you're using one for which there isn't a Trove
classifier. It's recommended to use Trove classifiers instead of this in
most cases.
maintainer, maintainer-email
Like author, for if you've taken over a project from someone else.
Here was the metadata section from flit using the older style:
.. code-block:: toml
[tool.flit.metadata]
module="flit"
author="Thomas Kluyver"
author-email="thomas@kluyver.me.uk"
home-page="https://github.com/pypa/flit"
requires=[
"flit_core >=2.2.0",
"requests",
"docutils",
"tomli",
"tomli-w",
]
requires-python=">=3.6"
description-file="README.rst"
classifiers=[
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries :: Python Modules",
]
.. _pyproject_toml_urls:
URLs subsection
~~~~~~~~~~~~~~~
Your project's page on `pypi.org <https://pypi.org/>`_ can show a number of
links, in addition to the ``home-page`` URL described above. You can
point people to documentation or a bug tracker, for example.
This section is called ``[tool.flit.metadata.urls]`` in the file. You can use
any names inside it. Here it is for flit:
.. code-block:: toml
[tool.flit.metadata.urls]
Documentation = "https://flit.readthedocs.io/en/latest/"
.. versionadded:: 1.0
.. _pyproject_toml_scripts:
Scripts section
~~~~~~~~~~~~~~~
A ``[tool.flit.scripts]`` table can be used along with ``[tool.flit.metadata]``.
It is in the same format as the newer ``[project.scripts]`` table
:ref:`described above <pyproject_project_scripts>`.
Entry points sections
~~~~~~~~~~~~~~~~~~~~~
``[tool.flit.entrypoints]`` tables can be used along with ``[tool.flit.metadata]``.
They are in the same format as the newer ``[project.entry-points]`` tables
:ref:`described above <pyproject_project_entrypoints>`.
.. _pyproject_toml_sdist:
Sdist section
-------------
.. versionadded:: 2.0
When you use :ref:`build_cmd` or :ref:`publish_cmd`, Flit builds an sdist
(source distribution) tarball containing the files that are checked into version
control (git or mercurial). If you want more control, or it doesn't recognise
your version control system, you can give lists of paths or glob patterns as
``include`` and ``exclude`` in this section. For example:
.. code-block:: toml
[tool.flit.sdist]
include = ["doc/"]
exclude = ["doc/*.html"]
These paths:
- Always use ``/`` as a separator (POSIX style)
- Must be relative paths from the directory containing ``pyproject.toml``
- Cannot go outside that directory (no ``../`` paths)
- Cannot contain control characters or ``<>:"\\``
- Cannot use recursive glob patterns (``**/``)
- Can refer to directories, in which case they include everything under the
directory, including subdirectories
- Should match the case of the files they refer to, as case-insensitive matching
is platform dependent
Exclusions have priority over inclusions.
.. note::
If you are not using :ref:`build_cmd` but ``flit_core`` via another build
frontend, Flit doesn't doesn't check the VCS for files to include but instead
builds a 'minimal' sdist (which includes the files necessary to build a wheel).
You'll have to adapt your inclusion/exclusion rules to achieve the same result
as you'd get with :ref:`build_cmd`.
.. _pyproject_toml_external_data:
External data section
---------------------
.. versionadded:: 3.7
Data files which your code will use should go inside the Python package folder.
Flit will package these with no special configuration.
However, sometimes it's useful to package external files for system integration,
such as man pages or files defining a Jupyter extension. To do this, arrange
the files within a directory such as ``data``, next to your ``pyproject.toml``
file, and add a section like this:
.. code-block:: toml
[tool.flit.external-data]
directory = "data"
Paths within this directory are typically installed to corresponding paths under
a prefix (such as a virtualenv directory). E.g. you might save a man page for a
script as ``(data)/share/man/man1/foo.1``.
Whether these files are detected by the systems they're meant to integrate with
depends on how your package is installed and how those systems are configured.
For instance, installing in a virtualenv usually doesn't affect anything outside
that environment. Don't rely on these files being picked up unless you have
close control of how the package will be installed.
If you install a package with ``flit install --symlink``, a symlink is made
for each file in the external data directory. Otherwise (including development
installs with ``pip install -e``), these files are copied to their destination,
so changes here won't take effect until you reinstall the package.
.. note::
For users coming from setuptools: external data corresponds to setuptools'
``data_files`` parameter, although setuptools offers more flexibility.
.. _environment marker: https://www.python.org/dev/peps/pep-0508/#environment-markers

58
doc/rationale.rst Normal file
View File

@ -0,0 +1,58 @@
Why use Flit?
=============
*Make the easy things easy and the hard things possible* is an old motto from
the Perl community. Flit is entirely focused on the *easy things* part of that,
and leaves the hard things up to other tools.
Specifically, the easy things are pure Python packages with no build steps
(neither compiling C code, nor bundling Javascript, etc.). The vast majority of
packages on PyPI are like this: plain Python code, with maybe some static data
files like icons included.
It's easy to underestimate the challenges involved in distributing and
installing code, because it seems like you just need to copy some files into
the right place. There's a whole lot of metadata and tooling that has to work
together around that fundamental step. But with the right tooling, a developer
who wants to release their code doesn't need to know about most of that.
What, specifically, does Flit make easy?
- ``flit init`` helps you set up the information Flit needs about your
package.
- Subpackages are automatically included: you only need to specify the
top-level package.
- Data files within a package directory are automatically included.
Missing data files has been a common packaging mistake with other tools.
- The version number is taken from your package's ``__version__`` attribute,
so that always matches the version that tools like pip see.
- ``flit publish`` uploads a package to PyPI, so you don't need a separate tool
to do this.
Setuptools, the most common tool for Python packaging, now has shortcuts for
many of the same things. But it has to stay compatible with projects published
many years ago, which limits what it can do by default.
Flit also has some support for :doc:`reproducible builds <reproducible>`,
a feature which some people care about.
There have been many other efforts to improve the user experience of Python
packaging, such as `pbr <https://pypi.org/project/pbr/>`_, but before Flit,
these tended to build on setuptools and distutils. That was a pragmatic
decision, but it's hard to build something radically different on top of those
libraries. The existence of Flit spurred the development of new standards,
like :pep:`518` and :pep:`517`, which are now used by other packaging tools
such as `Poetry <https://python-poetry.org/>`_ and
`Enscons <https://pypi.org/project/enscons/>`_.
Other options
-------------
If your package needs a build step, you won't be able to use Flit.
`Setuptools <https://setuptools.readthedocs.io/en/latest/>`_ is the de-facto
standard, but newer tools such as Enscons_ also cover this case.
Flit also doesn't help you manage dependencies: you have to add them to
``pyproject.toml`` by hand. Tools like Poetry_ and `Pipenv
<https://pypi.org/project/pipenv/>`_ have features which help add and update
dependencies on other packages.

34
doc/reproducible.rst Normal file
View File

@ -0,0 +1,34 @@
Reproducible builds
===================
.. versionadded:: 0.8
Wheels built by flit are reproducible: if you build from the same source code,
you should be able to make wheels that are exactly identical, byte for byte.
This is useful for verifying software. For more details, see
`reproducible-builds.org <https://reproducible-builds.org/>`__.
There is a caveat, however: wheels (which are zip files) include the
modification timestamp from each file. This will
probably be different on each computer, because it indicates when your local
copy of the file was written, not when it was changed in version control.
These timestamps can be overridden by the environment variable
:envvar:`SOURCE_DATE_EPOCH`.
.. code-block:: shell
SOURCE_DATE_EPOCH=$(date +%s)
flit publish
# Record the value of SOURCE_DATE_EPOCH in release notes for reproduction
.. versionchanged:: 0.12
Normalising permission bits
Flit normalises the permission bits of files copied into a wheel to either
755 (executable) or 644. This means that a file is readable by all users
and writable only by the user who owns it.
The most popular version control systems only track the executable bit,
so checking out the same repository on systems with different umasks
(e.g. Debian and Fedora) produces files with different permissions. With Flit
0.11 and earlier, this difference would produce non-identical wheels.

3
doc/requirements.txt Normal file
View File

@ -0,0 +1,3 @@
sphinx ~= 4.2
sphinxcontrib_github_alt ~= 1.2
sphinx-rtd-theme ~= 1.0

77
doc/upload.rst Normal file
View File

@ -0,0 +1,77 @@
Controlling package uploads
===========================
.. program:: flit publish
The command ``flit publish`` will upload your package to a package index server.
The default settings let you upload to `PyPI <https://pypi.org/>`_,
the default Python Package Index, with a single user account.
If you want to upload to other servers, or with more than one user account,
or upload packages from a continuous integration job,
you can configure Flit in two main ways:
Using .pypirc
-------------
You can create or edit a config file in your home directory, ``~/.pypirc`` that
will be used by default or you can specify a custom location.
This is also used by other Python tools such as `twine
<https://pypi.python.org/pypi/twine>`_.
For instance, to upload a package to the `Test PyPI server <https://test.pypi.org/>`_
instead of the normal PyPI, use a config file looking like this:
.. code-block:: ini
[distutils]
index-servers =
pypi
testpypi
[pypi]
repository = https://upload.pypi.org/legacy/
username = sirrobin # Replace with your PyPI username
[testpypi]
repository = https://test.pypi.org/legacy/
username = sirrobin # Replace with your TestPyPI username
You can select an index server from this config file with the
:option:`--repository` option::
flit publish --repository testpypi
If you don't use this option,
Flit will use the server called ``pypi`` in the config file. If that doesn't
exist, it uploads to PyPI at ``https://upload.pypi.org/legacy/`` by default.
If you publish a package and you don't have a ``.pypirc`` file, Flit will create
it to store your username.
Flit tries to store your password securely using the
`keyring <https://pypi.python.org/pypi/keyring>`_ library.
If keyring is not installed, Flit will ask for your password for each upload.
Alternatively, you can also manually add your password to the ``.pypirc`` file
(``password = ...``)
.. _upload_envvars:
Using environment variables
---------------------------
You can specify a server to upload to with :envvar:`FLIT_INDEX_URL`, and
pass credentials with :envvar:`FLIT_USERNAME` and :envvar:`FLIT_PASSWORD`.
Environment variables take precedence over the config file, except if you use
the :option:`--repository` option to explicitly pick a server from the config file.
This can make it easier to automate uploads, for example to release packages
from a continuous integration job.
.. warning::
Storing a password in an environment variable is convenient, but it's
`easy to accidentally leak it <https://www.diogomonica.com/2017/03/27/why-you-shouldnt-use-env-variables-for-secret-data/>`_.
Look out for scripts that helpfully print all environment variables for
debugging, and remember that other scripts and libraries you run in
that environment have access to your password.

203
flit/__init__.py Normal file
View File

@ -0,0 +1,203 @@
"""A simple packaging tool for simple packages."""
import argparse
import logging
import os
import pathlib
import shutil
import subprocess
import sys
from typing import Optional
from flit_core import common
from .config import ConfigError
from .log import enable_colourful_output
__version__ = '3.7.1'
log = logging.getLogger(__name__)
class PythonNotFoundError(FileNotFoundError): pass
def find_python_executable(python: Optional[str] = None) -> str:
"""Returns an absolute filepath to the executable of Python to use."""
if not python:
python = os.environ.get("FLIT_INSTALL_PYTHON")
if not python:
return sys.executable
if os.path.isabs(python): # sys.executable is absolute too
return python
# get absolute filepath of {python}
# shutil.which may give a different result to the raw subprocess call
# see https://github.com/pypa/flit/pull/300 and https://bugs.python.org/issue38905
resolved_python = shutil.which(python)
if resolved_python is None:
raise PythonNotFoundError("Unable to resolve Python executable {!r}".format(python))
try:
return subprocess.check_output(
[resolved_python, "-c", "import sys; print(sys.executable)"],
universal_newlines=True,
).strip()
except Exception as e:
raise PythonNotFoundError(
"{} occurred trying to find the absolute filepath of Python executable {!r} ({!r})".format(
e.__class__.__name__, python, resolved_python
)
) from e
def add_shared_install_options(parser: argparse.ArgumentParser):
parser.add_argument('--user', action='store_true', default=None,
help="Do a user-local install (default if site.ENABLE_USER_SITE is True)"
)
parser.add_argument('--env', action='store_false', dest='user',
help="Install into sys.prefix (default if site.ENABLE_USER_SITE is False, i.e. in virtualenvs)"
)
parser.add_argument('--python',
help="Target Python executable, if different from the one running flit"
)
def main(argv=None):
ap = argparse.ArgumentParser()
ap.add_argument('-f', '--ini-file', type=pathlib.Path, default='pyproject.toml')
ap.add_argument('-V', '--version', action='version', version='Flit '+__version__)
# --repository now belongs on 'flit publish' - it's still here for
# compatibility with scripts passing it before the subcommand.
ap.add_argument('--repository', dest='deprecated_repository', help=argparse.SUPPRESS)
ap.add_argument('--debug', action='store_true', help=argparse.SUPPRESS)
ap.add_argument('--logo', action='store_true', help=argparse.SUPPRESS)
subparsers = ap.add_subparsers(title='subcommands', dest='subcmd')
# flit build --------------------------------------------
parser_build = subparsers.add_parser('build',
help="Build wheel and sdist",
)
parser_build.add_argument('--format', action='append',
help="Select a format to build. Options: 'wheel', 'sdist'"
)
parser_build.add_argument('--setup-py', action='store_true',
help=("Generate a setup.py file in the sdist. "
"The sdist will work with older tools that predate PEP 517. "
)
)
parser_build.add_argument('--no-setup-py', action='store_true',
help=("Don't generate a setup.py file in the sdist. This is the default. "
"The sdist will only work with tools that support PEP 517, "
"but the wheel will still be usable by any compatible tool."
)
)
# flit publish --------------------------------------------
parser_publish = subparsers.add_parser('publish',
help="Upload wheel and sdist",
)
parser_publish.add_argument('--format', action='append',
help="Select a format to publish. Options: 'wheel', 'sdist'"
)
parser_publish.add_argument('--setup-py', action='store_true',
help=("Generate a setup.py file in the sdist. "
"The sdist will work with older tools that predate PEP 517. "
"This is the default for now, but will change in a future version."
)
)
parser_publish.add_argument('--no-setup-py', action='store_true',
help=("Don't generate a setup.py file in the sdist. "
"The sdist will only work with tools that support PEP 517, "
"but the wheel will still be usable by any compatible tool."
)
)
parser_publish.add_argument('--pypirc',
help="The .pypirc config file to be used. DEFAULT = \"~/.pypirc\""
)
parser_publish.add_argument('--repository',
help="Name of the repository to upload to (must be in the specified .pypirc file)"
)
# flit install --------------------------------------------
parser_install = subparsers.add_parser('install',
help="Install the package",
)
parser_install.add_argument('-s', '--symlink', action='store_true',
help="Symlink the module/package into site packages instead of copying it"
)
parser_install.add_argument('--pth-file', action='store_true',
help="Add .pth file for the module/package to site packages instead of copying it"
)
add_shared_install_options(parser_install)
parser_install.add_argument('--deps', choices=['all', 'production', 'develop', 'none'], default='all',
help="Which set of dependencies to install. If --deps=develop, the extras dev, doc, and test are installed"
)
parser_install.add_argument('--extras', default=(), type=lambda l: l.split(',') if l else (),
help="Install the dependencies of these (comma separated) extras additionally to the ones implied by --deps. "
"--extras=all can be useful in combination with --deps=production, --deps=none precludes using --extras"
)
# flit init --------------------------------------------
parser_init = subparsers.add_parser('init',
help="Prepare pyproject.toml for a new package"
)
args = ap.parse_args(argv)
if args.ini_file.suffix == '.ini':
sys.exit("flit.ini format is no longer supported. You can use "
"'python3 -m flit.tomlify' to convert it to pyproject.toml")
if args.subcmd not in {'init'} and not args.ini_file.is_file():
sys.exit('Config file {} does not exist'.format(args.ini_file))
enable_colourful_output(logging.DEBUG if args.debug else logging.INFO)
log.debug("Parsed arguments %r", args)
if args.logo:
from .logo import clogo
print(clogo.format(version=__version__))
sys.exit(0)
def gen_setup_py():
if not (args.setup_py or args.no_setup_py):
return False
return args.setup_py
if args.subcmd == 'build':
from .build import main
try:
main(args.ini_file, formats=set(args.format or []),
gen_setup_py=gen_setup_py())
except(common.NoDocstringError, common.VCSError, common.NoVersionError) as e:
sys.exit(e.args[0])
elif args.subcmd == 'publish':
if args.deprecated_repository:
log.warning("Passing --repository before the 'upload' subcommand is deprecated: pass it after")
repository = args.repository or args.deprecated_repository
from .upload import main
main(args.ini_file, repository, args.pypirc, formats=set(args.format or []),
gen_setup_py=gen_setup_py())
elif args.subcmd == 'install':
from .install import Installer
try:
python = find_python_executable(args.python)
Installer.from_ini_path(args.ini_file, user=args.user, python=python,
symlink=args.symlink, deps=args.deps, extras=args.extras,
pth=args.pth_file).install()
except (ConfigError, PythonNotFoundError, common.NoDocstringError, common.NoVersionError) as e:
sys.exit(e.args[0])
elif args.subcmd == 'init':
from .init import TerminalIniter
TerminalIniter().initialise()
else:
ap.print_help()
sys.exit(1)

5
flit/__main__.py Normal file
View File

@ -0,0 +1,5 @@
from __future__ import absolute_import
from . import main
main()

27
flit/_get_dirs.py Normal file
View File

@ -0,0 +1,27 @@
"""get_dirs() is pulled out as a separate file so we can run it in a target Python.
"""
import os
import sys
import sysconfig
def get_dirs(user=True):
"""Get the 'scripts' and 'purelib' directories we'll install into.
This is now a thin wrapper around sysconfig.get_paths(). It's not inlined,
because some tests mock it out to install to a different location.
"""
if user:
if (sys.platform == "darwin") and sysconfig.get_config_var('PYTHONFRAMEWORK'):
return sysconfig.get_paths('osx_framework_user')
return sysconfig.get_paths(os.name + '_user')
else:
# The default scheme is 'posix_prefix' or 'nt', and should work for e.g.
# installing into a virtualenv
return sysconfig.get_paths()
if __name__ == '__main__':
import json
user = '--user'in sys.argv
dirs = get_dirs(user)
json.dump(dirs, sys.stdout)

60
flit/build.py Normal file
View File

@ -0,0 +1,60 @@
"""flit build - build both wheel and sdist"""
from contextlib import contextmanager
import logging
import os
from pathlib import Path
import tarfile
from tempfile import TemporaryDirectory
from types import SimpleNamespace
import sys
from .config import read_flit_config, ConfigError
from .sdist import SdistBuilder
from .wheel import make_wheel_in
log = logging.getLogger(__name__)
ALL_FORMATS = {'wheel', 'sdist'}
@contextmanager
def unpacked_tarball(path):
tf = tarfile.open(str(path))
with TemporaryDirectory() as tmpdir:
tf.extractall(tmpdir)
files = os.listdir(tmpdir)
assert len(files) == 1, files
yield os.path.join(tmpdir, files[0])
def main(ini_file: Path, formats=None, gen_setup_py=True):
"""Build wheel and sdist"""
if not formats:
formats = ALL_FORMATS
elif not formats.issubset(ALL_FORMATS):
raise ValueError("Unknown package formats: {}".format(formats - ALL_FORMATS))
sdist_info = wheel_info = None
dist_dir = ini_file.parent / 'dist'
dist_dir.mkdir(parents=True, exist_ok=True)
try:
# Load the config file to make sure it gets validated
read_flit_config(ini_file)
if 'sdist' in formats:
sb = SdistBuilder.from_ini_path(ini_file)
sdist_file = sb.build(dist_dir, gen_setup_py=gen_setup_py)
sdist_info = SimpleNamespace(builder=sb, file=sdist_file)
# When we're building both, build the wheel from the unpacked sdist.
# This helps ensure that the sdist contains all the necessary files.
if 'wheel' in formats:
with unpacked_tarball(sdist_file) as tmpdir:
log.debug('Building wheel from unpacked sdist %s', tmpdir)
tmp_ini_file = Path(tmpdir, ini_file.name)
wheel_info = make_wheel_in(tmp_ini_file, dist_dir)
elif 'wheel' in formats:
wheel_info = make_wheel_in(ini_file, dist_dir)
except ConfigError as e:
sys.exit('Config error: {}'.format(e))
return SimpleNamespace(wheel=wheel_info, sdist=sdist_info)

1
flit/buildapi.py Normal file
View File

@ -0,0 +1 @@
from flit_core.buildapi import *

18
flit/config.py Normal file
View File

@ -0,0 +1,18 @@
import os
from flit_core.config import *
from flit_core.config import read_flit_config as _read_flit_config_core
from .validate import validate_config
def read_flit_config(path):
"""Read and check the `pyproject.toml` or `flit.ini` file with data about the package.
"""
res = _read_flit_config_core(path)
if validate_config(res):
if os.environ.get('FLIT_ALLOW_INVALID'):
log.warning("Allowing invalid data (FLIT_ALLOW_INVALID set). Uploads may still fail.")
else:
raise ConfigError("Invalid config values (see log)")
return res

251
flit/init.py Normal file
View File

@ -0,0 +1,251 @@
from datetime import date
import json
import os
from pathlib import Path
import re
import sys
import tomli_w
def get_data_dir():
"""Get the directory path for flit user data files.
"""
home = os.path.realpath(os.path.expanduser('~'))
if sys.platform == 'darwin':
d = Path(home, 'Library')
elif os.name == 'nt':
appdata = os.environ.get('APPDATA', None)
if appdata:
d = Path(appdata)
else:
d = Path(home, 'AppData', 'Roaming')
else:
# Linux, non-OS X Unix, AIX, etc.
xdg = os.environ.get("XDG_DATA_HOME", None)
d = Path(xdg) if xdg else Path(home, '.local/share')
return d / 'flit'
def get_defaults():
try:
with (get_data_dir() / 'init_defaults.json').open(encoding='utf-8') as f:
return json.load(f)
except FileNotFoundError:
return {}
def store_defaults(d):
data_dir = get_data_dir()
try:
data_dir.mkdir(parents=True)
except FileExistsError:
pass
with (data_dir / 'init_defaults.json').open('w', encoding='utf-8') as f:
json.dump(d, f, indent=2)
license_choices = [
('mit', "MIT - simple and permissive"),
('apache', "Apache - explicitly grants patent rights"),
('gpl3', "GPL - ensures that code based on this is shared with the same terms"),
('skip', "Skip - choose a license later"),
]
license_names_to_classifiers = {
'mit': 'License :: OSI Approved :: MIT License',
'gpl3': 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'apache': 'License :: OSI Approved :: Apache Software License'
}
license_templates_dir = Path(__file__).parent / 'license_templates'
class IniterBase:
def __init__(self, directory='.'):
self.directory = Path(directory)
self.defaults = get_defaults()
def validate_email(self, s):
# Properly validating an email address is much more complex
return bool(re.match(r'.+@.+', s)) or s == ""
def validate_homepage(self, s):
return not s or s.startswith(('http://', 'https://'))
def guess_module_name(self):
packages, modules = [], []
for p in self.directory.iterdir():
if not p.stem.isidentifier():
continue
if p.is_dir() and (p / '__init__.py').is_file():
if p.name not in {'test', 'tests'}:
packages.append(p.name)
elif p.is_file() and p.suffix == '.py':
if p.stem not in {'setup'} and not p.name.startswith('test_'):
modules.append(p.stem)
src_dir = self.directory / 'src'
if src_dir.is_dir():
for p in src_dir.iterdir():
if not p.stem.isidentifier():
continue
if p.is_dir() and (p / '__init__.py').is_file():
if p.name not in {'test', 'tests'}:
packages.append(p.name)
elif p.is_file() and p.suffix == '.py':
if p.stem not in {'setup'} and not p.name.startswith('test_'):
modules.append(p.stem)
if len(packages) == 1:
return packages[0]
elif len(packages) == 0 and len(modules) == 1:
return modules[0]
else:
return None
def update_defaults(self, author, author_email, module, home_page, license):
new_defaults = {'author': author, 'author_email': author_email,
'license': license}
name_chunk_pat = r'\b{}\b'.format(re.escape(module))
if re.search(name_chunk_pat, home_page):
new_defaults['home_page_template'] = \
re.sub(name_chunk_pat, '{modulename}', home_page, flags=re.I)
if any(new_defaults[k] != self.defaults.get(k) for k in new_defaults):
self.defaults.update(new_defaults)
store_defaults(self.defaults)
def write_license(self, name, author):
if (self.directory / 'LICENSE').exists():
return
year = date.today().year
with (license_templates_dir / name).open(encoding='utf-8') as f:
license_text = f.read()
with (self.directory / 'LICENSE').open('w', encoding='utf-8') as f:
f.write(license_text.format(year=year, author=author))
def find_readme(self):
allowed = ("readme.md","readme.rst","readme.txt")
for fl in self.directory.glob("*.*"):
if fl.name.lower() in allowed:
return fl.name
return None
class TerminalIniter(IniterBase):
def prompt_text(self, prompt, default, validator, retry_msg="Try again."):
if default is not None:
p = "{} [{}]: ".format(prompt, default)
else:
p = prompt + ': '
while True:
response = input(p)
if response == '' and default is not None:
response = default
if validator(response):
return response
print(retry_msg)
def prompt_options(self, prompt, options, default=None):
default_ix = None
print(prompt)
for i, (key, text) in enumerate(options, start=1):
print("{}. {}".format(i, text))
if key == default:
default_ix = i
while True:
p = "Enter 1-" + str(len(options))
if default_ix is not None:
p += ' [{}]'.format(default_ix)
response = input(p+': ')
if (default_ix is not None) and response == '':
return default
if response.isnumeric():
ir = int(response)
if 1 <= ir <= len(options):
return options[ir-1][0]
print("Try again.")
def initialise(self):
if (self.directory / 'pyproject.toml').exists():
resp = input("pyproject.toml exists - overwrite it? [y/N]: ")
if (not resp) or resp[0].lower() != 'y':
return
module = self.prompt_text('Module name', self.guess_module_name(),
str.isidentifier)
author = self.prompt_text('Author', self.defaults.get('author'),
lambda s: True)
author_email = self.prompt_text('Author email',
self.defaults.get('author_email'), self.validate_email)
if 'home_page_template' in self.defaults:
home_page_default = self.defaults['home_page_template'].replace(
'{modulename}', module)
else:
home_page_default = None
home_page = self.prompt_text('Home page', home_page_default, self.validate_homepage,
retry_msg="Should start with http:// or https:// - try again.")
license = self.prompt_options('Choose a license (see http://choosealicense.com/ for more info)',
license_choices, self.defaults.get('license'))
readme = self.find_readme()
self.update_defaults(author=author, author_email=author_email,
home_page=home_page, module=module, license=license)
# Format information as TOML
# This is ugly code, but I want the generated pyproject.toml, which
# will mostly be edited by hand, to look a particular way - e.g. authors
# in inline tables. It's easier to 'cheat' with some string formatting
# than to do this through a TOML library.
author_info = []
if author:
author_info.append(f'name = {json.dumps(author, ensure_ascii=False)}')
if author_email:
author_info.append(f'email = {json.dumps(author_email)}')
if author_info:
authors_list = "[{%s}]" % ", ".join(author_info)
else:
authors_list = "[]"
classifiers = []
if license != 'skip':
classifiers = [license_names_to_classifiers[license]]
self.write_license(license, author)
with (self.directory / 'pyproject.toml').open('w', encoding='utf-8') as f:
f.write(TEMPLATE.format(
name=json.dumps(module), authors=authors_list
))
if readme:
f.write(tomli_w.dumps({'readme': readme}))
if license != 'skip':
f.write('license = {file = "LICENSE"}\n')
if classifiers:
f.write(f"classifiers = {json.dumps(classifiers)}\n")
f.write('dynamic = ["version", "description"]\n')
if home_page:
f.write("\n" + tomli_w.dumps({
'project': {'urls': {'Home': home_page}}
}))
print()
print("Written pyproject.toml; edit that file to add optional extra info.")
TEMPLATE = """\
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[project]
name = {name}
authors = {authors}
"""
if __name__ == '__main__':
TerminalIniter().initialise()

432
flit/install.py Normal file
View File

@ -0,0 +1,432 @@
"""Install packages locally for development
"""
import logging
import os
import os.path as osp
import csv
import json
import pathlib
import random
import shutil
import site
import sys
import tempfile
from subprocess import check_call, check_output
import sysconfig
from flit_core import common
from .config import read_flit_config
from .wheel import WheelBuilder
from ._get_dirs import get_dirs
log = logging.getLogger(__name__)
def _requires_dist_to_pip_requirement(requires_dist):
"""Parse "Foo (v); python_version == '2.x'" from Requires-Dist
Returns pip-style appropriate for requirements.txt.
"""
env_mark = ''
if ';' in requires_dist:
name_version, env_mark = requires_dist.split(';', 1)
else:
name_version = requires_dist
if '(' in name_version:
# turn 'name (X)' and 'name (<X.Y)'
# into 'name == X' and 'name < X.Y'
name, version = name_version.split('(', 1)
name = name.strip()
version = version.replace(')', '').strip()
if not any(c in version for c in '=<>'):
version = '==' + version
name_version = name + version
# re-add environment marker
return ' ;'.join([name_version, env_mark])
def test_writable_dir(path):
"""Check if a directory is writable.
Uses os.access() on POSIX, tries creating files on Windows.
"""
if os.name == 'posix':
return os.access(path, os.W_OK)
return _test_writable_dir_win(path)
def _test_writable_dir_win(path):
# os.access doesn't work on Windows: http://bugs.python.org/issue2528
# and we can't use tempfile: http://bugs.python.org/issue22107
basename = 'accesstest_deleteme_fishfingers_custard_'
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
for i in range(10):
name = basename + ''.join(random.choice(alphabet) for _ in range(6))
file = osp.join(path, name)
try:
with open(file, mode='xb'):
pass
except FileExistsError:
continue
except PermissionError:
# This could be because there's a directory with the same name.
# But it's highly unlikely there's a directory called that,
# so we'll assume it's because the parent directory is not writable.
return False
else:
os.unlink(file)
return True
# This should never be reached
msg = ('Unexpected condition testing for writable directory {!r}. '
'Please open an issue on flit to debug why this occurred.') # pragma: no cover
raise EnvironmentError(msg.format(path)) # pragma: no cover
class RootInstallError(Exception):
def __str__(self):
return ("Installing packages as root is not recommended. "
"To allow this, set FLIT_ROOT_INSTALL=1 and try again.")
class DependencyError(Exception):
def __str__(self):
return 'To install dependencies for extras, you cannot set deps=none.'
class Installer(object):
def __init__(self, directory, ini_info, user=None, python=sys.executable,
symlink=False, deps='all', extras=(), pth=False):
self.directory = directory
self.ini_info = ini_info
self.python = python
self.symlink = symlink
self.pth = pth
self.deps = deps
self.extras = extras
if deps != 'none' and os.environ.get('FLIT_NO_NETWORK', ''):
self.deps = 'none'
log.warning('Not installing dependencies, because FLIT_NO_NETWORK is set')
if deps == 'none' and extras:
raise DependencyError()
self.module = common.Module(self.ini_info.module, directory)
if (hasattr(os, 'getuid') and (os.getuid() == 0) and
(not os.environ.get('FLIT_ROOT_INSTALL'))):
raise RootInstallError
if user is None:
self.user = self._auto_user(python)
else:
self.user = user
log.debug('User install? %s', self.user)
self.installed_files = []
@classmethod
def from_ini_path(cls, ini_path, user=None, python=sys.executable,
symlink=False, deps='all', extras=(), pth=False):
ini_info = read_flit_config(ini_path)
return cls(ini_path.parent, ini_info, user=user, python=python,
symlink=symlink, deps=deps, extras=extras, pth=pth)
def _run_python(self, code=None, file=None, extra_args=()):
if code and file:
raise ValueError('Specify code or file, not both')
if not (code or file):
raise ValueError('Specify code or file')
if code:
args = [self.python, '-c', code]
else:
args = [self.python, file]
args.extend(extra_args)
env = os.environ.copy()
env['PYTHONIOENCODING'] = 'utf-8'
# On Windows, shell needs to be True to pick up our local PATH
# when finding the Python command.
shell = (os.name == 'nt')
return check_output(args, shell=shell, env=env).decode('utf-8')
def _auto_user(self, python):
"""Default guess for whether to do user-level install.
This should be True for system Python, and False in an env.
"""
if python == sys.executable:
user_site = site.ENABLE_USER_SITE
lib_dir = sysconfig.get_path('purelib')
else:
out = self._run_python(code=
("import sysconfig, site; "
"print(site.ENABLE_USER_SITE); "
"print(sysconfig.get_path('purelib'))"))
user_site, lib_dir = out.split('\n', 1)
user_site = (user_site.strip() == 'True')
lib_dir = lib_dir.strip()
if not user_site:
# No user site packages - probably a virtualenv
log.debug('User site packages not available - env install')
return False
log.debug('Checking access to %s', lib_dir)
return not test_writable_dir(lib_dir)
def install_scripts(self, script_defs, scripts_dir):
for name, ep in script_defs.items():
module, func = common.parse_entry_point(ep)
import_name = func.split('.')[0]
script_file = pathlib.Path(scripts_dir) / name
log.info('Writing script to %s', script_file)
with script_file.open('w', encoding='utf-8') as f:
f.write(common.script_template.format(
interpreter=self.python,
module=module,
import_name=import_name,
func=func
))
script_file.chmod(0o755)
self.installed_files.append(script_file)
if sys.platform == 'win32':
cmd_file = script_file.with_suffix('.cmd')
cmd = '@echo off\r\n"{python}" "%~dp0\\{script}" %*\r\n'.format(
python=self.python, script=name)
log.debug("Writing script wrapper to %s", cmd_file)
with cmd_file.open('w') as f:
f.write(cmd)
self.installed_files.append(cmd_file)
def install_data_dir(self, target_data_dir):
for src_path in common.walk_data_dir(self.ini_info.data_directory):
rel_path = os.path.relpath(src_path, self.ini_info.data_directory)
dst_path = os.path.join(target_data_dir, rel_path)
os.makedirs(os.path.dirname(dst_path), exist_ok=True)
if self.symlink:
os.symlink(os.path.realpath(src_path), dst_path)
else:
shutil.copy2(src_path, dst_path)
self.installed_files.append(dst_path)
def _record_installed_directory(self, path):
for dirpath, dirnames, files in os.walk(path):
for f in files:
self.installed_files.append(osp.join(dirpath, f))
def _extras_to_install(self):
extras_to_install = set(self.extras)
if self.deps == 'all' or 'all' in extras_to_install:
extras_to_install |= set(self.ini_info.reqs_by_extra.keys())
# We dont remove 'all' from the set because there might be an extra called “all”.
elif self.deps == 'develop':
extras_to_install |= {'dev', 'doc', 'test'}
if self.deps != 'none':
# '.none' is an internal token for normal requirements
extras_to_install.add('.none')
log.info("Extras to install for deps %r: %s", self.deps, extras_to_install)
return extras_to_install
def install_requirements(self):
"""Install requirements of a package with pip.
Creates a temporary requirements.txt from requires_dist metadata.
"""
# construct the full list of requirements, including dev requirements
requirements = []
if self.deps == 'none':
return
for extra in self._extras_to_install():
requirements.extend(self.ini_info.reqs_by_extra.get(extra, []))
# there aren't any requirements, so return
if len(requirements) == 0:
return
requirements = [
_requires_dist_to_pip_requirement(req_d)
for req_d in requirements
]
# install the requirements with pip
cmd = [self.python, '-m', 'pip', 'install']
if self.user:
cmd.append('--user')
with tempfile.NamedTemporaryFile(mode='w',
suffix='requirements.txt',
delete=False) as tf:
tf.file.write('\n'.join(requirements))
cmd.extend(['-r', tf.name])
log.info("Installing requirements")
try:
check_call(cmd)
finally:
os.remove(tf.name)
def install_reqs_my_python_if_needed(self):
"""Install requirements to this environment if needed.
We can normally get the summary and version number without import the
module, but if we do need to import it, we may need to install
its requirements for the Python where flit is running.
"""
try:
common.get_info_from_module(self.module, self.ini_info.dynamic_metadata)
except ImportError:
if self.deps == 'none':
raise # We were asked not to install deps, so bail out.
log.warning("Installing requirements to Flit's env to import module.")
user = self.user if (self.python == sys.executable) else None
i2 = Installer(self.directory, self.ini_info, user=user, deps='production')
i2.install_requirements()
def _get_dirs(self, user):
if self.python == sys.executable:
return get_dirs(user=user)
else:
import json
path = osp.join(osp.dirname(__file__), '_get_dirs.py')
args = ['--user'] if user else []
return json.loads(self._run_python(file=path, extra_args=args))
def install_directly(self):
"""Install a module/package into site-packages, and create its scripts.
"""
dirs = self._get_dirs(user=self.user)
os.makedirs(dirs['purelib'], exist_ok=True)
os.makedirs(dirs['scripts'], exist_ok=True)
module_rel_path = self.module.path.relative_to(self.module.source_dir)
dst = osp.join(dirs['purelib'], module_rel_path)
if osp.lexists(dst):
if osp.isdir(dst) and not osp.islink(dst):
shutil.rmtree(dst)
else:
os.unlink(dst)
# Install requirements to target environment
self.install_requirements()
# Install requirements to this environment if we need them to
# get docstring & version number.
if self.python != sys.executable:
self.install_reqs_my_python_if_needed()
src = self.module.path
if self.symlink:
if self.module.in_namespace_package:
ns_dir = os.path.dirname(dst)
os.makedirs(ns_dir, exist_ok=True)
log.info("Symlinking %s -> %s", src, dst)
os.symlink(src.resolve(), dst)
self.installed_files.append(dst)
elif self.pth:
# .pth points to the the folder containing the module (which is
# added to sys.path)
pth_file = pathlib.Path(dirs['purelib'], self.module.name + '.pth')
log.info("Adding .pth file %s for %s", pth_file, self.module.source_dir)
pth_file.write_text(str(self.module.source_dir.resolve()), 'utf-8')
self.installed_files.append(pth_file)
elif self.module.is_package:
log.info("Copying directory %s -> %s", src, dst)
shutil.copytree(src, dst)
self._record_installed_directory(dst)
else:
log.info("Copying file %s -> %s", src, dst)
os.makedirs(osp.dirname(dst), exist_ok=True)
shutil.copy2(src, dst)
self.installed_files.append(dst)
scripts = self.ini_info.entrypoints.get('console_scripts', {})
self.install_scripts(scripts, dirs['scripts'])
self.install_data_dir(dirs['data'])
self.write_dist_info(dirs['purelib'])
def install_with_pip(self):
"""Let pip install the project directory
pip will create an isolated build environment and install build
dependencies, which means downloading flit_core from PyPI. We ask pip
to install the project directory (instead of building a temporary wheel
and asking pip to install it), so pip will record the project directory
in direct_url.json.
"""
self.install_reqs_my_python_if_needed()
extras = self._extras_to_install()
extras.discard('.none')
req_with_extras = '{}[{}]'.format(self.directory, ','.join(extras)) \
if extras else str(self.directory)
cmd = [self.python, '-m', 'pip', 'install', req_with_extras]
if self.user:
cmd.append('--user')
if self.deps == 'none':
cmd.append('--no-deps')
shell = (os.name == 'nt')
check_call(cmd, shell=shell)
def write_dist_info(self, site_pkgs):
"""Write dist-info folder, according to PEP 376"""
metadata = common.make_metadata(self.module, self.ini_info)
dist_info = pathlib.Path(site_pkgs) / common.dist_info_name(
metadata.name, metadata.version)
try:
dist_info.mkdir()
except FileExistsError:
shutil.rmtree(str(dist_info))
dist_info.mkdir()
with (dist_info / 'METADATA').open('w', encoding='utf-8') as f:
metadata.write_metadata_file(f)
self.installed_files.append(dist_info / 'METADATA')
with (dist_info / 'INSTALLER').open('w', encoding='utf-8') as f:
f.write('flit')
self.installed_files.append(dist_info / 'INSTALLER')
# We only handle explicitly requested installations
with (dist_info / 'REQUESTED').open('wb'): pass
self.installed_files.append(dist_info / 'REQUESTED')
if self.ini_info.entrypoints:
with (dist_info / 'entry_points.txt').open('w') as f:
common.write_entry_points(self.ini_info.entrypoints, f)
self.installed_files.append(dist_info / 'entry_points.txt')
with (dist_info / 'direct_url.json').open('w', encoding='utf-8') as f:
json.dump(
{
"url": self.directory.resolve().as_uri(),
"dir_info": {"editable": bool(self.symlink or self.pth)}
},
f
)
self.installed_files.append(dist_info / 'direct_url.json')
# newline='' because the csv module does its own newline translation
with (dist_info / 'RECORD').open('w', encoding='utf-8', newline='') as f:
cf = csv.writer(f)
for path in sorted(self.installed_files, key=str):
path = pathlib.Path(path)
if path.is_symlink() or path.suffix in {'.pyc', '.pyo'}:
hash, size = '', ''
else:
hash = 'sha256=' + common.hash_file(str(path))
size = path.stat().st_size
try:
path = path.relative_to(site_pkgs)
except ValueError:
pass
cf.writerow((str(path), hash, size))
cf.writerow(((dist_info / 'RECORD').relative_to(site_pkgs), '', ''))
def install(self):
if self.symlink or self.pth:
self.install_directly()
else:
self.install_with_pip()

View File

@ -0,0 +1,68 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
2. Grant of Copyright License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
3. Grant of Patent License.
Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
4. Redistribution.
You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
You must give any other recipients of the Work or Derivative Works a copy of this License; and
You must cause any modified files to carry prominent notices stating that You changed the files; and
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
5. Submission of Contributions.
Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
6. Trademarks.
This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty.
Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
8. Limitation of Liability.
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability.
While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS

619
flit/license_templates/gpl3 Normal file
View File

@ -0,0 +1,619 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.

View File

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) {year} {author}
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.

110
flit/log.py Normal file
View File

@ -0,0 +1,110 @@
"""Nicer log formatting with colours.
Code copied from Tornado, Apache licensed.
"""
# Copyright 2012 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
import sys
try:
import curses
except ImportError:
curses = None
def _stderr_supports_color():
color = False
if curses and hasattr(sys.stderr, 'isatty') and sys.stderr.isatty():
try:
curses.setupterm()
if curses.tigetnum("colors") > 0:
color = True
except Exception:
pass
return color
class LogFormatter(logging.Formatter):
"""Log formatter with colour support
"""
DEFAULT_COLORS = {
logging.INFO: 2, # Green
logging.WARNING: 3, # Yellow
logging.ERROR: 1, # Red
logging.CRITICAL: 1,
}
def __init__(self, color=True, datefmt=None):
r"""
:arg bool color: Enables color support.
:arg string fmt: Log message format.
It will be applied to the attributes dict of log records. The
text between ``%(color)s`` and ``%(end_color)s`` will be colored
depending on the level if color support is on.
:arg dict colors: color mappings from logging level to terminal color
code
:arg string datefmt: Datetime format.
Used for formatting ``(asctime)`` placeholder in ``prefix_fmt``.
.. versionchanged:: 3.2
Added ``fmt`` and ``datefmt`` arguments.
"""
logging.Formatter.__init__(self, datefmt=datefmt)
self._colors = {}
if color and _stderr_supports_color():
# The curses module has some str/bytes confusion in
# python3. Until version 3.2.3, most methods return
# bytes, but only accept strings. In addition, we want to
# output these strings with the logging module, which
# works with unicode strings. The explicit calls to
# unicode() below are harmless in python2 but will do the
# right conversion in python 3.
fg_color = (curses.tigetstr("setaf") or
curses.tigetstr("setf") or "")
if (3, 0) < sys.version_info < (3, 2, 3):
fg_color = str(fg_color, "ascii")
for levelno, code in self.DEFAULT_COLORS.items():
self._colors[levelno] = str(curses.tparm(fg_color, code), "ascii")
self._normal = str(curses.tigetstr("sgr0"), "ascii")
scr = curses.initscr()
self.termwidth = scr.getmaxyx()[1]
curses.endwin()
else:
self._normal = ''
# Default width is usually 80, but too wide is worse than too narrow
self.termwidth = 70
def formatMessage(self, record):
l = len(record.message)
right_text = '{initial}-{name}'.format(initial=record.levelname[0],
name=record.name)
if l + len(right_text) < self.termwidth:
space = ' ' * (self.termwidth - (l + len(right_text)))
else:
space = ' '
if record.levelno in self._colors:
start_color = self._colors[record.levelno]
end_color = self._normal
else:
start_color = end_color = ''
return record.message + space + start_color + right_text + end_color
def enable_colourful_output(level=logging.INFO):
handler = logging.StreamHandler()
handler.setFormatter(LogFormatter())
logging.root.addHandler(handler)
logging.root.setLevel(level)

20
flit/logo.py Normal file
View File

@ -0,0 +1,20 @@
"""White and colored version for flit"""
logo = """
._ ._
```. ```. .--.______
`. `-. `. / °,-´
`. `~-.>.' /
`. .` |
-..;. /
/ /___ _____
/r_,.´| | | |
,' `/ |—— | | |
.´ ,'/ | |__ | |
.´ / . /
'__/|/ V {version}
"""
clogo = '\x1b[36m'+logo+'\x1b[39m'

236
flit/sdist.py Normal file
View File

@ -0,0 +1,236 @@
from collections import defaultdict
import io
import logging
import os
from pathlib import Path
from posixpath import join as pjoin
from pprint import pformat
import tarfile
from flit_core.sdist import SdistBuilder as SdistBuilderCore
from flit_core.common import Module, VCSError
from flit.vcs import identify_vcs
log = logging.getLogger(__name__)
# Our generated setup.py deliberately loads distutils, not setuptools, to
# discourage running it directly and getting a setuptools mess. Tools like pip
# handle this correctly - loading setuptools anyway but avoiding its issues.
SETUP = """\
#!/usr/bin/env python
# setup.py generated by flit for tools that don't yet use PEP 517
from distutils.core import setup
{before}
setup(name={name!r},
version={version!r},
description={description!r},
author={author!r},
author_email={author_email!r},
url={url!r},
{extra}
)
"""
def namespace_packages(module: Module):
"""Get parent package names"""
name_parts = []
for part in module.namespace_package_name.split('.'):
name_parts.append(part)
yield '.'.join(name_parts)
def auto_packages(module: Module):
"""Discover subpackages and package_data"""
pkgdir = os.path.normpath(str(module.path))
pkg_name = module.name
packages = []
if module.in_namespace_package:
packages.extend(namespace_packages(module))
packages.append(pkg_name)
pkg_data = defaultdict(list)
# Undocumented distutils feature: the empty string matches all package names
pkg_data[''].append('*')
subpkg_paths = set()
def find_nearest_pkg(rel_path):
parts = rel_path.split(os.sep)
for i in reversed(range(1, len(parts))):
ancestor = '/'.join(parts[:i])
if ancestor in subpkg_paths:
pkg = '.'.join([pkg_name] + parts[:i])
return pkg, '/'.join(parts[i:])
# Relative to the top-level package
return pkg_name, rel_path
for path, dirnames, filenames in os.walk(pkgdir, topdown=True):
if os.path.basename(path) == '__pycache__':
continue
from_top_level = os.path.relpath(path, pkgdir)
if from_top_level == '.':
continue
is_subpkg = '__init__.py' in filenames
if is_subpkg:
subpkg_paths.add(from_top_level)
parts = from_top_level.split(os.sep)
packages.append('.'.join([pkg_name] + parts))
else:
pkg, from_nearest_pkg = find_nearest_pkg(from_top_level)
pkg_data[pkg].append(pjoin(from_nearest_pkg, '*'))
# Sort values in pkg_data
pkg_data = {k: sorted(v) for (k, v) in pkg_data.items()}
return sorted(packages), pkg_data
def include_path(p):
return not (p.startswith('dist' + os.sep)
or (os.sep+'__pycache__' in p)
or p.endswith('.pyc'))
def _parse_req(requires_dist):
"""Parse "Foo (v); python_version == '2.x'" from Requires-Dist
Returns pip-style appropriate for requirements.txt.
"""
if ';' in requires_dist:
name_version, env_mark = requires_dist.split(';', 1)
env_mark = env_mark.strip()
else:
name_version, env_mark = requires_dist, None
if '(' in name_version:
# turn 'name (X)' and 'name (<X.Y)'
# into 'name == X' and 'name < X.Y'
name, version = name_version.split('(', 1)
name = name.strip()
version = version.replace(')', '').strip()
if not any(c in version for c in '=<>'):
version = '==' + version
name_version = name + version
return name_version, env_mark
def convert_requires(reqs_by_extra):
"""Regroup requirements by (extra, env_mark)"""
grouping = defaultdict(list)
for extra, reqs in reqs_by_extra.items():
for req in reqs:
name_version, env_mark = _parse_req(req)
grouping[(extra, env_mark)].append(name_version)
install_reqs = grouping.pop(('.none', None), [])
extra_reqs = {}
for (extra, env_mark), reqs in grouping.items():
if extra == '.none':
extra = ''
if env_mark is None:
extra_reqs[extra] = reqs
else:
extra_reqs[extra + ':' + env_mark] = reqs
return install_reqs, extra_reqs
class SdistBuilder(SdistBuilderCore):
"""Build a complete sdist
This extends the minimal sdist-building in flit_core:
- Include any files tracked in version control, such as docs sources and
tests.
- Add a generated setup.py for compatibility with tools which don't yet know
about PEP 517.
"""
def select_files(self):
vcs_mod = identify_vcs(self.cfgdir)
if vcs_mod is not None:
untracked_deleted = vcs_mod.list_untracked_deleted_files(self.cfgdir)
if any(include_path(p) and not self.excludes.match_file(p)
for p in untracked_deleted):
raise VCSError(
"Untracked or deleted files in the source directory. "
"Commit, undo or ignore these files in your VCS.",
self.cfgdir)
files = [os.path.normpath(p)
for p in vcs_mod.list_tracked_files(self.cfgdir)]
files = sorted(filter(include_path, files))
log.info("Found %d files tracked in %s", len(files), vcs_mod.name)
else:
files = super().select_files()
return files
def add_setup_py(self, files_to_add, target_tarfile):
if 'setup.py' in files_to_add:
log.warning(
"Using setup.py from repository, not generating setup.py")
else:
setup_py = self.make_setup_py()
log.info("Writing generated setup.py")
ti = tarfile.TarInfo(pjoin(self.dir_name, 'setup.py'))
ti.size = len(setup_py)
target_tarfile.addfile(ti, io.BytesIO(setup_py))
def make_setup_py(self):
before, extra = [], []
if self.module.is_package:
packages, package_data = auto_packages(self.module)
before.append("packages = \\\n%s\n" % pformat(sorted(packages)))
before.append("package_data = \\\n%s\n" % pformat(package_data))
extra.append("packages=packages,")
extra.append("package_data=package_data,")
else:
extra.append("py_modules={!r},".format([self.module.name]))
if self.module.in_namespace_package:
packages = list(namespace_packages(self.module))
before.append("packages = \\\n%s\n" % pformat(packages))
extra.append("packages=packages,")
if self.module.prefix:
package_dir = pformat({'': self.module.prefix})
before.append("package_dir = \\\n%s\n" % package_dir)
extra.append("package_dir=package_dir,")
install_reqs, extra_reqs = convert_requires(self.reqs_by_extra)
if install_reqs:
before.append("install_requires = \\\n%s\n" % pformat(install_reqs))
extra.append("install_requires=install_requires,")
if extra_reqs:
before.append("extras_require = \\\n%s\n" % pformat(extra_reqs))
extra.append("extras_require=extras_require,")
entrypoints = self.prep_entry_points()
if entrypoints:
before.append("entry_points = \\\n%s\n" % pformat(entrypoints))
extra.append("entry_points=entry_points,")
if self.metadata.requires_python:
extra.append('python_requires=%r,' % self.metadata.requires_python)
return SETUP.format(
before='\n'.join(before),
name=self.metadata.name,
version=self.metadata.version,
description=self.metadata.summary,
author=self.metadata.author,
author_email=self.metadata.author_email,
url=self.metadata.home_page,
extra='\n '.join(extra),
).encode('utf-8')

83
flit/tomlify.py Normal file
View File

@ -0,0 +1,83 @@
"""Convert a flit.ini file to pyproject.toml
"""
import argparse
from collections import OrderedDict
import configparser
import os
from pathlib import Path
import tomli_w
from .config import metadata_list_fields
TEMPLATE = """\
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
{metadata}
"""
class CaseSensitiveConfigParser(configparser.ConfigParser):
optionxform = staticmethod(str)
def convert(path):
cp = configparser.ConfigParser()
with path.open(encoding='utf-8') as f:
cp.read_file(f)
ep_file = Path('entry_points.txt')
metadata = OrderedDict()
for name, value in cp['metadata'].items():
if name in metadata_list_fields:
metadata[name] = [l for l in value.splitlines() if l.strip()]
elif name == 'entry-points-file':
ep_file = Path(value)
else:
metadata[name] = value
if 'scripts' in cp:
scripts = OrderedDict(cp['scripts'])
else:
scripts = {}
entrypoints = CaseSensitiveConfigParser()
if ep_file.is_file():
with ep_file.open(encoding='utf-8') as f:
entrypoints.read_file(f)
written_entrypoints = False
with Path('pyproject.toml').open('w', encoding='utf-8') as f:
f.write(TEMPLATE.format(metadata=tomli_w.dumps(metadata)))
if scripts:
f.write('\n[tool.flit.scripts]\n')
f.write(tomli_w.dumps(scripts))
for groupname, group in entrypoints.items():
if not dict(group):
continue
if '.' in groupname:
groupname = '"{}"'.format(groupname)
f.write('\n[tool.flit.entrypoints.{}]\n'.format(groupname))
f.write(tomli_w.dumps(OrderedDict(group)))
written_entrypoints = True
print("Written 'pyproject.toml'")
files = str(path)
if written_entrypoints:
files += ' and ' + str(ep_file)
print("Please check the new file, then remove", files)
def main(argv=None):
ap = argparse.ArgumentParser()
ap.add_argument('-f', '--ini-file', type=Path, default='flit.ini')
args = ap.parse_args(argv)
os.chdir(str(args.ini_file.parent))
convert(Path(args.ini_file.name))
if __name__ == '__main__':
main()

270
flit/upload.py Normal file
View File

@ -0,0 +1,270 @@
"""Code to communicate with PyPI to register distributions and upload files.
This is cribbed heavily from distutils.command.(upgrade|register), which as part
of Python is under the PSF license.
"""
import configparser
import getpass
import hashlib
import logging
import os
from pathlib import Path
import requests
import sys
from urllib.parse import urlparse
from flit_core.common import Metadata
log = logging.getLogger(__name__)
PYPI = "https://upload.pypi.org/legacy/"
PYPIRC_DEFAULT = "~/.pypirc"
SWITCH_TO_HTTPS = (
"http://pypi.python.org/",
"http://testpypi.python.org/",
"http://upload.pypi.org/",
"http://upload.pypi.io/",
)
def get_repositories(file="~/.pypirc"):
"""Get the known repositories from a pypirc file.
This returns a dict keyed by name, of dicts with keys 'url', 'username',
'password'. Username and password may be None.
"""
cp = configparser.ConfigParser()
if isinstance(file, str):
file = os.path.expanduser(file)
if not os.path.isfile(file):
return {'pypi': {
'url': PYPI, 'username': None, 'password': None,
}}
cp.read(file)
else:
cp.read_file(file)
names = cp.get('distutils', 'index-servers', fallback='pypi').split()
repos = {}
for name in names:
repos[name] = {
'url': cp.get(name, 'repository', fallback=PYPI),
'username': cp.get(name, 'username', fallback=None),
'password': cp.get(name, 'password', fallback=None),
}
return repos
def get_repository(pypirc_path="~/.pypirc", name=None):
"""Get the url, username and password for one repository.
Returns a dict with keys 'url', 'username', 'password'.
There is a hierarchy of possible sources of information:
Index URL:
1. Command line arg --repository (looked up in .pypirc)
2. $FLIT_INDEX_URL
3. Repository called 'pypi' from .pypirc
4. Default PyPI (hardcoded)
Username:
1. Command line arg --repository (looked up in .pypirc)
2. $FLIT_USERNAME
3. Repository called 'pypi' from .pypirc
4. Terminal prompt (write to .pypirc if it doesn't exist yet)
Password:
1. Command line arg --repository (looked up in .pypirc)
2. $FLIT_PASSWORD
3. Repository called 'pypi' from .pypirc
3. keyring
4. Terminal prompt (store to keyring if available)
"""
log.debug("Loading repositories config from %r", pypirc_path)
repos_cfg = get_repositories(pypirc_path)
if name is not None:
repo = repos_cfg[name]
elif 'FLIT_INDEX_URL' in os.environ:
repo = {'url': os.environ['FLIT_INDEX_URL'],
'username': None, 'password': None}
elif 'pypi' in repos_cfg:
repo = repos_cfg['pypi']
if 'FLIT_PASSWORD' in os.environ:
repo['password'] = os.environ['FLIT_PASSWORD']
else:
repo = {'url': PYPI, 'username': None, 'password': None}
if repo['url'].startswith(SWITCH_TO_HTTPS):
# Use https for PyPI, even if an http URL was given
repo['url'] = 'https' + repo['url'][4:]
elif repo['url'].startswith('http://'):
log.warning("Unencrypted connection - credentials may be visible on "
"the network.")
log.info("Using repository at %s", repo['url'])
if ('FLIT_USERNAME' in os.environ) and ((name is None) or (not repo['username'])):
repo['username'] = os.environ['FLIT_USERNAME']
if sys.stdin.isatty():
while not repo['username']:
repo['username'] = input("Username: ")
if repo['url'] == PYPI:
write_pypirc(repo, pypirc_path)
elif not repo['username']:
raise Exception("Could not find username for upload.")
repo['password'] = get_password(repo, prefer_env=(name is None))
repo['is_warehouse'] = repo['url'].rstrip('/').endswith('/legacy')
return repo
def write_pypirc(repo, file="~/.pypirc"):
"""Write .pypirc if it doesn't already exist
"""
file = os.path.expanduser(file)
if os.path.isfile(file):
return
with open(file, 'w', encoding='utf-8') as f:
f.write("[pypi]\n"
"username = %s\n" % repo['username'])
def get_password(repo, prefer_env):
if ('FLIT_PASSWORD' in os.environ) and (prefer_env or not repo['password']):
return os.environ['FLIT_PASSWORD']
if repo['password']:
return repo['password']
try:
import keyring
except ImportError: # pragma: no cover
log.warning("Install keyring to store passwords securely")
keyring = None
else:
stored_pw = keyring.get_password(repo['url'], repo['username'])
if stored_pw is not None:
return stored_pw
if sys.stdin.isatty():
pw = None
while not pw:
print('Server :', repo['url'])
print('Username:', repo['username'])
pw = getpass.getpass('Password: ')
else:
raise Exception("Could not find password for upload.")
if keyring is not None:
keyring.set_password(repo['url'], repo['username'], pw)
log.info("Stored password with keyring")
return pw
def build_post_data(action, metadata:Metadata):
"""Prepare the metadata needed for requests to PyPI.
"""
d = {
":action": action,
"name": metadata.name,
"version": metadata.version,
# additional meta-data
"metadata_version": '2.1',
"summary": metadata.summary,
"home_page": metadata.home_page,
"author": metadata.author,
"author_email": metadata.author_email,
"maintainer": metadata.maintainer,
"maintainer_email": metadata.maintainer_email,
"license": metadata.license,
"description": metadata.description,
"keywords": metadata.keywords,
"platform": metadata.platform,
"classifiers": metadata.classifiers,
"download_url": metadata.download_url,
"supported_platform": metadata.supported_platform,
# Metadata 1.1 (PEP 314)
"provides": metadata.provides,
"requires": metadata.requires,
"obsoletes": metadata.obsoletes,
# Metadata 1.2 (PEP 345)
"project_urls": metadata.project_urls,
"provides_dist": metadata.provides_dist,
"obsoletes_dist": metadata.obsoletes_dist,
"requires_dist": metadata.requires_dist,
"requires_external": metadata.requires_external,
"requires_python": metadata.requires_python,
# Metadata 2.1 (PEP 566)
"description_content_type": metadata.description_content_type,
"provides_extra": metadata.provides_extra,
}
return {k:v for k,v in d.items() if v}
def upload_file(file:Path, metadata:Metadata, repo):
"""Upload a file to an index server, given the index server details.
"""
data = build_post_data('file_upload', metadata)
data['protocol_version'] = '1'
if file.suffix == '.whl':
data['filetype'] = 'bdist_wheel'
py2_support = not (metadata.requires_python or '')\
.startswith(('3', '>3', '>=3'))
data['pyversion'] = ('py2.' if py2_support else '') + 'py3'
else:
data['filetype'] = 'sdist'
with file.open('rb') as f:
content = f.read()
files = {'content': (file.name, content)}
data['md5_digest'] = hashlib.md5(content).hexdigest()
data['sha256_digest'] = hashlib.sha256(content).hexdigest()
log.info('Uploading %s...', file)
resp = requests.post(repo['url'],
data=data,
files=files,
auth=(repo['username'], repo['password']),
)
resp.raise_for_status()
def do_upload(file:Path, metadata:Metadata, pypirc_path="~/.pypirc", repo_name=None):
"""Upload a file to an index server.
"""
repo = get_repository(pypirc_path, repo_name)
upload_file(file, metadata, repo)
if repo['is_warehouse']:
domain = urlparse(repo['url']).netloc
if domain.startswith('upload.'):
domain = domain[7:]
log.info("Package is at https://%s/project/%s/", domain, metadata.name)
else:
log.info("Package is at %s/%s", repo['url'], metadata.name)
def main(ini_path, repo_name, pypirc_path=None, formats=None, gen_setup_py=True):
"""Build and upload wheel and sdist."""
if pypirc_path is None:
pypirc_path = PYPIRC_DEFAULT
elif not os.path.isfile(pypirc_path):
raise FileNotFoundError("The specified pypirc config file does not exist.")
from . import build
built = build.main(ini_path, formats=formats, gen_setup_py=gen_setup_py)
if built.wheel is not None:
do_upload(built.wheel.file, built.wheel.builder.metadata, pypirc_path, repo_name)
if built.sdist is not None:
do_upload(built.sdist.file, built.sdist.builder.metadata, pypirc_path, repo_name)

301
flit/validate.py Normal file
View File

@ -0,0 +1,301 @@
"""Validate various pieces of packaging data"""
import errno
import io
import logging
import os
from pathlib import Path
import re
import requests
import sys
from .vendorized.readme.rst import render
log = logging.getLogger(__name__)
CUSTOM_CLASSIFIERS = frozenset({
# https://github.com/pypa/warehouse/pull/5440
'Private :: Do Not Upload',
})
def get_cache_dir() -> Path:
"""Locate a platform-appropriate cache directory for flit to use
Does not ensure that the cache directory exists.
"""
# Linux, Unix, AIX, etc.
if os.name == 'posix' and sys.platform != 'darwin':
# use ~/.cache if empty OR not set
xdg = os.environ.get("XDG_CACHE_HOME", None) \
or os.path.expanduser('~/.cache')
return Path(xdg, 'flit')
# Mac OS
elif sys.platform == 'darwin':
return Path(os.path.expanduser('~'), 'Library/Caches/flit')
# Windows (hopefully)
else:
local = os.environ.get('LOCALAPPDATA', None) \
or os.path.expanduser('~\\AppData\\Local')
return Path(local, 'flit')
def _read_classifiers_cached():
"""Reads classifiers from cached file"""
with (get_cache_dir() / 'classifiers.lst').open(encoding='utf-8') as f:
valid_classifiers = set(l.strip() for l in f)
return valid_classifiers
def _download_and_cache_classifiers():
"""Get the list of valid trove classifiers from PyPI"""
log.info('Fetching list of valid trove classifiers')
resp = requests.get(
'https://pypi.org/pypi?%3Aaction=list_classifiers')
resp.raise_for_status()
cache_dir = get_cache_dir()
try:
cache_dir.mkdir(parents=True)
except (FileExistsError, PermissionError):
pass
except OSError as e:
# readonly mounted file raises OSError, only these should be captured
if e.errno != errno.EROFS:
raise
try:
with (cache_dir / 'classifiers.lst').open('wb') as f:
f.write(resp.content)
except (PermissionError, FileNotFoundError):
# cache file could not be created
pass
except OSError as e:
# readonly mounted file raises OSError, only these should be captured
if e.errno != errno.EROFS:
raise
valid_classifiers = set(l.strip() for l in resp.text.splitlines())
return valid_classifiers
def _verify_classifiers(classifiers, valid_classifiers):
"""Check classifiers against a set of known classifiers"""
invalid = classifiers - valid_classifiers
return ["Unrecognised classifier: {!r}".format(c)
for c in sorted(invalid)]
def validate_classifiers(classifiers):
"""Verify trove classifiers from config file.
Fetches and caches a list of known classifiers from PyPI. Setting the
environment variable FLIT_NO_NETWORK=1 will skip this if the classifiers
are not already cached.
"""
if not classifiers:
return []
problems = []
classifiers = set(classifiers)
try:
valid_classifiers = _read_classifiers_cached()
valid_classifiers.update(CUSTOM_CLASSIFIERS)
problems = _verify_classifiers(classifiers, valid_classifiers)
except (FileNotFoundError, PermissionError) as e1:
# We haven't yet got the classifiers cached or couldn't read it
pass
else:
if not problems:
return []
# Either we don't have the list, or there were unexpected classifiers
# which might have been added since we last fetched it. Fetch and cache.
if os.environ.get('FLIT_NO_NETWORK', ''):
log.warning(
"Not checking classifiers, because FLIT_NO_NETWORK is set")
return []
# Try to download up-to-date list of classifiers
try:
valid_classifiers = _download_and_cache_classifiers()
except requests.ConnectionError:
# The error you get on a train, going through Oregon, without wifi
log.warning(
"Couldn't get list of valid classifiers to check against")
return problems
valid_classifiers.update(CUSTOM_CLASSIFIERS)
return _verify_classifiers(classifiers, valid_classifiers)
def validate_entrypoints(entrypoints):
"""Check that the loaded entrypoints are valid.
Expects a dict of dicts, e.g.::
{'console_scripts': {'flit': 'flit:main'}}
"""
def _is_identifier_attr(s):
return all(n.isidentifier() for n in s.split('.'))
problems = []
for groupname, group in entrypoints.items():
for k, v in group.items():
if ':' in v:
mod, obj = v.split(':', 1)
valid = _is_identifier_attr(mod) and _is_identifier_attr(obj)
else:
valid = _is_identifier_attr(v)
if not valid:
problems.append('Invalid entry point in group {}: '
'{} = {}'.format(groupname, k, v))
return problems
# Distribution name, not quite the same as a Python identifier
NAME = re.compile(r'^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$', re.IGNORECASE)
r''
VERSION_SPEC = re.compile(r'(~=|===?|!=|<=?|>=?)\s*[A-Z0-9\-_.*+!]+$', re.IGNORECASE)
REQUIREMENT = re.compile(NAME.pattern[:-1] + # Trim '$'
r"""\s*(?P<extras>\[.*\])?
\s*(?P<version>[(=~<>!@][^;]*)?
\s*(?P<envmark>;.*)?
$""", re.IGNORECASE | re.VERBOSE)
MARKER_OP = re.compile(r'(~=|===?|!=|<=?|>=?|\s+in\s+|\s+not in\s+)')
def validate_name(metadata):
name = metadata.get('name', None)
if name is None or NAME.match(name):
return []
return ['Invalid name: {!r}'.format(name)]
def _valid_version_specifier(s):
for clause in s.split(','):
if not VERSION_SPEC.match(clause.strip()):
return False
return True
def validate_requires_python(metadata):
spec = metadata.get('requires_python', None)
if spec is None or _valid_version_specifier(spec):
return []
return ['Invalid requires-python: {!r}'.format(spec)]
MARKER_VARS = {
'python_version', 'python_full_version', 'os_name', 'sys_platform',
'platform_release', 'platform_system', 'platform_version', 'platform_machine',
'platform_python_implementation', 'implementation_name',
'implementation_version', 'extra',
}
def validate_environment_marker(em):
clauses = re.split(r'\s+(?:and|or)\s+', em)
problems = []
for c in clauses:
# TODO: validate parentheses properly. They're allowed by PEP 508.
parts = MARKER_OP.split(c.strip('()'))
if len(parts) != 3:
problems.append("Invalid expression in environment marker: {!r}".format(c))
continue
l, op, r = parts
for var in (l.strip(), r.strip()):
if var[:1] in {'"', "'"}:
if len(var) < 2 or var[-1:] != var[:1]:
problems.append("Invalid string in environment marker: {}".format(var))
elif var not in MARKER_VARS:
problems.append("Invalid variable name in environment marker: {!r}".format(var))
return problems
def validate_requires_dist(metadata):
probs = []
for req in metadata.get('requires_dist', []):
m = REQUIREMENT.match(req)
if not m:
probs.append("Could not parse requirement: {!r}".format(req))
continue
extras, version, envmark = m.group('extras', 'version', 'envmark')
if not (extras is None or all(NAME.match(e.strip())
for e in extras[1:-1].split(','))):
probs.append("Invalid extras in requirement: {!r}".format(req))
if version is not None:
if version.startswith('(') and version.endswith(')'):
version = version[1:-1]
if version.startswith('@'):
pass # url specifier TODO: validate URL
elif not _valid_version_specifier(version):
print((extras, version, envmark))
probs.append("Invalid version specifier {!r} in requirement {!r}"
.format(version, req))
if envmark is not None:
probs.extend(validate_environment_marker(envmark[1:]))
return probs
def validate_url(url):
if url is None:
return []
probs = []
if not url.startswith(('http://', 'https://')):
probs.append("URL {!r} doesn't start with https:// or http://"
.format(url))
elif not url.split('//', 1)[1]:
probs.append("URL missing address")
return probs
def validate_project_urls(metadata):
probs = []
for prurl in metadata.get('project_urls', []):
name, url = prurl.split(',', 1)
url = url.lstrip()
if not name:
probs.append("No name for project URL {!r}".format(url))
elif len(name) > 32:
probs.append("Project URL name {!r} longer than 32 characters"
.format(name))
probs.extend(validate_url(url))
return probs
def validate_readme_rst(metadata):
mimetype = metadata.get('description_content_type', '')
if mimetype != 'text/x-rst':
return []
# rst check
raw_desc = metadata.get('description', '')
stream = io.StringIO()
res = render(raw_desc, stream)
if not res:
return [
("The file description seems not to be valid rst for PyPI;"
" it will be interpreted as plain text"),
stream.getvalue(),
]
return [] # rst rendered OK
def validate_config(config_info):
i = config_info
problems = sum([
validate_classifiers(i.metadata.get('classifiers')),
validate_entrypoints(i.entrypoints),
validate_name(i.metadata),
validate_requires_python(i.metadata),
validate_requires_dist(i.metadata),
validate_url(i.metadata.get('home_page', None)),
validate_project_urls(i.metadata),
validate_readme_rst(i.metadata)
], [])
for p in problems:
log.error(p)
return problems

14
flit/vcs/__init__.py Normal file
View File

@ -0,0 +1,14 @@
from pathlib import Path
from . import hg
from . import git
def identify_vcs(directory: Path):
directory = directory.resolve()
for p in [directory] + list(directory.parents):
if (p / '.git').is_dir():
return git
if (p / '.hg').is_dir():
return hg
return None

15
flit/vcs/git.py Normal file
View File

@ -0,0 +1,15 @@
import os
from subprocess import check_output
name = 'git'
def list_tracked_files(directory):
outb = check_output(['git', 'ls-files', '--recurse-submodules', '-z'],
cwd=str(directory))
return [os.fsdecode(l) for l in outb.strip(b'\0').split(b'\0') if l]
def list_untracked_deleted_files(directory):
outb = check_output(['git', 'ls-files', '--deleted', '--others',
'--exclude-standard', '-z'],
cwd=str(directory))
return [os.fsdecode(l) for l in outb.strip(b'\0').split(b'\0') if l]

34
flit/vcs/hg.py Normal file
View File

@ -0,0 +1,34 @@
import os
from subprocess import check_output
name = 'hg'
def find_repo_root(directory):
for p in [directory] + list(directory.parents):
if (p / '.hg').is_dir():
return p
def _repo_paths_to_directory_paths(paths, directory):
# 'hg status' gives paths from repo root, which may not be our directory.
directory = directory.resolve()
repo = find_repo_root(directory)
if directory != repo:
directory_in_repo = str(directory.relative_to(repo)) + os.sep
ix = len(directory_in_repo)
paths = [p[ix:] for p in paths
if os.path.normpath(p).startswith(directory_in_repo)]
return paths
def list_tracked_files(directory):
outb = check_output(['hg', 'status', '--clean', '--added', '--no-status'],
cwd=str(directory))
paths = [os.fsdecode(l) for l in outb.strip().splitlines()]
return _repo_paths_to_directory_paths(paths, directory)
def list_untracked_deleted_files(directory):
outb = check_output(['hg', 'status', '--unknown', '--deleted', '--no-status'],
cwd=str(directory))
paths = [os.fsdecode(l) for l in outb.strip().splitlines()]
return _repo_paths_to_directory_paths(paths, directory)

View File

View File

View File

@ -0,0 +1,2 @@
## shim readme clean to simplify vendorizing of readme.rst
clean = lambda x:x

View File

@ -0,0 +1,128 @@
# Copyright 2014 Donald Stufft
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Copied from https://github.com/pypa/readme_renderer
# Commit 5b455a9c5bafc1732dafad9619bcbfa8e15432c9
from __future__ import absolute_import, division, print_function
import io
import os.path
from docutils.core import publish_parts
from docutils.writers.html4css1 import HTMLTranslator, Writer
from docutils.utils import SystemMessage
from .clean import clean
class ReadMeHTMLTranslator(HTMLTranslator):
def depart_image(self, node):
uri = node["uri"]
ext = os.path.splitext(uri)[1].lower()
# we need to swap RST's use of `object` with `img` tags
# see http://git.io/5me3dA
if ext == ".svg":
# preserve essential attributes
atts = {}
for attribute, value in node.attributes.items():
# we have no time for empty values
if value:
if attribute == "uri":
atts["src"] = value
else:
atts[attribute] = value
# toss off `object` tag
self.body.pop()
# add on `img` with attributes
self.body.append(self.starttag(node, "img", **atts))
SETTINGS = {
# Cloaking email addresses provides a small amount of additional
# privacy protection for email addresses inside of a chunk of ReST.
"cloak_email_addresses": True,
# Prevent a lone top level heading from being promoted to document
# title, and thus second level headings from being promoted to top
# level.
"doctitle_xform": True,
# Prevent a lone subsection heading from being promoted to section
# title, and thus second level headings from being promoted to top
# level.
"sectsubtitle_xform": True,
# Set our initial header level
"initial_header_level": 2,
# Prevent local files from being included into the rendered output.
# This is a security concern because people can insert files
# that are part of the system, such as /etc/passwd.
"file_insertion_enabled": False,
# Halt rendering and throw an exception if there was any errors or
# warnings from docutils.
"halt_level": 2,
# Output math blocks as LaTeX that can be interpreted by MathJax for
# a prettier display of Math formulas.
"math_output": "MathJax",
# Disable raw html as enabling it is a security risk, we do not want
# people to be able to include any old HTML in the final output.
"raw_enabled": False,
# Disable all system messages from being reported.
"report_level": 5,
# Use typographic quotes, and transform --, ---, and ... into their
# typographic counterparts.
"smart_quotes": True,
# Strip all comments from the rendered output.
"strip_comments": True,
# PATCH FOR FLIT ----------------------------------
# Disable syntax highlighting so we don't need Pygments installed.
"syntax_highlight": "none",
# -------------------------------------------------
}
def render(raw, stream=None):
if stream is None:
# Use a io.StringIO as the warning stream to prevent warnings from
# being printed to sys.stderr.
stream = io.StringIO()
settings = SETTINGS.copy()
settings["warning_stream"] = stream
writer = Writer()
writer.translator_class = ReadMeHTMLTranslator
try:
parts = publish_parts(raw, writer=writer, settings_overrides=settings)
except SystemMessage:
rendered = None
else:
rendered = parts.get("fragment")
if rendered:
return clean(rendered)
else:
return None

12
flit/wheel.py Normal file
View File

@ -0,0 +1,12 @@
import logging
import flit_core.wheel as core_wheel
log = logging.getLogger(__name__)
def make_wheel_in(ini_path, wheel_directory, editable=False):
return core_wheel.make_wheel_in(ini_path, wheel_directory, editable)
class WheelBuilder(core_wheel.WheelBuilder):
pass

6
flit_core/README.rst Normal file
View File

@ -0,0 +1,6 @@
flit_core
---------
This provides a PEP 517 build backend for packages using Flit.
The only public interface is the API specified by PEP 517, at ``flit_core.buildapi``.

View File

@ -0,0 +1,48 @@
"""Install flit_core without using any other tools.
Normally, you would install flit_core with pip like any other Python package.
This script is meant to help with 'bootstrapping' other packaging
systems, where you may need flit_core to build other packaging tools.
Use 'python -m flit_core.wheel' to make a wheel, then:
python bootstrap_install.py flit_core-3.6.0-py3-none-any.whl
To install for something other than the Python running the script, pass a
site-packages or equivalent directory with the --installdir option.
"""
import argparse
import sys
import sysconfig
from pathlib import Path
from zipfile import ZipFile
def extract_wheel(whl_path, dest):
print("Installing to", dest)
with ZipFile(whl_path) as zf:
zf.extractall(dest)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'wheel',
type=Path,
help=f'flit_core wheel to install (.whl file)',
)
purelib = Path(sysconfig.get_path('purelib')).resolve()
parser.add_argument(
'--installdir',
'-i',
type=Path,
default=purelib,
help=f'installdir directory (defaults to {purelib})',
)
args = parser.parse_args()
if not args.wheel.name.startswith('flit_core-'):
sys.exit("Use this script only for flit_core wheels")
if not args.installdir.is_dir():
sys.exit(f"{args.installdir} is not a directory")
extract_wheel(args.wheel, args.installdir)

17
flit_core/build_dists.py Normal file
View File

@ -0,0 +1,17 @@
"""Build flit_core to upload to PyPI.
Normally, this should only be used by me when making a release.
"""
import os
from flit_core import buildapi
os.chdir(os.path.dirname(os.path.abspath(__file__)))
print("Building sdist")
sdist_fname = buildapi.build_sdist('dist/')
print(os.path.join('dist', sdist_fname))
print("\nBuilding wheel")
whl_fname = buildapi.build_wheel('dist/')
print(os.path.join('dist', whl_fname))

View File

@ -0,0 +1,7 @@
"""Flit's core machinery for building packages.
This package provides a standard PEP 517 API to build packages using Flit.
All the convenient development features live in the main 'flit' package.
"""
__version__ = '3.7.1'

View File

@ -0,0 +1,83 @@
"""PEP-517 compliant buildsystem API"""
import logging
import io
import os
import os.path as osp
from pathlib import Path
from .common import (
Module, make_metadata, write_entry_points, dist_info_name,
get_docstring_and_version_via_ast,
)
from .config import read_flit_config
from .wheel import make_wheel_in, _write_wheel_file
from .sdist import SdistBuilder
log = logging.getLogger(__name__)
# PEP 517 specifies that the CWD will always be the source tree
pyproj_toml = Path('pyproject.toml')
def get_requires_for_build_wheel(config_settings=None):
"""Returns a list of requirements for building, as strings"""
info = read_flit_config(pyproj_toml)
# If we can get version & description from pyproject.toml (PEP 621), or
# by parsing the module (_via_ast), we don't need any extra
# dependencies. If not, we'll need to try importing it, so report any
# runtime dependencies as build dependencies.
want_summary = 'description' in info.dynamic_metadata
want_version = 'version' in info.dynamic_metadata
module = Module(info.module, Path.cwd())
docstring, version = get_docstring_and_version_via_ast(module)
if (want_summary and not docstring) or (want_version and not version):
return info.metadata.get('requires_dist', [])
else:
return []
# Requirements to build an sdist are the same as for a wheel
get_requires_for_build_sdist = get_requires_for_build_wheel
# Requirements to build an editable are the same as for a wheel
get_requires_for_build_editable = get_requires_for_build_wheel
def prepare_metadata_for_build_wheel(metadata_directory, config_settings=None):
"""Creates {metadata_directory}/foo-1.2.dist-info"""
ini_info = read_flit_config(pyproj_toml)
module = Module(ini_info.module, Path.cwd())
metadata = make_metadata(module, ini_info)
dist_info = osp.join(metadata_directory,
dist_info_name(metadata.name, metadata.version))
os.mkdir(dist_info)
with io.open(osp.join(dist_info, 'WHEEL'), 'w', encoding='utf-8') as f:
_write_wheel_file(f, supports_py2=metadata.supports_py2)
with io.open(osp.join(dist_info, 'METADATA'), 'w', encoding='utf-8') as f:
metadata.write_metadata_file(f)
if ini_info.entrypoints:
with io.open(osp.join(dist_info, 'entry_points.txt'), 'w', encoding='utf-8') as f:
write_entry_points(ini_info.entrypoints, f)
return osp.basename(dist_info)
# Metadata for editable are the same as for a wheel
prepare_metadata_for_build_editable = prepare_metadata_for_build_wheel
def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
"""Builds a wheel, places it in wheel_directory"""
info = make_wheel_in(pyproj_toml, Path(wheel_directory))
return info.file.name
def build_editable(wheel_directory, config_settings=None, metadata_directory=None):
"""Builds an "editable" wheel, places it in wheel_directory"""
info = make_wheel_in(pyproj_toml, Path(wheel_directory), editable=True)
return info.file.name
def build_sdist(sdist_directory, config_settings=None):
"""Builds an sdist, places it in sdist_directory"""
path = SdistBuilder.from_ini_path(pyproj_toml).build(Path(sdist_directory))
return path.name

View File

@ -0,0 +1,447 @@
import ast
from contextlib import contextmanager
import hashlib
import logging
import os
import sys
from pathlib import Path
import re
log = logging.getLogger(__name__)
from .versionno import normalise_version
class Module(object):
"""This represents the module/package that we are going to distribute
"""
in_namespace_package = False
namespace_package_name = None
def __init__(self, name, directory=Path()):
self.name = name
# It must exist either as a .py file or a directory, but not both
name_as_path = name.replace('.', os.sep)
pkg_dir = directory / name_as_path
py_file = directory / (name_as_path+'.py')
src_pkg_dir = directory / 'src' / name_as_path
src_py_file = directory / 'src' / (name_as_path+'.py')
existing = set()
if pkg_dir.is_dir():
self.path = pkg_dir
self.is_package = True
self.prefix = ''
existing.add(pkg_dir)
if py_file.is_file():
self.path = py_file
self.is_package = False
self.prefix = ''
existing.add(py_file)
if src_pkg_dir.is_dir():
self.path = src_pkg_dir
self.is_package = True
self.prefix = 'src'
existing.add(src_pkg_dir)
if src_py_file.is_file():
self.path = src_py_file
self.is_package = False
self.prefix = 'src'
existing.add(src_py_file)
if len(existing) > 1:
raise ValueError(
"Multiple files or folders could be module {}: {}"
.format(name, ", ".join([str(p) for p in sorted(existing)]))
)
elif not existing:
raise ValueError("No file/folder found for module {}".format(name))
self.source_dir = directory / self.prefix
if '.' in name:
self.namespace_package_name = name.rpartition('.')[0]
self.in_namespace_package = True
@property
def file(self):
if self.is_package:
return self.path / '__init__.py'
else:
return self.path
def iter_files(self):
"""Iterate over the files contained in this module.
Yields absolute paths - caller may want to make them relative.
Excludes any __pycache__ and *.pyc files.
"""
def _include(path):
name = os.path.basename(path)
if (name == '__pycache__') or name.endswith('.pyc'):
return False
return True
if self.is_package:
# Ensure we sort all files and directories so the order is stable
for dirpath, dirs, files in os.walk(str(self.path)):
for file in sorted(files):
full_path = os.path.join(dirpath, file)
if _include(full_path):
yield full_path
dirs[:] = [d for d in sorted(dirs) if _include(d)]
else:
yield str(self.path)
class ProblemInModule(ValueError): pass
class NoDocstringError(ProblemInModule): pass
class NoVersionError(ProblemInModule): pass
class InvalidVersion(ProblemInModule): pass
class VCSError(Exception):
def __init__(self, msg, directory):
self.msg = msg
self.directory = directory
def __str__(self):
return self.msg + ' ({})'.format(self.directory)
@contextmanager
def _module_load_ctx():
"""Preserve some global state that modules might change at import time.
- Handlers on the root logger.
"""
logging_handlers = logging.root.handlers[:]
try:
yield
finally:
logging.root.handlers = logging_handlers
def get_docstring_and_version_via_ast(target):
"""
Return a tuple like (docstring, version) for the given module,
extracted by parsing its AST.
"""
# read as bytes to enable custom encodings
with target.file.open('rb') as f:
node = ast.parse(f.read())
for child in node.body:
# Only use the version from the given module if it's a simple
# string assignment to __version__
is_version_str = (
isinstance(child, ast.Assign)
and len(child.targets) == 1
and isinstance(child.targets[0], ast.Name)
and child.targets[0].id == "__version__"
and isinstance(child.value, ast.Str)
)
if is_version_str:
version = child.value.s
break
else:
version = None
return ast.get_docstring(node), version
# To ensure we're actually loading the specified file, give it a unique name to
# avoid any cached import. In normal use we'll only load one module per process,
# so it should only matter for the tests, but we'll do it anyway.
_import_i = 0
def get_docstring_and_version_via_import(target):
"""
Return a tuple like (docstring, version) for the given module,
extracted by importing the module and pulling __doc__ & __version__
from it.
"""
global _import_i
_import_i += 1
log.debug("Loading module %s", target.file)
from importlib.util import spec_from_file_location, module_from_spec
mod_name = 'flit_core.dummy.import%d' % _import_i
spec = spec_from_file_location(mod_name, target.file)
with _module_load_ctx():
m = module_from_spec(spec)
# Add the module to sys.modules to allow relative imports to work.
# importlib has more code around this to handle the case where two
# threads are trying to load the same module at the same time, but Flit
# should always be running a single thread, so we won't duplicate that.
sys.modules[mod_name] = m
try:
spec.loader.exec_module(m)
finally:
sys.modules.pop(mod_name, None)
docstring = m.__dict__.get('__doc__', None)
version = m.__dict__.get('__version__', None)
return docstring, version
def get_info_from_module(target, for_fields=('version', 'description')):
"""Load the module/package, get its docstring and __version__
"""
if not for_fields:
return {}
# What core metadata calls Summary, PEP 621 calls description
want_summary = 'description' in for_fields
want_version = 'version' in for_fields
log.debug("Loading module %s", target.file)
# Attempt to extract our docstring & version by parsing our target's
# AST, falling back to an import if that fails. This allows us to
# build without necessarily requiring that our built package's
# requirements are installed.
docstring, version = get_docstring_and_version_via_ast(target)
if (want_summary and not docstring) or (want_version and not version):
docstring, version = get_docstring_and_version_via_import(target)
res = {}
if want_summary:
if (not docstring) or not docstring.strip():
raise NoDocstringError(
'Flit cannot package module without docstring, or empty docstring. '
'Please add a docstring to your module ({}).'.format(target.file)
)
res['summary'] = docstring.lstrip().splitlines()[0]
if want_version:
res['version'] = check_version(version)
return res
def check_version(version):
"""
Check whether a given version string match PEP 440, and do normalisation.
Raise InvalidVersion/NoVersionError with relevant information if
version is invalid.
Log a warning if the version is not canonical with respect to PEP 440.
Returns the version in canonical PEP 440 format.
"""
if not version:
raise NoVersionError('Cannot package module without a version string. '
'Please define a `__version__ = "x.y.z"` in your module.')
if not isinstance(version, str):
raise InvalidVersion('__version__ must be a string, not {}.'
.format(type(version)))
# Import here to avoid circular import
version = normalise_version(version)
return version
script_template = """\
#!{interpreter}
# -*- coding: utf-8 -*-
import re
import sys
from {module} import {import_name}
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\\.pyw|\\.exe)?$', '', sys.argv[0])
sys.exit({func}())
"""
def parse_entry_point(ep):
"""Check and parse a 'package.module:func' style entry point specification.
Returns (modulename, funcname)
"""
if ':' not in ep:
raise ValueError("Invalid entry point (no ':'): %r" % ep)
mod, func = ep.split(':')
for piece in func.split('.'):
if not piece.isidentifier():
raise ValueError("Invalid entry point: %r is not an identifier" % piece)
for piece in mod.split('.'):
if not piece.isidentifier():
raise ValueError("Invalid entry point: %r is not a module path" % piece)
return mod, func
def write_entry_points(d, fp):
"""Write entry_points.txt from a two-level dict
Sorts on keys to ensure results are reproducible.
"""
for group_name in sorted(d):
fp.write(u'[{}]\n'.format(group_name))
group = d[group_name]
for name in sorted(group):
val = group[name]
fp.write(u'{}={}\n'.format(name, val))
fp.write(u'\n')
def hash_file(path, algorithm='sha256'):
with open(path, 'rb') as f:
h = hashlib.new(algorithm, f.read())
return h.hexdigest()
def normalize_file_permissions(st_mode):
"""Normalize the permission bits in the st_mode field from stat to 644/755
Popular VCSs only track whether a file is executable or not. The exact
permissions can vary on systems with different umasks. Normalising
to 644 (non executable) or 755 (executable) makes builds more reproducible.
"""
# Set 644 permissions, leaving higher bits of st_mode unchanged
new_mode = (st_mode | 0o644) & ~0o133
if st_mode & 0o100:
new_mode |= 0o111 # Executable: 644 -> 755
return new_mode
class Metadata(object):
summary = None
home_page = None
author = None
author_email = None
maintainer = None
maintainer_email = None
license = None
description = None
keywords = None
download_url = None
requires_python = None
description_content_type = None
platform = ()
supported_platform = ()
classifiers = ()
provides = ()
requires = ()
obsoletes = ()
project_urls = ()
provides_dist = ()
requires_dist = ()
obsoletes_dist = ()
requires_external = ()
provides_extra = ()
metadata_version = "2.1"
def __init__(self, data):
data = data.copy()
self.name = data.pop('name')
self.version = data.pop('version')
for k, v in data.items():
assert hasattr(self, k), "data does not have attribute '{}'".format(k)
setattr(self, k, v)
def _normalise_name(self, n):
return n.lower().replace('-', '_')
def write_metadata_file(self, fp):
"""Write out metadata in the email headers format"""
fields = [
'Metadata-Version',
'Name',
'Version',
]
optional_fields = [
'Summary',
'Home-page',
'License',
'Keywords',
'Author',
'Author-email',
'Maintainer',
'Maintainer-email',
'Requires-Python',
'Description-Content-Type',
]
for field in fields:
value = getattr(self, self._normalise_name(field))
fp.write(u"{}: {}\n".format(field, value))
for field in optional_fields:
value = getattr(self, self._normalise_name(field))
if value is not None:
# TODO: verify which fields can be multiline
# The spec has multiline examples for Author, Maintainer &
# License (& Description, but we put that in the body)
# Indent following lines with 8 spaces:
value = '\n '.join(value.splitlines())
fp.write(u"{}: {}\n".format(field, value))
for clsfr in self.classifiers:
fp.write(u'Classifier: {}\n'.format(clsfr))
for req in self.requires_dist:
fp.write(u'Requires-Dist: {}\n'.format(req))
for url in self.project_urls:
fp.write(u'Project-URL: {}\n'.format(url))
for extra in self.provides_extra:
fp.write(u'Provides-Extra: {}\n'.format(extra))
if self.description is not None:
fp.write(u'\n' + self.description + u'\n')
@property
def supports_py2(self):
"""Return True if Requires-Python indicates Python 2 support."""
for part in (self.requires_python or "").split(","):
if re.search(r"^\s*(>\s*(=\s*)?)?[3-9]", part):
return False
return True
def make_metadata(module, ini_info):
md_dict = {'name': module.name, 'provides': [module.name]}
md_dict.update(get_info_from_module(module, ini_info.dynamic_metadata))
md_dict.update(ini_info.metadata)
return Metadata(md_dict)
def normalize_dist_name(name: str, version: str) -> str:
"""Normalizes a name and a PEP 440 version
The resulting string is valid as dist-info folder name
and as first part of a wheel filename
See https://packaging.python.org/specifications/binary-distribution-format/#escaping-and-unicode
"""
normalized_name = re.sub(r'[-_.]+', '_', name, flags=re.UNICODE).lower()
assert check_version(version) == version
assert '-' not in version, 'Normalized versions cant have dashes'
return '{}-{}'.format(normalized_name, version)
def dist_info_name(distribution, version):
"""Get the correct name of the .dist-info folder"""
return normalize_dist_name(distribution, version) + '.dist-info'
def walk_data_dir(data_directory):
"""Iterate over the files in the given data directory.
Yields paths prefixed with data_directory - caller may want to make them
relative to that. Excludes any __pycache__ subdirectories.
"""
if data_directory is None:
return
for dirpath, dirs, files in os.walk(data_directory):
for file in sorted(files):
full_path = os.path.join(dirpath, file)
yield full_path
dirs[:] = [d for d in sorted(dirs) if d != '__pycache__']

View File

@ -0,0 +1,651 @@
import difflib
from email.headerregistry import Address
import errno
import logging
import os
import os.path as osp
from pathlib import Path
import re
from .vendor import tomli
from .versionno import normalise_version
log = logging.getLogger(__name__)
class ConfigError(ValueError):
pass
metadata_list_fields = {
'classifiers',
'requires',
'dev-requires'
}
metadata_allowed_fields = {
'module',
'author',
'author-email',
'maintainer',
'maintainer-email',
'home-page',
'license',
'keywords',
'requires-python',
'dist-name',
'description-file',
'requires-extra',
} | metadata_list_fields
metadata_required_fields = {
'module',
'author',
}
pep621_allowed_fields = {
'name',
'version',
'description',
'readme',
'requires-python',
'license',
'authors',
'maintainers',
'keywords',
'classifiers',
'urls',
'scripts',
'gui-scripts',
'entry-points',
'dependencies',
'optional-dependencies',
'dynamic',
}
def read_flit_config(path):
"""Read and check the `pyproject.toml` file with data about the package.
"""
d = tomli.loads(path.read_text('utf-8'))
return prep_toml_config(d, path)
class EntryPointsConflict(ConfigError):
def __str__(self):
return ('Please specify console_scripts entry points, or [scripts] in '
'flit config, not both.')
def prep_toml_config(d, path):
"""Validate config loaded from pyproject.toml and prepare common metadata
Returns a LoadedConfig object.
"""
dtool = d.get('tool', {}).get('flit', {})
if 'project' in d:
# Metadata in [project] table (PEP 621)
if 'metadata' in dtool:
raise ConfigError(
"Use [project] table for metadata or [tool.flit.metadata], not both."
)
if ('scripts' in dtool) or ('entrypoints' in dtool):
raise ConfigError(
"Don't mix [project] metadata with [tool.flit.scripts] or "
"[tool.flit.entrypoints]. Use [project.scripts],"
"[project.gui-scripts] or [project.entry-points] as replacements."
)
loaded_cfg = read_pep621_metadata(d['project'], path)
module_tbl = dtool.get('module', {})
if 'name' in module_tbl:
loaded_cfg.module = module_tbl['name']
elif 'metadata' in dtool:
# Metadata in [tool.flit.metadata] (pre PEP 621 format)
if 'module' in dtool:
raise ConfigError(
"Use [tool.flit.module] table with new-style [project] metadata, "
"not [tool.flit.metadata]"
)
loaded_cfg = _prep_metadata(dtool['metadata'], path)
loaded_cfg.dynamic_metadata = ['version', 'description']
if 'entrypoints' in dtool:
loaded_cfg.entrypoints = flatten_entrypoints(dtool['entrypoints'])
if 'scripts' in dtool:
loaded_cfg.add_scripts(dict(dtool['scripts']))
else:
raise ConfigError(
"Neither [project] nor [tool.flit.metadata] found in pyproject.toml"
)
unknown_sections = set(dtool) - {
'metadata', 'module', 'scripts', 'entrypoints', 'sdist', 'external-data'
}
unknown_sections = [s for s in unknown_sections if not s.lower().startswith('x-')]
if unknown_sections:
raise ConfigError('Unexpected tables in pyproject.toml: ' + ', '.join(
'[tool.flit.{}]'.format(s) for s in unknown_sections
))
if 'sdist' in dtool:
unknown_keys = set(dtool['sdist']) - {'include', 'exclude'}
if unknown_keys:
raise ConfigError(
"Unknown keys in [tool.flit.sdist]:" + ", ".join(unknown_keys)
)
loaded_cfg.sdist_include_patterns = _check_glob_patterns(
dtool['sdist'].get('include', []), 'include'
)
loaded_cfg.sdist_exclude_patterns = _check_glob_patterns(
dtool['sdist'].get('exclude', []), 'exclude'
)
data_dir = dtool.get('external-data', {}).get('directory', None)
if data_dir is not None:
toml_key = "tool.flit.external-data.directory"
if not isinstance(data_dir, str):
raise ConfigError(f"{toml_key} must be a string")
normp = osp.normpath(data_dir)
if osp.isabs(normp):
raise ConfigError(f"{toml_key} cannot be an absolute path")
if normp.startswith('..' + os.sep):
raise ConfigError(
f"{toml_key} cannot point outside the directory containing pyproject.toml"
)
if normp == '.':
raise ConfigError(
f"{toml_key} cannot refer to the directory containing pyproject.toml"
)
loaded_cfg.data_directory = path.parent / data_dir
if not loaded_cfg.data_directory.is_dir():
raise ConfigError(f"{toml_key} must refer to a directory")
return loaded_cfg
def flatten_entrypoints(ep):
"""Flatten nested entrypoints dicts.
Entry points group names can include dots. But dots in TOML make nested
dictionaries:
[entrypoints.a.b] # {'entrypoints': {'a': {'b': {}}}}
The proper way to avoid this is:
[entrypoints."a.b"] # {'entrypoints': {'a.b': {}}}
But since there isn't a need for arbitrarily nested mappings in entrypoints,
flit allows you to use the former. This flattens the nested dictionaries
from loading pyproject.toml.
"""
def _flatten(d, prefix):
d1 = {}
for k, v in d.items():
if isinstance(v, dict):
for flattened in _flatten(v, prefix+'.'+k):
yield flattened
else:
d1[k] = v
if d1:
yield prefix, d1
res = {}
for k, v in ep.items():
res.update(_flatten(v, k))
return res
def _check_glob_patterns(pats, clude):
"""Check and normalise glob patterns for sdist include/exclude"""
if not isinstance(pats, list):
raise ConfigError("sdist {} patterns must be a list".format(clude))
# Windows filenames can't contain these (nor * or ?, but they are part of
# glob patterns) - https://stackoverflow.com/a/31976060/434217
bad_chars = re.compile(r'[\000-\037<>:"\\]')
normed = []
for p in pats:
if bad_chars.search(p):
raise ConfigError(
'{} pattern {!r} contains bad characters (<>:\"\\ or control characters)'
.format(clude, p)
)
if '**' in p:
raise ConfigError(
"Recursive globbing (**) is not supported yet (in {} pattern {!r})"
.format(clude, p)
)
normp = osp.normpath(p)
if osp.isabs(normp):
raise ConfigError(
'{} pattern {!r} is an absolute path'.format(clude, p)
)
if normp.startswith('..' + os.sep):
raise ConfigError(
'{} pattern {!r} points out of the directory containing pyproject.toml'
.format(clude, p)
)
normed.append(normp)
return normed
class LoadedConfig(object):
def __init__(self):
self.module = None
self.metadata = {}
self.reqs_by_extra = {}
self.entrypoints = {}
self.referenced_files = []
self.sdist_include_patterns = []
self.sdist_exclude_patterns = []
self.dynamic_metadata = []
self.data_directory = None
def add_scripts(self, scripts_dict):
if scripts_dict:
if 'console_scripts' in self.entrypoints:
raise EntryPointsConflict
else:
self.entrypoints['console_scripts'] = scripts_dict
readme_ext_to_content_type = {
'.rst': 'text/x-rst',
'.md': 'text/markdown',
'.txt': 'text/plain',
}
def description_from_file(rel_path: str, proj_dir: Path, guess_mimetype=True):
if osp.isabs(rel_path):
raise ConfigError("Readme path must be relative")
desc_path = proj_dir / rel_path
try:
with desc_path.open('r', encoding='utf-8') as f:
raw_desc = f.read()
except IOError as e:
if e.errno == errno.ENOENT:
raise ConfigError(
"Description file {} does not exist".format(desc_path)
)
raise
if guess_mimetype:
ext = desc_path.suffix.lower()
try:
mimetype = readme_ext_to_content_type[ext]
except KeyError:
log.warning("Unknown extension %r for description file.", ext)
log.warning(" Recognised extensions: %s",
" ".join(readme_ext_to_content_type))
mimetype = None
else:
mimetype = None
return raw_desc, mimetype
def _prep_metadata(md_sect, path):
"""Process & verify the metadata from a config file
- Pull out the module name we're packaging.
- Read description-file and check that it's valid rst
- Convert dashes in key names to underscores
(e.g. home-page in config -> home_page in metadata)
"""
if not set(md_sect).issuperset(metadata_required_fields):
missing = metadata_required_fields - set(md_sect)
raise ConfigError("Required fields missing: " + '\n'.join(missing))
res = LoadedConfig()
res.module = md_sect.get('module')
if not all([m.isidentifier() for m in res.module.split(".")]):
raise ConfigError("Module name %r is not a valid identifier" % res.module)
md_dict = res.metadata
# Description file
if 'description-file' in md_sect:
desc_path = md_sect.get('description-file')
res.referenced_files.append(desc_path)
desc_content, mimetype = description_from_file(desc_path, path.parent)
md_dict['description'] = desc_content
md_dict['description_content_type'] = mimetype
if 'urls' in md_sect:
project_urls = md_dict['project_urls'] = []
for label, url in sorted(md_sect.pop('urls').items()):
project_urls.append("{}, {}".format(label, url))
for key, value in md_sect.items():
if key in {'description-file', 'module'}:
continue
if key not in metadata_allowed_fields:
closest = difflib.get_close_matches(key, metadata_allowed_fields,
n=1, cutoff=0.7)
msg = "Unrecognised metadata key: {!r}".format(key)
if closest:
msg += " (did you mean {!r}?)".format(closest[0])
raise ConfigError(msg)
k2 = key.replace('-', '_')
md_dict[k2] = value
if key in metadata_list_fields:
if not isinstance(value, list):
raise ConfigError('Expected a list for {} field, found {!r}'
.format(key, value))
if not all(isinstance(a, str) for a in value):
raise ConfigError('Expected a list of strings for {} field'
.format(key))
elif key == 'requires-extra':
if not isinstance(value, dict):
raise ConfigError('Expected a dict for requires-extra field, found {!r}'
.format(value))
if not all(isinstance(e, list) for e in value.values()):
raise ConfigError('Expected a dict of lists for requires-extra field')
for e, reqs in value.items():
if not all(isinstance(a, str) for a in reqs):
raise ConfigError('Expected a string list for requires-extra. (extra {})'
.format(e))
else:
if not isinstance(value, str):
raise ConfigError('Expected a string for {} field, found {!r}'
.format(key, value))
# What we call requires in the ini file is technically requires_dist in
# the metadata.
if 'requires' in md_dict:
md_dict['requires_dist'] = md_dict.pop('requires')
# And what we call dist-name is name in the metadata
if 'dist_name' in md_dict:
md_dict['name'] = md_dict.pop('dist_name')
# Move dev-requires into requires-extra
reqs_noextra = md_dict.pop('requires_dist', [])
res.reqs_by_extra = md_dict.pop('requires_extra', {})
dev_requires = md_dict.pop('dev_requires', None)
if dev_requires is not None:
if 'dev' in res.reqs_by_extra:
raise ConfigError(
'dev-requires occurs together with its replacement requires-extra.dev.')
else:
log.warning(
'"dev-requires = ..." is obsolete. Use "requires-extra = {"dev" = ...}" instead.')
res.reqs_by_extra['dev'] = dev_requires
# Add requires-extra requirements into requires_dist
md_dict['requires_dist'] = \
reqs_noextra + list(_expand_requires_extra(res.reqs_by_extra))
md_dict['provides_extra'] = sorted(res.reqs_by_extra.keys())
# For internal use, record the main requirements as a '.none' extra.
res.reqs_by_extra['.none'] = reqs_noextra
return res
def _expand_requires_extra(re):
for extra, reqs in sorted(re.items()):
for req in reqs:
if ';' in req:
name, envmark = req.split(';', 1)
yield '{} ; extra == "{}" and ({})'.format(name, extra, envmark)
else:
yield '{} ; extra == "{}"'.format(req, extra)
def _check_type(d, field_name, cls):
if not isinstance(d[field_name], cls):
raise ConfigError(
"{} field should be {}, not {}".format(field_name, cls, type(d[field_name]))
)
def _check_list_of_str(d, field_name):
if not isinstance(d[field_name], list) or not all(
isinstance(e, str) for e in d[field_name]
):
raise ConfigError(
"{} field should be a list of strings".format(field_name)
)
def read_pep621_metadata(proj, path) -> LoadedConfig:
lc = LoadedConfig()
md_dict = lc.metadata
if 'name' not in proj:
raise ConfigError('name must be specified in [project] table')
_check_type(proj, 'name', str)
lc.module = md_dict['name'] = proj['name']
unexpected_keys = proj.keys() - pep621_allowed_fields
if unexpected_keys:
log.warning("Unexpected names under [project]: %s", ', '.join(unexpected_keys))
if 'version' in proj:
_check_type(proj, 'version', str)
md_dict['version'] = normalise_version(proj['version'])
if 'description' in proj:
_check_type(proj, 'description', str)
md_dict['summary'] = proj['description']
if 'readme' in proj:
readme = proj['readme']
if isinstance(readme, str):
lc.referenced_files.append(readme)
desc_content, mimetype = description_from_file(readme, path.parent)
elif isinstance(readme, dict):
unrec_keys = set(readme.keys()) - {'text', 'file', 'content-type'}
if unrec_keys:
raise ConfigError(
"Unrecognised keys in [project.readme]: {}".format(unrec_keys)
)
if 'content-type' in readme:
mimetype = readme['content-type']
mtype_base = mimetype.split(';')[0].strip() # e.g. text/x-rst
if mtype_base not in readme_ext_to_content_type.values():
raise ConfigError(
"Unrecognised readme content-type: {!r}".format(mtype_base)
)
# TODO: validate content-type parameters (charset, md variant)?
else:
raise ConfigError(
"content-type field required in [project.readme] table"
)
if 'file' in readme:
if 'text' in readme:
raise ConfigError(
"[project.readme] should specify file or text, not both"
)
lc.referenced_files.append(readme['file'])
desc_content, _ = description_from_file(
readme['file'], path.parent, guess_mimetype=False
)
elif 'text' in readme:
desc_content = readme['text']
else:
raise ConfigError(
"file or text field required in [project.readme] table"
)
else:
raise ConfigError(
"project.readme should be a string or a table"
)
md_dict['description'] = desc_content
md_dict['description_content_type'] = mimetype
if 'requires-python' in proj:
md_dict['requires_python'] = proj['requires-python']
if 'license' in proj:
_check_type(proj, 'license', dict)
license_tbl = proj['license']
unrec_keys = set(license_tbl.keys()) - {'text', 'file'}
if unrec_keys:
raise ConfigError(
"Unrecognised keys in [project.license]: {}".format(unrec_keys)
)
# TODO: Do something with license info.
# The 'License' field in packaging metadata is a brief description of
# a license, not the full text or a file path. PEP 639 will improve on
# how licenses are recorded.
if 'file' in license_tbl:
if 'text' in license_tbl:
raise ConfigError(
"[project.license] should specify file or text, not both"
)
lc.referenced_files.append(license_tbl['file'])
elif 'text' in license_tbl:
pass
else:
raise ConfigError(
"file or text field required in [project.license] table"
)
if 'authors' in proj:
_check_type(proj, 'authors', list)
md_dict.update(pep621_people(proj['authors']))
if 'maintainers' in proj:
_check_type(proj, 'maintainers', list)
md_dict.update(pep621_people(proj['maintainers'], group_name='maintainer'))
if 'keywords' in proj:
_check_list_of_str(proj, 'keywords')
md_dict['keywords'] = ",".join(proj['keywords'])
if 'classifiers' in proj:
_check_list_of_str(proj, 'classifiers')
md_dict['classifiers'] = proj['classifiers']
if 'urls' in proj:
_check_type(proj, 'urls', dict)
project_urls = md_dict['project_urls'] = []
for label, url in sorted(proj['urls'].items()):
project_urls.append("{}, {}".format(label, url))
if 'entry-points' in proj:
_check_type(proj, 'entry-points', dict)
for grp in proj['entry-points'].values():
if not isinstance(grp, dict):
raise ConfigError(
"projects.entry-points should only contain sub-tables"
)
if not all(isinstance(k, str) for k in grp.values()):
raise ConfigError(
"[projects.entry-points.*] tables should have string values"
)
if set(proj['entry-points'].keys()) & {'console_scripts', 'gui_scripts'}:
raise ConfigError(
"Scripts should be specified in [project.scripts] or "
"[project.gui-scripts], not under [project.entry-points]"
)
lc.entrypoints = proj['entry-points']
if 'scripts' in proj:
_check_type(proj, 'scripts', dict)
if not all(isinstance(k, str) for k in proj['scripts'].values()):
raise ConfigError(
"[projects.scripts] table should have string values"
)
lc.entrypoints['console_scripts'] = proj['scripts']
if 'gui-scripts' in proj:
_check_type(proj, 'gui-scripts', dict)
if not all(isinstance(k, str) for k in proj['gui-scripts'].values()):
raise ConfigError(
"[projects.gui-scripts] table should have string values"
)
lc.entrypoints['gui_scripts'] = proj['gui-scripts']
if 'dependencies' in proj:
_check_list_of_str(proj, 'dependencies')
reqs_noextra = proj['dependencies']
else:
reqs_noextra = []
if 'optional-dependencies' in proj:
_check_type(proj, 'optional-dependencies', dict)
optdeps = proj['optional-dependencies']
if not all(isinstance(e, list) for e in optdeps.values()):
raise ConfigError(
'Expected a dict of lists in optional-dependencies field'
)
for e, reqs in optdeps.items():
if not all(isinstance(a, str) for a in reqs):
raise ConfigError(
'Expected a string list for optional-dependencies ({})'.format(e)
)
lc.reqs_by_extra = optdeps.copy()
md_dict['provides_extra'] = sorted(lc.reqs_by_extra.keys())
md_dict['requires_dist'] = \
reqs_noextra + list(_expand_requires_extra(lc.reqs_by_extra))
# For internal use, record the main requirements as a '.none' extra.
if reqs_noextra:
lc.reqs_by_extra['.none'] = reqs_noextra
if 'dynamic' in proj:
_check_list_of_str(proj, 'dynamic')
dynamic = set(proj['dynamic'])
unrec_dynamic = dynamic - {'version', 'description'}
if unrec_dynamic:
raise ConfigError(
"flit only supports dynamic metadata for 'version' & 'description'"
)
if dynamic.intersection(proj):
raise ConfigError(
"keys listed in project.dynamic must not be in [project] table"
)
lc.dynamic_metadata = dynamic
if ('version' not in proj) and ('version' not in lc.dynamic_metadata):
raise ConfigError(
"version must be specified under [project] or listed as a dynamic field"
)
if ('description' not in proj) and ('description' not in lc.dynamic_metadata):
raise ConfigError(
"description must be specified under [project] or listed as a dynamic field"
)
return lc
def pep621_people(people, group_name='author') -> dict:
"""Convert authors/maintainers from PEP 621 to core metadata fields"""
names, emails = [], []
for person in people:
if not isinstance(person, dict):
raise ConfigError("{} info must be list of dicts".format(group_name))
unrec_keys = set(person.keys()) - {'name', 'email'}
if unrec_keys:
raise ConfigError(
"Unrecognised keys in {} info: {}".format(group_name, unrec_keys)
)
if 'email' in person:
email = person['email']
if 'name' in person:
email = str(Address(person['name'], addr_spec=email))
emails.append(email)
elif 'name' in person:
names.append(person['name'])
res = {}
if names:
res[group_name] = ", ".join(names)
if emails:
res[group_name + '_email'] = ", ".join(emails)
return res

View File

@ -0,0 +1,202 @@
from collections import defaultdict
from copy import copy
from glob import glob
from gzip import GzipFile
import io
import logging
import os
import os.path as osp
from pathlib import Path
from posixpath import join as pjoin
import tarfile
from . import common
log = logging.getLogger(__name__)
def clean_tarinfo(ti, mtime=None):
"""Clean metadata from a TarInfo object to make it more reproducible.
- Set uid & gid to 0
- Set uname and gname to ""
- Normalise permissions to 644 or 755
- Set mtime if not None
"""
ti = copy(ti)
ti.uid = 0
ti.gid = 0
ti.uname = ''
ti.gname = ''
ti.mode = common.normalize_file_permissions(ti.mode)
if mtime is not None:
ti.mtime = mtime
return ti
class FilePatterns:
"""Manage a set of file inclusion/exclusion patterns relative to basedir"""
def __init__(self, patterns, basedir):
self.basedir = basedir
self.dirs = set()
self.files = set()
for pattern in patterns:
for path in sorted(glob(osp.join(basedir, pattern))):
rel = osp.relpath(path, basedir)
if osp.isdir(path):
self.dirs.add(rel)
else:
self.files.add(rel)
def match_file(self, rel_path):
if rel_path in self.files:
return True
return any(rel_path.startswith(d + os.sep) for d in self.dirs)
def match_dir(self, rel_path):
if rel_path in self.dirs:
return True
# Check if it's a subdirectory of any directory in the list
return any(rel_path.startswith(d + os.sep) for d in self.dirs)
class SdistBuilder:
"""Builds a minimal sdist
These minimal sdists should work for PEP 517.
The class is extended in flit.sdist to make a more 'full fat' sdist,
which is what should normally be published to PyPI.
"""
def __init__(self, module, metadata, cfgdir, reqs_by_extra, entrypoints,
extra_files, data_directory, include_patterns=(), exclude_patterns=()):
self.module = module
self.metadata = metadata
self.cfgdir = cfgdir
self.reqs_by_extra = reqs_by_extra
self.entrypoints = entrypoints
self.extra_files = extra_files
self.data_directory = data_directory
self.includes = FilePatterns(include_patterns, str(cfgdir))
self.excludes = FilePatterns(exclude_patterns, str(cfgdir))
@classmethod
def from_ini_path(cls, ini_path: Path):
# Local import so bootstrapping doesn't try to load toml
from .config import read_flit_config
ini_info = read_flit_config(ini_path)
srcdir = ini_path.parent
module = common.Module(ini_info.module, srcdir)
metadata = common.make_metadata(module, ini_info)
extra_files = [ini_path.name] + ini_info.referenced_files
return cls(
module, metadata, srcdir, ini_info.reqs_by_extra,
ini_info.entrypoints, extra_files, ini_info.data_directory,
ini_info.sdist_include_patterns, ini_info.sdist_exclude_patterns,
)
def prep_entry_points(self):
# Reformat entry points from dict-of-dicts to dict-of-lists
res = defaultdict(list)
for groupname, group in self.entrypoints.items():
for name, ep in sorted(group.items()):
res[groupname].append('{} = {}'.format(name, ep))
return dict(res)
def select_files(self):
"""Pick which files from the source tree will be included in the sdist
This is overridden in flit itself to use information from a VCS to
include tests, docs, etc. for a 'gold standard' sdist.
"""
cfgdir_s = str(self.cfgdir)
return [
osp.relpath(p, cfgdir_s) for p in self.module.iter_files()
] + [
osp.relpath(p, cfgdir_s) for p in common.walk_data_dir(self.data_directory)
] + self.extra_files
def apply_includes_excludes(self, files):
cfgdir_s = str(self.cfgdir)
files = {f for f in files if not self.excludes.match_file(f)}
for f_rel in self.includes.files:
if not self.excludes.match_file(f_rel):
files.add(f_rel)
for rel_d in self.includes.dirs:
for dirpath, dirs, dfiles in os.walk(osp.join(cfgdir_s, rel_d)):
for file in dfiles:
f_abs = osp.join(dirpath, file)
f_rel = osp.relpath(f_abs, cfgdir_s)
if not self.excludes.match_file(f_rel):
files.add(f_rel)
# Filter subdirectories before os.walk scans them
dirs[:] = [d for d in dirs if not self.excludes.match_dir(
osp.relpath(osp.join(dirpath, d), cfgdir_s)
)]
crucial_files = set(
self.extra_files + [str(self.module.file.relative_to(self.cfgdir))]
)
missing_crucial = crucial_files - files
if missing_crucial:
raise Exception("Crucial files were excluded from the sdist: {}"
.format(", ".join(missing_crucial)))
return sorted(files)
def add_setup_py(self, files_to_add, target_tarfile):
"""No-op here; overridden in flit to generate setup.py"""
pass
@property
def dir_name(self):
return '{}-{}'.format(self.metadata.name, self.metadata.version)
def build(self, target_dir, gen_setup_py=True):
os.makedirs(str(target_dir), exist_ok=True)
target = target_dir / '{}-{}.tar.gz'.format(
self.metadata.name, self.metadata.version
)
source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH', '')
mtime = int(source_date_epoch) if source_date_epoch else None
gz = GzipFile(str(target), mode='wb', mtime=mtime)
tf = tarfile.TarFile(str(target), mode='w', fileobj=gz,
format=tarfile.PAX_FORMAT)
try:
files_to_add = self.apply_includes_excludes(self.select_files())
for relpath in files_to_add:
path = str(self.cfgdir / relpath)
ti = tf.gettarinfo(path, arcname=pjoin(self.dir_name, relpath))
ti = clean_tarinfo(ti, mtime)
if ti.isreg():
with open(path, 'rb') as f:
tf.addfile(ti, f)
else:
tf.addfile(ti) # Symlinks & ?
if gen_setup_py:
self.add_setup_py(files_to_add, tf)
stream = io.StringIO()
self.metadata.write_metadata_file(stream)
pkg_info = stream.getvalue().encode()
ti = tarfile.TarInfo(pjoin(self.dir_name, 'PKG-INFO'))
ti.size = len(pkg_info)
tf.addfile(ti, io.BytesIO(pkg_info))
finally:
tf.close()
gz.close()
log.info("Built sdist: %s", target)
return target

View File

View File

@ -0,0 +1,4 @@
This is an example long description for tests to load.
This file is `valid reStructuredText
<http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html>`_.

View File

@ -0,0 +1,9 @@
[build-system]
requires = ["flit"]
[tool.flit.metadata]
module = "module1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"
description-file = "module1.py" # WRONG

View File

@ -0,0 +1,8 @@
[build-system]
requires = ["flit"]
[tool.flit.metadata]
module = "module1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"

View File

@ -0,0 +1,4 @@
"""This module has a __version__ that requires runtime interpretation"""
__version__ = ".".join(["1", "2", "3"])

View File

@ -0,0 +1,12 @@
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
module = "module1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"
requires = [
"numpy >=1.16.0",
]

View File

@ -0,0 +1,13 @@
[build-system]
requires = ["flit"]
[tool.flit.metadata]
module = "module1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"
description-file = "EG_README.rst"
dev-requires = ["apackage"]
[tool.flit.metadata.requires-extra]
dev = ["anotherpackage"]

View File

@ -0,0 +1,15 @@
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
module = "module1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"
description-file = "EG_README.rst"
requires = ["toml"]
[tool.flit.metadata.requires-extra]
test = ["pytest"]
custom = ["requests"]

View File

@ -0,0 +1,3 @@
"""This module has a __version__ that requires a relative import"""
from ._version import __version__

View File

@ -0,0 +1 @@
__version__ = '0.5.8'

View File

@ -0,0 +1,10 @@
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[project]
name = "package1"
authors = [
{name = "Sir Röbin", email = "robin@camelot.uk"}
]
dynamic = ["version", "description"]

View File

@ -0,0 +1,2 @@
This directory will match the LICENSE* glob which Flit uses to add license
files to wheel metadata.

View File

@ -0,0 +1 @@
sdists should include this (see pyproject.toml)

View File

@ -0,0 +1 @@
sdists should include this (see pyproject.toml)

View File

@ -0,0 +1 @@
sdists should exclude this (see pyproject.toml)

View File

@ -0,0 +1,3 @@
"""For tests"""
__version__ = '0.1'

View File

@ -0,0 +1,12 @@
[build-system]
requires = ["flit"]
build-backend = "flit.buildapi"
[tool.flit.metadata]
module = "module1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
[tool.flit.sdist]
include = ["doc"]
exclude = ["doc/*.txt"]

View File

@ -0,0 +1,3 @@
"""Sample module with invalid __version__ string"""
__version__ = "not starting with a number"

View File

@ -0,0 +1,9 @@
[build-system]
requires = ["flit"]
[tool.flit.metadata]
module = "missingdescriptionfile"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/missingdescriptionfile"
description-file = "definitely-missing.rst"

View File

@ -0,0 +1,10 @@
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
module = "package1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
descryption-file = "my-description.rst" # Deliberate typo for test
home-page = "http://github.com/sirrobin/package1"

View File

@ -0,0 +1,5 @@
[metadata]
module=module1
author=Sir Robin
author-email=robin@camelot.uk
home-page=http://github.com/sirrobin/module1

View File

@ -0,0 +1,12 @@
[build-system]
requires = ["flit"]
[tool.flit.metadata]
module = "module1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"
description-file = "EG_README.rst"
[tool.flit.metadata.urls]
Documentation = "https://example.com/module1"

View File

@ -0,0 +1,3 @@
"""Example module"""
__version__ = '0.1'

View File

@ -0,0 +1,10 @@
"""
Docstring formatted like this.
"""
a = {}
# An assignment to a subscript (a['test']) broke introspection
# https://github.com/pypa/flit/issues/343
a['test'] = 6
__version__ = '7.0'

View File

@ -0,0 +1,8 @@
"""
A sample unimportable module
"""
raise ImportError()
__version__ = "0.1"

View File

@ -0,0 +1 @@
Sample description for test.

View File

@ -0,0 +1,12 @@
[build-system]
requires = ["flit"]
[tool.flit.metadata]
module = "no_docstring"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/no_docstring"
description-file = "EG_README.rst"
[tool.flit.metadata.urls]
Documentation = "https://example.com/no_docstring"

View File

@ -0,0 +1 @@
__version__ = '7.0'

View File

@ -0,0 +1,4 @@
This is an example long description for tests to load.
This file is `valid reStructuredText
<http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html>`_.

View File

@ -0,0 +1,8 @@
"""
==================
ns1.pkg
==================
"""
__version__ = '0.1'

View File

@ -0,0 +1,10 @@
[build-system]
requires = ["flit_core >=3.5,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
module = "ns1.pkg"
author = "Sir Robin"
author-email = "robin@camelot.uk"
home-page = "http://github.com/sirrobin/module1"
description-file = "EG_README.rst"

View File

@ -0,0 +1,13 @@
[build-system]
requires = ["flit_core >=2,<4"]
build-backend = "flit_core.buildapi"
[tool.flit.metadata]
module = "package1"
author = "Sir Robin"
author-email = "robin@camelot.uk"
description-file = "my-description.rst"
home-page = "http://github.com/sirrobin/package1"
[scripts]
pkg_script = "package1:main"

View File

@ -0,0 +1,6 @@
"""A sample package"""
__version__ = '0.1'
def main():
print("package1 main")

View File

@ -0,0 +1,2 @@
#!/bin/sh
echo "Example data file"

View File

@ -0,0 +1 @@
a = 1

View File

@ -0,0 +1 @@
{"example": true}

View File

@ -0,0 +1 @@
This file should be added to wheels

Some files were not shown because too many files have changed in this diff Show More