Skip to content

Commit

Permalink
Merge 9fea9f0 into 57e522a
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Oct 30, 2020
2 parents 57e522a + 9fea9f0 commit a06936d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ Changelog

- Drop Python 3.5 support.

- Switch from ``pep517`` to `python-build <https://pypi.org/p/build>`__ (
`#128 <https://github.com/mgedmin/check-manifest/pull/128>`__).

- Add ``--no-build-isolation`` option so check-manifest can succeed building
pep517-based distributions without an internet connection. With
``--no-build-isolation``, you must preinstall the ``build-system.requires``
beforehand. (
`#128 <https://github.com/mgedmin/check-manifest/pull/128>`__).


0.44 (2020-10-03)
-----------------
Expand Down
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ git-workflow. Add the following to your ``.pre-commit-config.yaml``.
hooks:
- id: check-manifest
If you are running pre-commit without a network, you can utilize
``args: [--no-build-isolation]`` to prevent a ``pip install`` reaching out to
pypi. If you have additional ``build-system.requires`` outside of pip /
setuptools / wheel you will want to list those in ``additional_dependencies``.

.. code-block:: yaml
repos:
- repo: https://github.com/mgedmin/check-manifest
rev: ... # pick a valid tag / revision
hooks:
- id: check-manifest
args: [--no-build-isolation]
additional_dependencies: [setuptools-scm]
.. |buildstatus| image:: https://api.travis-ci.com/mgedmin/check-manifest.svg?branch=master
.. _buildstatus: https://travis-ci.com/mgedmin/check-manifest
Expand Down
27 changes: 19 additions & 8 deletions check_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,26 +897,30 @@ def should_use_pep_517():
return True


def build_sdist(tempdir, python=sys.executable):
def build_sdist(tempdir, python=sys.executable, build_isolation=True):
"""Build a source distribution in a temporary directory.
Should be run with the current working directory inside the Python package
you want to build.
"""
if should_use_pep_517():
# I could do this in-process with
# import pep517.envbuild
# pep517.envbuild.build_sdist('.', tempdir)
# import build.__main__
# build.__main__.build('.', tempdir)
# but then it would print a bunch of things to stdout and I'd have to
# worry about exceptions
run([python, '-m', 'pep517.build', '--source', '-o', tempdir, '.'])
cmd = [python, '-m', 'build', '--sdist', '.', '--outdir', tempdir]
if not build_isolation:
cmd.append('--no-isolation')
run(cmd)
else:
run([python, 'setup.py', 'sdist', '-d', tempdir])


def check_manifest(source_tree='.', create=False, update=False,
python=sys.executable, ui=None, extra_ignore=None,
extra_ignore_bad_ideas=None):
extra_ignore_bad_ideas=None,
build_isolation=True):
"""Compare a generated source distribution with list of files in a VCS.
Returns True if the manifest is fine.
Expand Down Expand Up @@ -944,7 +948,7 @@ def check_manifest(source_tree='.', create=False, update=False,
raise Failure('There are no files added to version control!')
ui.info_begin("building an sdist")
with mkdtemp('-sdist') as tempdir:
build_sdist(tempdir, python=python)
build_sdist(tempdir, python=python, build_isolation=build_isolation)
sdist_filename = get_one_file_in(tempdir)
ui.info_continue(": %s" % os.path.basename(sdist_filename))
sdist_files = get_sdist_file_list(sdist_filename, ignore)
Expand All @@ -970,7 +974,7 @@ def check_manifest(source_tree='.', create=False, update=False,
with cd(tempsourcedir):
with mkdtemp('-sdist') as tempdir:
os.environ['SETUPTOOLS_SCM_PRETEND_VERSION'] = version
build_sdist(tempdir, python=python)
build_sdist(tempdir, python=python, build_isolation=build_isolation)
sdist_filename = get_one_file_in(tempdir)
ui.info_continue(": %s" % os.path.basename(sdist_filename))
clean_sdist_files = get_sdist_file_list(sdist_filename, ignore)
Expand Down Expand Up @@ -1050,6 +1054,12 @@ def main():
parser.add_argument('--ignore-bad-ideas', metavar='patterns',
default=[], help='ignore bad idea files/directories '
'matching these comma-separated patterns')
parser.add_argument(
'--no-build-isolation', dest='build_isolation', action='store_false',
help='Disable isolation when building a modern source distribution. '
'Build dependencies specified by PEP 518 must be already installed if '
'this option is used.',
)
args = parser.parse_args()

ignore = IgnoreList()
Expand All @@ -1066,7 +1076,8 @@ def main():
if not check_manifest(args.source_tree, create=args.create,
update=args.update, python=args.python,
ui=ui, extra_ignore=ignore,
extra_ignore_bad_ideas=ignore_bad_ideas):
extra_ignore_bad_ideas=ignore_bad_ideas,
build_isolation=args.build_isolation):
sys.exit(1)
except Failure as e:
ui.error(str(e))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
zip_safe=False,
python_requires=">=3.6",
install_requires=[
'pep517',
'build>=0.1',
'setuptools',
'toml',
],
Expand Down
10 changes: 8 additions & 2 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def test_should_use_pep517_yes_please(self):
with cd(src_dir):
self.assertTrue(should_use_pep_517())

def test_build_sdist(self):
def _test_build_sdist_pep517(self, build_isolation):
from check_manifest import build_sdist, cd, get_one_file_in
src_dir = self.make_temp_dir()
filename = os.path.join(src_dir, 'pyproject.toml')
Expand All @@ -621,9 +621,15 @@ def test_build_sdist(self):
out_dir = self.make_temp_dir()
python = os.path.abspath(sys.executable)
with cd(src_dir):
build_sdist(out_dir, python=python)
build_sdist(out_dir, python=python, build_isolation=build_isolation)
self.assertTrue(get_one_file_in(out_dir))

def test_build_sdist_pep517_isolated(self):
self._test_build_sdist_pep517(build_isolation=True)

def test_build_sdist_pep517_no_isolation(self):
self._test_build_sdist_pep517(build_isolation=False)


class TestConfiguration(unittest.TestCase):

Expand Down

0 comments on commit a06936d

Please sign in to comment.