[Python-modules-commits] [check-manifest] 01/02: New upstream version 0.36

Sergio Durigan Junior sergiodj-guest at moszumanska.debian.org
Mon Jan 1 00:27:05 UTC 2018


This is an automated email from the git hooks/post-receive script.

sergiodj-guest pushed a commit to branch master
in repository check-manifest.

commit 7d4e97cc1d3e32f32aa8d06b9d088f6f5344289d
Author: Sergio Durigan Junior <sergiodj at sergiodj.net>
Date:   Thu Dec 28 01:47:06 2017 -0500

    New upstream version 0.36
---
 .coveragerc       |    6 +
 .gitignore        |    9 +
 .travis.yml       |   24 +
 CHANGES.rst       |  322 ++++++++++++
 LICENSE.rst       |   20 +
 MANIFEST.in       |    8 +
 Makefile          |   72 +++
 README.rst        |  125 +++++
 appveyor.yml      |   27 +
 check_manifest.py |  977 ++++++++++++++++++++++++++++++++++
 setup.cfg         |   24 +
 setup.py          |   77 +++
 tests.py          | 1500 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 tox.ini           |   29 ++
 14 files changed, 3220 insertions(+)

diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..ac30d67
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,6 @@
+[report]
+exclude_lines =
+    pragma: nocover
+    except ImportError:
+    if __name__ == '__main__':
+    if sys.platform == 'darwin':
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..f08f3c5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+*.pyc
+__pycache__/
+.tox/
+*.egg-info/
+dist/
+tmp/
+.coverage
+build/
+tags
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..99616e3
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,24 @@
+language: python
+sudo: false
+python:
+    - 2.7
+    - 3.3
+    - 3.4
+    - 3.5
+    - 3.6
+    - pypy
+    - pypy3
+env:
+    - FORCE_TEST_VCS=bzr
+    - FORCE_TEST_VCS=git
+    - FORCE_TEST_VCS=hg
+    - FORCE_TEST_VCS=svn
+install:
+    - pip install coverage coveralls mock
+script:
+    - SKIP_NO_TESTS=1 coverage run --source=check_manifest setup.py test -q
+    - coverage run --source=check_manifest --append check_manifest.py
+after_script:
+    - coveralls
+notifications:
+    email: false
diff --git a/CHANGES.rst b/CHANGES.rst
new file mode 100644
index 0000000..e0e6711
--- /dev/null
+++ b/CHANGES.rst
@@ -0,0 +1,322 @@
+Changelog
+=========
+
+
+0.36 (2017-11-21)
+-----------------
+
+- Handle empty VCS repositories more gracefully
+  (`#84 <https://github.com/mgedmin/check-manifest/issues/84>`__).
+
+
+0.35 (2017-01-30)
+-----------------
+
+- Python 3.6 support.
+
+
+0.34 (2016-09-14)
+-----------------
+
+- Fix WindowsError due to presence of read-only files
+  (`#74 <https://github.com/mgedmin/check-manifest/issues/74>`__).
+
+
+0.33 (2016-08-29)
+-----------------
+
+- Fix WindowsError due to git submodules in subdirectories
+  (`#73 <https://github.com/mgedmin/check-manifest/pull/73>`__).
+  Contributed by Loren Gordon.
+
+
+0.32 (2016-08-16)
+-----------------
+
+* New config/command line option to ignore bad ideas (ignore-bad-ideas)
+  (`issue #67 <https://github.com/mgedmin/check-manifest/issues/67>`__).
+  Contributed by Brecht Machiels.
+
+* Files named ``.hgsigs`` are ignored by default.  Contributed by Jakub Wilk.
+
+
+0.31 (2016-01-28)
+-----------------
+
+- Drop Python 3.2 support.
+
+- Ignore commented-out lines in MANIFEST.in
+  (`issue #66 <https://github.com/mgedmin/check-manifest/issues/66>`__).
+
+
+0.30 (2015-12-10)
+-----------------
+
+* Support git submodules
+  (`issue #61 <https://github.com/mgedmin/check-manifest/issues/61>`__).
+
+* Revert the zc.buildout support hack from 0.26 because it causes breakage
+  (`issue #56 <https://github.com/mgedmin/check-manifest/issues/56>`__).
+
+* Improve non-ASCII filename handling with Bazaar on Windows.
+
+
+0.29 (2015-11-21)
+-----------------
+
+* Fix --python with just a command name, to be found in path (`issue #57
+  <https://github.com/mgedmin/check-manifest/issues/57>`__).
+
+
+0.28 (2015-11-11)
+-----------------
+
+* Fix detection of git repositories when .git is a file and not a directory (`#53
+  <https://github.com/mgedmin/check-manifest/pull/53>`__).  One situation
+  where this occurs is when the project is checked out as a git submodule.
+
+* Apply ignore patterns in subdirectories too (`#54
+  <https://github.com/mgedmin/check-manifest/issues/54>`__).
+
+
+0.27 (2015-11-02)
+-----------------
+
+* Fix utter breakage on Windows, introduced in 0.26 (`issue #52
+  <https://github.com/mgedmin/check-manifest/issues/52>`__).
+  (The bug -- clearing the environment unnecessarily -- could probably
+  also cause locale-related problems on other OSes.)
+
+
+0.26 (2015-10-30)
+-----------------
+
+* Do not complain about missing ``.gitattributes`` file (`PR #50
+  <https://github.com/mgedmin/check-manifest/pull/50>`__).
+
+* Normalize unicode representation and case of filenames. (`issue #47
+  <https://github.com/mgedmin/check-manifest/issues/47>`__).
+
+* Support installation via zc.buildout better (`issue #35
+  <https://github.com/mgedmin/check-manifest/issues/35>`__).
+
+* Drop Python 2.6 support because one of our test dependencies (mock) dropped
+  it.  This also means we no longer use environment markers.
+
+
+0.25 (2015-05-27)
+-----------------
+
+* Stop dynamic computation of install_requires in setup.py: this doesn't work
+  well in the presence of the pip 7 wheel cache.  Use PEP-426 environment
+  markers instead (this means we now require setuptools >= 0.7, and pip >= 6.0,
+  and wheel >= 0.24).
+
+
+0.24 (2015-03-26)
+-----------------
+
+* Make sure ``setup.py`` not being added to the VCS doesn't cause
+  hard-to-understand errors (`issue #46
+  <https://github.com/mgedmin/check-manifest/issues/46>`__).
+
+
+0.23 (2015-02-12)
+-----------------
+
+* More reliable svn status parsing; now handles svn externals (`issue #45
+  <https://github.com/mgedmin/check-manifest/issues/45>`__).
+
+* The test suite now skips tests for version control systems that aren't
+  installed (`issue #42
+  <https://github.com/mgedmin/check-manifest/issues/42>`__).
+
+
+0.22 (2014-12-23)
+-----------------
+
+* More terse output by default; use the new ``-v`` (``--verbose``) flag
+  to see all the details.
+
+* Warn the user if MANIFEST.in is missing  (`issue #31
+  <https://github.com/mgedmin/check-manifest/issues/31>`__).
+
+* Fix IOError when files listed under version control are missing (`issue #32
+  <https://github.com/mgedmin/check-manifest/issues/32>`__).
+
+* Improved wording of the match/do not match messages (`issue #34
+  <https://github.com/mgedmin/check-manifest/issues/34>`__).
+
+* Handle a relative --python path (`issue #36
+  <https://github.com/mgedmin/check-manifest/issues/36>`__).
+
+* Warn about leading and trailing slashes in MANIFEST.in (`issue #37
+  <https://github.com/mgedmin/check-manifest/issues/37>`__).
+
+* Ignore .travis.yml by default (`issue #39
+  <https://github.com/mgedmin/check-manifest/issues/39>`__).
+
+* Suggest a rule for Makefile found deeper in the source tree.
+
+
+0.21 (2014-06-13)
+-----------------
+
+* Don't drop setup.cfg when copying version-controlled files into a clean
+  temporary directory (`issue #29
+  <https://github.com/mgedmin/check-manifest/issues/29>`__).
+
+
+0.20 (2014-05-14)
+-----------------
+
+* Restore warning about files included in the sdist but not added to the
+  version control system (`issue #27
+  <https://github.com/mgedmin/check-manifest/issues/27>`__).
+
+* Fix ``check-manifest relative/pathname`` (`issue #28
+  <https://github.com/mgedmin/check-manifest/issues/28>`__).
+
+
+0.19 (2014-02-09)
+-----------------
+
+* More correct MANIFEST.in parsing for exclusion rules.
+* Some effort was expended towards Windows compatibility.
+* Handles non-ASCII filenames, as long as they're valid in your locale
+  (`issue #23 <https://github.com/mgedmin/check-manifest/issues/23>`__,
+  `#25 <https://github.com/mgedmin/check-manifest/issues/23>`__).
+
+
+0.18 (2014-01-30)
+-----------------
+
+* Friendlier error message when an external command cannot be found
+  (`issue #21 <https://github.com/mgedmin/check-manifest/issues/21>`__).
+* Add suggestion pattern for `.coveragerc`.
+* Python 2.6 support
+  (`issue #22 <https://github.com/mgedmin/check-manifest/issues/22>`__).
+
+
+0.17 (2013-10-10)
+-----------------
+
+* Read the existing MANIFEST.in file for files to ignore
+  (`issue #19 <https://github.com/mgedmin/check-manifest/issues/19>`__).
+
+
+0.16 (2013-10-01)
+-----------------
+
+* Fix Subversion status parsing in the presence of svn usernames longer than 12
+  characters (`issue #18 <https://github.com/mgedmin/check-manifest/issues/18>`__).
+
+
+0.15 (2013-09-20)
+-----------------
+
+* Normalize the paths of all files, avoiding some duplicate misses of
+  directories.  (`issue #16 <https://github.com/mgedmin/check-manifest/issues/16>`__).
+  [maurits]
+
+
+0.14 (2013-08-28)
+-----------------
+
+* Supports packages that do not live in the root of a version control
+  repository (`issue #15 <https://github.com/mgedmin/check-manifest/issues/15>`__).
+
+* More reliable svn support: detect files that have been added but not
+  committed (or committed but not updated).
+
+* Licence changed from GPL (v2 or later) to MIT
+  (`issue #12 <https://github.com/mgedmin/check-manifest/issues/12>`__).
+
+
+0.13 (2013-07-31)
+-----------------
+
+* New command line option: --ignore
+  (`issue #11 <https://github.com/mgedmin/check-manifest/issues/11>`__).
+  Contributed by Steven Myint.
+
+* New command line option: -p, --python.  Defaults to the Python you used to
+  run check-manifest.  Fixes issues with packages that require Python 3 to run
+  setup.py (`issue #13 <https://github.com/mgedmin/check-manifest/issues/13>`__).
+
+
+0.12 (2013-05-15)
+-----------------
+
+* Add suggestion pattern for `Makefile`.
+
+* More generic suggestion patterns, should cover almost anything.
+
+* zest.releaser_ integration: skip check-release for non-Python packages
+  (`issue #9 <https://github.com/mgedmin/check-manifest/issues/9>`__).
+
+
+0.11 (2013-03-20)
+-----------------
+
+* Make sure ``MANIFEST.in`` is not ignored even if it hasn't been added to the
+  VCS yet (`issue #7 <https://github.com/mgedmin/check-manifest/issues/7>`__).
+
+
+0.10 (2013-03-17)
+-----------------
+
+* ``check-manifest --version`` now prints the version number.
+
+* Don't apologize for not adding rules for directories (especially after adding
+  rules that include files inside that directory).
+
+* Python 3 support contributed by Steven Myint.
+
+* Default ignore patterns can be configured in ``setup.cfg``
+  (`issue #3 <https://github.com/mgedmin/check-manifest/issues/3>`_).
+
+
+0.9 (2013-03-06)
+----------------
+
+* Add suggestion pattern for `.travis.yml`.
+
+* When check-manifest -u (or -c) doesn't know how to write a rule matching a
+  particular file, it now apologizes explicitly.
+
+* Copy the source tree to a temporary directory before running python setup.py
+  sdist to avoid side effects from setuptools plugins or stale
+  \*.egg-info/SOURCES.txt files
+  (`issue #1 <https://github.com/mgedmin/check-manifest/issues/1>`_).
+
+* Warn if `*.egg-info` or `*.mo` is actually checked into the VCS.
+
+* Don't complain if `*.mo` files are present in the sdist but not in the VCS
+  (`issue #2 <https://github.com/mgedmin/check-manifest/issues/2>`_).
+
+
+0.8 (2013-03-06)
+----------------
+
+* Entry point for zest.releaser_.  If you install both zest.releaser and
+  check-manifest, you will be asked if you want to check your manifest during
+  ``fullrelease``.
+
+.. _zest.releaser: https://pypi.python.org/pypi/zest.releaser
+
+
+0.7 (2013-03-05)
+----------------
+
+* First release available from the Python Package Index.
+
+* Moved from https://gist.github.com/4277075
+  to https://github.com/mgedmin/check-manifest
+
+* Added README.rst, CHANGES.rst, setup.py, tox.ini (but no real tests yet),
+  MANIFEST.in, and a Makefile.
+
+* Fixed a bug in error reporting (when setup.py failed, the user would get
+  `TypeError: descriptor '__init__' requires an 'exceptions.Exception' object
+  but received a 'str'`).
diff --git a/LICENSE.rst b/LICENSE.rst
new file mode 100644
index 0000000..6d8cc43
--- /dev/null
+++ b/LICENSE.rst
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2013 Marius Gedminas and contributors
+
+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.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..c29ebc0
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,8 @@
+include *.rst
+include *.py
+include tox.ini
+include Makefile
+include .gitignore
+include .travis.yml
+include appveyor.yml
+include .coveragerc
diff --git a/Makefile b/Makefile
new file mode 100755
index 0000000..7ed36fb
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,72 @@
+PYTHON = python
+FILE_WITH_VERSION = check_manifest.py
+FILE_WITH_CHANGELOG = CHANGES.rst
+
+.PHONY: all
+all:
+	@echo "Nothing to build.  Try 'make test' perhaps?"
+
+.PHONY: check test
+test:
+	detox
+check:
+	SKIP_NO_TESTS=1 tox
+
+.PHONY: coverage
+coverage:
+	tox -e coverage
+
+.PHONY: dist
+dist:
+	$(PYTHON) setup.py -q sdist bdist_wheel
+
+.PHONY: distcheck
+distcheck:
+	$(PYTHON) check_manifest.py
+	# Bit of a chicken-and-egg here, but if the tree is unclean, make
+	# distcheck will fail.
+	@test -z "`git status -s 2>&1`" || { echo; echo "Your working tree is not clean" 1>&2; git status; exit 1; }
+	make dist
+	pkg_and_version=`$(PYTHON) setup.py --name`-`$(PYTHON) setup.py --version` && \
+	rm -rf tmp && \
+	mkdir tmp && \
+	git archive --format=tar --prefix=tmp/tree/ HEAD | tar -xf - && \
+	cd tmp && \
+	tar xvzf ../dist/$$pkg_and_version.tar.gz && \
+	diff -ur $$pkg_and_version tree -x PKG-INFO -x setup.cfg -x '*.egg-info' && \
+	cd $$pkg_and_version && \
+	make dist check && \
+	cd .. && \
+	mkdir one two && \
+	cd one && \
+	tar xvzf ../../dist/$$pkg_and_version.tar.gz && \
+	cd ../two/ && \
+	tar xvzf ../$$pkg_and_version/dist/$$pkg_and_version.tar.gz && \
+	cd .. && \
+	diff -ur one two -x SOURCES.txt && \
+	cd .. && \
+	rm -rf tmp && \
+	echo "sdist seems to be ok"
+
+.PHONY: releasechecklist
+releasechecklist:
+	@$(PYTHON) setup.py --version | grep -qv dev || { \
+	    echo "Please remove the 'dev' suffix from the version number in $(FILE_WITH_VERSION)"; exit 1; }
+	@$(PYTHON) setup.py --long-description | rst2html --exit-status=2 > /dev/null
+	@ver_and_date="`$(PYTHON) setup.py --version` (`date +%Y-%m-%d`)" && \
+	    grep -q "^$$ver_and_date$$" $(FILE_WITH_CHANGELOG) || { \
+	        echo "$(FILE_WITH_CHANGELOG) has no entry for $$ver_and_date"; exit 1; }
+	make distcheck
+
+.PHONY: release
+release: releasechecklist
+	# I'm chicken so I won't actually do these things yet
+	@echo "Please run"
+	@echo
+	@echo "  rm -rf dist && $(PYTHON) setup.py -q sdist bdist_wheel && twine upload dist/* && git tag `$(PYTHON) setup.py --version`"
+	@echo
+	@echo "Please increment the version number in $(FILE_WITH_VERSION)"
+	@echo "and add a new empty entry at the top of the changelog in $(FILE_WITH_CHANGELOG), then"
+	@echo
+	@echo '  git commit -a -m "Post-release version bump" && git push && git push --tags'
+	@echo
diff --git a/README.rst b/README.rst
new file mode 100644
index 0000000..633977d
--- /dev/null
+++ b/README.rst
@@ -0,0 +1,125 @@
+check-manifest
+==============
+
+|buildstatus|_ |appveyor|_ |coverage|_
+
+Are you a Python developer?  Have you uploaded packages to the Python Package
+Index?  Have you accidentally uploaded *broken* packages with some files
+missing?  If so, check-manifest is for you.
+
+Quick start
+-----------
+
+::
+
+    $ pip install check-manifest
+
+    $ cd ~/src/mygreatpackage
+    $ check-manifest
+
+You can ask the script to help you update your MANIFEST.in::
+
+    $ check-manifest -u -v
+    listing source files under version control: 6 files and directories
+    building an sdist: check-manifest-0.7.tar.gz: 4 files and directories
+    lists of files in version control and sdist do not match!
+    missing from sdist:
+      tests.py
+      tox.ini
+    suggested MANIFEST.in rules:
+      include *.py
+      include tox.ini
+    updating MANIFEST.in
+
+    $ cat MANIFEST.in
+    include *.rst
+
+    # added by check_manifest.py
+    include *.py
+    include tox.ini
+
+
+Command-line reference
+----------------------
+
+::
+
+    $ check-manifest --help
+    usage: check-manifest [-h] [--version] [-v] [-c] [-u] [-p PYTHON]
+                          [--ignore patterns]
+                          [source_tree]
+
+    Check a Python MANIFEST.in file for completeness
+
+    positional arguments:
+      source_tree           location for the source tree (default: .)
+
+    optional arguments:
+      -h, --help            show this help message and exit
+      --version             show program's version number and exit
+      -v, --verbose         more verbose output (default: False)
+      -c, --create          create a MANIFEST.in if missing (default: False)
+      -u, --update          append suggestions to MANIFEST.in (implies --create)
+                            (default: False)
+      -p PYTHON, --python PYTHON
+                            use this Python interpreter for running setup.py sdist
+                            (default: /home/mg/.venv/bin/python)
+      --ignore patterns     ignore files/directories matching these comma-
+                            separated patterns (default: None)
+      --ignore-bad-ideas patterns
+                            ignore bad idea files/directories matching these
+                            comma-separated patterns (default: [])
+
+
+Configuration
+-------------
+
+You can tell check-manifest to ignore certain file patterns by adding a
+``check-manifest`` section to your package's ``setup.cfg``.  Example::
+
+    [check-manifest]
+    ignore =
+        .travis.yml
+
+The following options are recognized:
+
+ignore
+    A list of newline separated filename patterns that will be ignored by
+    check-manifest.  Use this if you want to keep files in your version
+    control system that shouldn't be included in your source distributions.
+    The default ignore list is ::
+
+        PKG-INFO
+        *.egg-info
+        *.egg-info/*
+        setup.cfg
+        .hgtags
+        .hgsigs
+        .hgignore
+        .gitignore
+        .bzrignore
+        .gitattributes
+        .travis.yml
+        Jenkinsfile
+        *.mo
+
+ignore-default-rules
+    If set to ``true``, your ``ignore`` patterns will replace the default
+    ignore list instead of adding to it.
+
+ignore-bad-ideas
+    A list of newline separated filename patterns that will be ignored by
+    check-manifest's generated files check.  Use this if you want to keep
+    generated files in your version control system, even though it is generally
+    a bad idea.
+
+
+.. |buildstatus| image:: https://api.travis-ci.org/mgedmin/check-manifest.svg?branch=master
+.. _buildstatus: https://travis-ci.org/mgedmin/check-manifest
+
+.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/github/mgedmin/check-manifest?branch=master&svg=true
+.. _appveyor: https://ci.appveyor.com/project/mgedmin/check-manifest
+
+.. |coverage| image:: https://coveralls.io/repos/mgedmin/check-manifest/badge.svg?branch=master
+.. _coverage: https://coveralls.io/r/mgedmin/check-manifest
+
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..0a8569c
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,27 @@
+version: build-{build}-{branch}
+
+environment:
+  matrix:
+    # https://www.appveyor.com/docs/installed-software#python lists available
+    # versions
+    - PYTHON: "C:\\Python27"
+    - PYTHON: "C:\\Python33"
+    - PYTHON: "C:\\Python34"
+    - PYTHON: "C:\\Python35"
+    - PYTHON: "C:\\Python36"
+
+init:
+  - "echo %PYTHON%"
+
+install:
+  - "set PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
+  - python --version
+  - pip install tox
+  - choco install bzr
+  - "set PATH=C:\\Program Files (x86)\\Bazaar;%PATH%"
+  - bzr --version
+
+build: off
+
+test_script:
+  - tox -e py
diff --git a/check_manifest.py b/check_manifest.py
new file mode 100755
index 0000000..b49b9c3
--- /dev/null
+++ b/check_manifest.py
@@ -0,0 +1,977 @@
+#!/usr/bin/env python
+"""Check the MANIFEST.in file in a Python source package for completeness.
+
+This script works by building a source distribution archive (by running
+setup.py sdist), then checking the file list in the archive against the
+file list in version control (Subversion, Git, Mercurial, Bazaar are
+supported).
+
+Since the first check can fail to catch missing MANIFEST.in entries when
+you've got the right setuptools version control system support plugins
+installed, the script copies all the versioned files into a temporary
+directory and building the source distribution again.  This also avoids issues
+with stale egg-info/SOURCES.txt files that may cause files not mentioned in
+MANIFEST.in to be included nevertheless.
+"""
+from __future__ import print_function
+
+import argparse
+import codecs
+import fnmatch
+import locale
+import os
+import posixpath
+import re
+import shutil
+import stat
+import subprocess
+import sys
+import tarfile
+import tempfile
+import unicodedata
+import zipfile
+from distutils.filelist import glob_to_re
+from contextlib import contextmanager, closing
+from distutils.text_file import TextFile
+from xml.etree import cElementTree as ET
+
+try:
+    import ConfigParser
+except ImportError:
+    # Python 3.x
+    import configparser as ConfigParser
+
+
+__version__ = '0.36'
+__author__ = 'Marius Gedminas <marius at gedmin.as>'
+__licence__ = 'MIT'
+__url__ = 'https://github.com/mgedmin/check-manifest'
+
+
+class Failure(Exception):
+    """An expected failure (as opposed to a bug in this script)."""
+
+
+#
+# User interface
+#
+
+VERBOSE = False
+
+_to_be_continued = False
+def _check_tbc():
+    global _to_be_continued
+    if _to_be_continued:
+        print()
+        _to_be_continued = False
+
+
+def info(message):
+    _check_tbc()
+    print(message)
+
+
+def info_begin(message):
+    if not VERBOSE:
+        return
+    _check_tbc()
+    sys.stdout.write(message)
+    sys.stdout.flush()
+    global _to_be_continued
+    _to_be_continued = True
+
+
+def info_continue(message):
+    if not VERBOSE:
+        return
+    sys.stdout.write(message)
+    sys.stdout.flush()
+    global _to_be_continued
+    _to_be_continued = True
+
+
+def info_end(message):
+    if not VERBOSE:
+        return
+    print(message)
+    global _to_be_continued
+    _to_be_continued = False
+
+
+def error(message):
+    _check_tbc()
+    print(message, file=sys.stderr)
+
+
+def warning(message):
+    _check_tbc()
+    print(message, file=sys.stderr)
+
+
+def format_list(list_of_strings):
+    return "\n".join("  " + s for s in list_of_strings)
+
+
+def format_missing(missing_from_a, missing_from_b, name_a, name_b):
+    res = []
+    if missing_from_a:
+        res.append("missing from %s:\n%s"
+                   % (name_a, format_list(sorted(missing_from_a))))
+    if missing_from_b:
+        res.append("missing from %s:\n%s"
+                   % (name_b, format_list(sorted(missing_from_b))))
+    return '\n'.join(res)
+
+
+#
+# Filesystem/OS utilities
+#
+
+class CommandFailed(Failure):
+    def __init__(self, command, status, output):
+        Failure.__init__(self, "%s failed (status %s):\n%s" % (
+                               command, status, output))
+
+
+def run(command, encoding=None, decode=True, cwd=None):
+    """Run a command [cmd, arg1, arg2, ...].
+
+    Returns the output (stdout + stderr).
+
+    Raises CommandFailed in cases of error.
+    """
+    if not encoding:
+        encoding = locale.getpreferredencoding()
+    try:
+        with open(os.devnull, 'rb') as devnull:
+            pipe = subprocess.Popen(command, stdin=devnull,
+                                    stdout=subprocess.PIPE,
+                                    stderr=subprocess.STDOUT, cwd=cwd)
+    except OSError as e:
+        raise Failure("could not run %s: %s" % (command, e))
+    output = pipe.communicate()[0]
+    if decode:
+        output = output.decode(encoding)
+    status = pipe.wait()
+    if status != 0:
+        raise CommandFailed(command, status, output)
+    return output
+
+
+ at contextmanager
+def cd(directory):
+    """Change the current working directory, temporarily.
+
+    Use as a context manager: with cd(d): ...
+    """
+    old_dir = os.getcwd()
+    try:
+        os.chdir(directory)
+        yield
+    finally:
+        os.chdir(old_dir)
+
+
+ at contextmanager
+def mkdtemp(hint=''):
+    """Create a temporary directory, then clean it up.
+
+    Use as a context manager: with mkdtemp('-purpose'): ...
+    """
+    dirname = tempfile.mkdtemp(prefix='check-manifest-', suffix=hint)
+    try:
+        yield dirname
+    finally:
+        rmtree(dirname)
+
+
+def chmod_plus(path, add_bits=stat.S_IWUSR):
+    """Change a file's mode by adding a few bits.
+
+    Like chmod +<bits> <path> in a Unix shell.
+    """
+    try:
+        os.chmod(path, stat.S_IMODE(os.stat(path).st_mode) | add_bits)
+    except OSError:  # pragma: nocover
+        pass  # well, we tried
+
+
+def rmtree(path):
+    """A version of rmtree that can deal with read-only files and directories.
+
+    Needed because the stock shutil.rmtree() fails with an access error
+    when there are read-only files in the directory on Windows, or when the
+    directory itself is read-only on Unix.
+    """
+    def onerror(func, path, exc_info):
+        # Did you know what on Python 3.3 on Windows os.remove() and
+        # os.unlink() are distinct functions?
+        if func is os.remove or func is os.unlink or func is os.rmdir:
+            if sys.platform != 'win32':
+                chmod_plus(os.path.dirname(path), stat.S_IWUSR | stat.S_IXUSR)
+            chmod_plus(path)
+            func(path)
+        else:
+            raise
+    shutil.rmtree(path, onerror=onerror)
+
+
+def copy_files(filelist, destdir):
+    """Copy a list of files to destdir, preserving directory structure.
+
+    File names should be relative to the current working directory.
+    """
+    for filename in filelist:
+        destfile = os.path.join(destdir, filename)
+        # filename should not be absolute, but let's double-check
+        assert destfile.startswith(destdir + os.path.sep)
+        destfiledir = os.path.dirname(destfile)
+        if not os.path.isdir(destfiledir):
+            os.makedirs(destfiledir)
+        if os.path.isdir(filename):
+            os.mkdir(destfile)
+        else:
+            shutil.copy2(filename, destfile)
+
+
+def get_one_file_in(dirname):
+    """Return the pathname of the one file in a directory.
+
+    Raises if the directory has no files or more than one file.
+    """
+    files = os.listdir(dirname)
+    if len(files) > 1:
+        raise Failure('More than one file exists in %s:\n%s' %
+                      (dirname, '\n'.join(sorted(files))))
+    elif not files:
+        raise Failure('No files found in %s' % dirname)
+    return os.path.join(dirname, files[0])
+
+
+def unicodify(filename):
+    """Make sure filename is Unicode.
+
+    Because the tarfile module on Python 2 doesn't return Unicode.
+    """
+    if isinstance(filename, bytes):
+        return filename.decode(locale.getpreferredencoding())
+    else:
+        return filename
+
+
+def get_archive_file_list(archive_filename):
+    """Return the list of files in an archive.
+
+    Supports .tar.gz and .zip.
+    """
+    if archive_filename.endswith('.zip'):
+        with closing(zipfile.ZipFile(archive_filename)) as zf:
+            return add_directories(zf.namelist())
+    elif archive_filename.endswith(('.tar.gz', '.tar.bz2', '.tar')):
+        with closing(tarfile.open(archive_filename)) as tf:
+            return add_directories(list(map(unicodify, tf.getnames())))
+    else:
+        ext = os.path.splitext(archive_filename)[-1]
+        raise Failure('Unrecognized archive type: %s' % ext)
+
+
+def strip_toplevel_name(filelist):
+    """Strip toplevel name from a file list.
+
+        >>> strip_toplevel_name(['a', 'a/b', 'a/c', 'a/c/d'])
+        ['b', 'c', 'c/d']
+
+        >>> strip_toplevel_name(['a/b', 'a/c', 'a/c/d'])
+        ['b', 'c', 'c/d']
+
+    """
+    if not filelist:
+        return filelist
+    prefix = filelist[0]
+    if '/' in prefix:
+        prefix = prefix.partition('/')[0] + '/'
+        names = filelist
+    else:
+        prefix = prefix + '/'
+        names = filelist[1:]
+    for name in names:
+        if not name.startswith(prefix):
+            raise Failure("File doesn't have the common prefix (%s): %s"
+                          % (name, prefix))
+    return [name[len(prefix):] for name in names]
+
+
+def add_prefix_to_each(prefix, filelist):
+    """Add a prefix to each name in a file list.
... 2326 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/check-manifest.git



More information about the Python-modules-commits mailing list