diff --git a/.appveyor.yml b/.appveyor.yml index 4e53701fc..84e0c7a76 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -48,8 +48,8 @@ install: - "python --version" - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" - # upgrade pip to avoid out-of-date warnings - - "python -m pip install --disable-pip-version-check --user --upgrade pip" + # upgrade pip and setuptools to avoid out-of-date warnings + - "python -m pip install --disable-pip-version-check --user --upgrade pip setuptools" - "python -m pip --version" # install the dependencies to run the tests diff --git a/.travis.yml b/.travis.yml index 25fd9bbeb..0a0265c5e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,9 @@ matrix: - python: 3.4 env: TOXENV=py34 - python: 3.5 - env: TOXENV=py35 + env: + - TOXENV=py35 + - BUILD_DIST=true - python: pypy env: TOXENV=pypy - language: generic diff --git a/.travis/run.sh b/.travis/run.sh index 9ff433cdd..e0b19a8a0 100755 --- a/.travis/run.sh +++ b/.travis/run.sh @@ -17,5 +17,12 @@ if [[ "${TOXENV}" == "jython" ]]; then jython -m pytest || true else source ~/.venv/bin/activate + if [ "$BUILD_DIST" = true ]; then + # Travis by default only clones a 'shallow' repository with --depth=50. + # When building the distribution packages, we use git to determine the + # package version string (via setuptools_scm), hence we need to fetch + # the whole repo, and not just the last 50 commits. + git fetch --unshallow + fi tox fi \ No newline at end of file diff --git a/Lib/fontTools/__init__.py b/Lib/fontTools/__init__.py index ac38eae23..e5dc5d0e8 100644 --- a/Lib/fontTools/__init__.py +++ b/Lib/fontTools/__init__.py @@ -5,6 +5,4 @@ from fontTools.misc.loggingTools import configLogger log = logging.getLogger(__name__) -version = "3.0" - -__all__ = ["version", "log", "configLogger"] +__all__ = ["log", "configLogger"] diff --git a/Lib/fontTools/ttLib/__init__.py b/Lib/fontTools/ttLib/__init__.py index 1a62687ab..fd13f5f97 100644 --- a/Lib/fontTools/ttLib/__init__.py +++ b/Lib/fontTools/ttLib/__init__.py @@ -250,9 +250,13 @@ class TTFont(object): list of tables to dump. The 'skipTables' argument may be a list of tables to skip, but only when the 'tables' argument is false. """ - from fontTools import version + from fontTools.version import __version__ from fontTools.misc import xmlWriter + # only write the MAJOR.MINOR version in the 'ttLibVersion' attribute of + # TTX files' root element (without PATCH or .dev suffixes) + version = ".".join(__version__.split('.')[:2]) + if quiet is not None: deprecateArgument("quiet", "configure logging instead") diff --git a/Lib/fontTools/ttx.py b/Lib/fontTools/ttx.py index 54fb46147..e7c820ebd 100644 --- a/Lib/fontTools/ttx.py +++ b/Lib/fontTools/ttx.py @@ -1,7 +1,7 @@ """\ usage: ttx [options] inputfile1 [... inputfileN] - TTX %s -- From OpenType To XML And Back + TTX -- From OpenType To XML And Back If an input file is a TrueType or OpenType font file, it will be dumped to an TTX file (an XML-based text format). @@ -12,7 +12,8 @@ usage: ttx [options] inputfile1 [... inputfileN] never overwritten. General options: - -h Help: print this message + -h Help: print this message. + --version: show version and exit. -d Specify a directory where the output files are to be created. -o Specify a file to write the output to. A special @@ -93,12 +94,6 @@ import logging log = logging.getLogger(__name__) - -def usage(): - from fontTools import version - print(__doc__ % version) - - numberAddedRE = re.compile("#\d+$") opentypeheaderRE = re.compile('''sfntVersion=['"]OTTO["']''') @@ -144,7 +139,11 @@ class Options(object): for option, value in rawOptions: # general options if option == "-h": - usage() + print(__doc__) + sys.exit(0) + elif option == "--version": + from fontTools.version import __version__ + print(__version__) sys.exit(0) elif option == "-d": if not os.path.isdir(value): @@ -312,7 +311,7 @@ def guessFileType(fileName): def parseOptions(args): rawOptions, files = getopt.getopt(args, "ld:o:fvqht:x:sim:z:baey:", - ['unicodedata=', "recalc-timestamp", 'flavor=', + ['unicodedata=', "recalc-timestamp", 'flavor=', 'version', 'with-zopfli']) options = Options(rawOptions, len(files)) @@ -373,8 +372,7 @@ def main(args=None): try: jobs, options = parseOptions(args) except getopt.GetoptError as e: - usage() - print("ERROR:", e, file=sys.stderr) + print("%s\nERROR: %s" % (__doc__, e), file=sys.stderr) sys.exit(2) configLogger(level=options.logLevel) diff --git a/Lib/fontTools/version.py b/Lib/fontTools/version.py new file mode 100644 index 000000000..4d5a3c0f6 --- /dev/null +++ b/Lib/fontTools/version.py @@ -0,0 +1,4 @@ +try: + __version__ = __import__('pkg_resources').require('fontTools')[0].version +except Exception: + __version__ = 'unknown' diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index afa74cc40..000000000 --- a/MANIFEST.in +++ /dev/null @@ -1,16 +0,0 @@ -include README.md -include LICENSE -include NEWS -include Snippets/*.py -include Snippets/README.md -include Doc/ttx.1 -include MetaTools/*.py -include Lib/fontTools/ttLib/tables/table_API_readme.txt - -include *requirements.txt -include tox.ini -include run-tests.sh - -recursive-include Lib/fontTools testdata/*.ttx testdata/*.otx testdata/*.fea -recursive-include Lib/fontTools testdata/*.lwfn testdata/*.pfa testdata/*.pfb -recursive-include Lib/fontTools testdata/*.xml testdata/*.designspace diff --git a/setup.py b/setup.py index 87026270e..a11f19038 100755 --- a/setup.py +++ b/setup.py @@ -40,7 +40,7 @@ TrueType/OpenType fonts to and from an XML-based format. setup( name="fonttools", - version="3.1.0", + use_scm_version=True, description="Tools to manipulate font files", author="Just van Rossum", author_email="just@letterror.com", @@ -58,6 +58,9 @@ setup( data_files=[ ('share/man/man1', ["Doc/ttx.1"]) ] if sys.platform.startswith('linux') else [], + setup_requires=[ + "setuptools_scm>=1.11.1", + ], entry_points={ 'console_scripts': [ "ttx = fontTools.ttx:main",