Browse files

Lots of tweaks for broader Python support (2.5+)

Now including a base `tox` config file to run the tests in 2.5-3.3
virtualenvs. All tests currently pass in all listed versions.
  • Loading branch information...
1 parent 7fac063 commit 7307d0b24d56678673384b807c996e104f92ee53 @jimr committed Dec 22, 2012
Showing with 192 additions and 109 deletions.
  1. +2 −0 .gitignore
  2. +0 −13 LICENSE
  3. +19 −0 LICENSE.txt
  4. +2 −0 MANIFEST.in
  5. +0 −87 README.md
  6. +94 −0 README.rst
  7. +7 −1 projectmill/__init__.py
  8. +13 −3 projectmill/utils.py
  9. +2 −0 requirements-2.5.txt
  10. +2 −1 requirements.txt
  11. +3 −2 setup.py
  12. +2 −0 tests/test_merge_config.py
  13. +7 −1 tests/test_process_mml.py
  14. +7 −1 tests/test_process_mss.py
  15. +32 −0 tox.ini
View
2 .gitignore
@@ -6,3 +6,5 @@ env
*.swp
*.egg-info
.DS_Store
+.tox
+tox-local.ini
View
13 LICENSE
@@ -1,13 +0,0 @@
-Copyright (c) 2012, James Rutherford <james.rutherford@maplecroft.com>
-
-Permission to use, copy, modify, and/or distribute this software for any
-purpose with or without fee is hereby granted, provided that the above
-copyright notice and this permission notice appear in all copies.
-
-THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
-REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
-FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
-INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
-LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
-OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
-PERFORMANCE OF THIS SOFTWARE.
View
19 LICENSE.txt
@@ -0,0 +1,19 @@
+Copyright (c) 2012 James Rutherford
+
+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.
View
2 MANIFEST.in
@@ -0,0 +1,2 @@
+include *.rst
+include *.txt
View
87 README.md
@@ -1,87 +0,0 @@
-Py-ProjectMill
-==============
-
-Python port of https://github.com/mapbox/projectmill
-
-Currently only support `--mill` and `--render`.
-
-The only Python requirement so far are `testy` and `nose` (for running tests).
-To run tests, first `pip install -r requirements.txt` and then just run `nosetests`.
-
-The remainder of the documentation is adapted from the original project.
-
-- - -
-
-Need to generate a bunch of TileMill projects that are nearly identical and
-then render them all out? What to script that? We gotcha covered.
-
-Usage: `projectmill <command> [options]`
-
-Example: `projectmill --mill -c config.example.json -t ../tilemill/`
-
-## Installation
-
-Install with `pip install -e .` or `python setup.py install`.
-If you're using Python 2.7, there are no dependencies unless you want to run the tests.
-If you're using Python 2.6, 3.0, or 3.1, you will need to `pip install -r requirements-X.Y.txt` (2.6 / 3.0 / 3.1 don't include `argparse`, which is required).
-
-Not yet tested with 2.5 or 3.x, but it ought to work with both.
-
-## Configuration
-
-Configuration is expected as a json file which contains an array as the root
-object. See `config.example.json` for an example. Each element in the array
-should be an object which can have the following keys:
-
-`source` REQUIRED The source project, generally the name of folder it
- lives in.
-
-`destination` REQUIRED The destination project name.
-
-`mml` A json snippet which will be merged on top of the project's mml
- file. To clear out an option set it to 'null'
-
-`cartoVars` A json object containing key value pairs which can be use to
- override variables in in carto stylesheets.
-
-`MBmeta` MBTiles: A json object containing key value pairs which will be added to
- a rendered MBtiles export.
-
-Additionally, the following options will be passed to TileMill's export commnd
-
-`format` Export format (png|pdf|svg|mbtiles). (Default: undefined)
-
-`bbox` Array containing coordinates of bounding box to export. (Default: undefined)
-
-`minzoom` MBTiles: minimum zoom level to export. (Default: undefined)
-
-`maxzoom` MBTiles: maximum zoom level to export. (Default: undefined)
-
-`width` Image: image width in pixels. (Default: 400)
-
-`height` Image: image height in pixels. (Default: 400)
-
-`bufferSize` Mapnik render buffer size. (Default: 128)
-
-
-## Commands
-
-ProjectMill accepts the following commands. They can be issued either
-individually or together.
-
-`--mill` Generates new tilemill projects based on configuration.
-
-`--render` Renders projects that are present in configuration and have been milled.
-
-`--upload` Uploads projects that are present in configuration and have been rendered.
-
-
-## Options
-
--t Path to the TileMill install
-
--c specify a configuration file. (Defaults: `./config.json`)
-
--p Path to TileMill project folder. (Defaults: `~/Documents/Mapbox`)
-
--f Replace existing projects (together with `mill`) or existing projects and exports (together with `render`).
View
94 README.rst
@@ -0,0 +1,94 @@
+==============
+Py-ProjectMill
+==============
+
+Python port of https://github.com/mapbox/projectmill
+
+Currently only support ``--mill`` and ``--render``.
+
+The only Python requirement so far are ``testy`` and ``nose`` (for running tests).
+To run tests, first ``pip install -r requirements.txt`` and then just run ``nosetests``.
+
+The remainder of the documentation is adapted from the original project.
+
+----
+
+Need to generate a bunch of TileMill projects that are nearly identical and
+then render them all out? What to script that? We gotcha covered.
+
+Usage: ``projectmill <command> [options]``
+
+Example: ``projectmill --mill -c config.example.json -t ../tilemill/``
+
+Installation
+============
+
+Install with ``pip install -e .`` or ``python setup.py install``.
+If you're using Python 2.7, there are no dependencies unless you want to run the tests.
+If you're using Python 2.6, 3.0, or 3.1, you will need to ``pip install -r requirements-X.Y.txt`` (2.6 / 3.0 / 3.1 don't include ``argparse``, which is required).
+
+Not yet tested with 2.5 or 3.x, but it ought to work with both.
+
+Configuration
+=============
+
+Configuration is expected as a json file which contains an array as the root
+object. See ``config.example.json`` for an example. Each element in the array
+should be an object which can have the following keys::
+
+ source REQUIRED The source project, generally the name of folder it
+ lives in.
+
+ destination REQUIRED The destination project name.
+
+ mml A json snippet which will be merged on top of the project's mml
+ file. To clear out an option set it to 'null'
+
+ cartoVars A json object containing key value pairs which can be use to
+ override variables in in carto stylesheets.
+
+ MBmeta MBTiles: A json object containing key value pairs which will be added to
+ a rendered MBtiles export.
+
+ Additionally, the following options will be passed to TileMill's export commnd
+
+ format Export format (png|pdf|svg|mbtiles). (Default: undefined)
+
+ bbox Array containing coordinates of bounding box to export. (Default: undefined)
+
+ minzoom MBTiles: minimum zoom level to export. (Default: undefined)
+
+ maxzoom MBTiles: maximum zoom level to export. (Default: undefined)
+
+ width Image: image width in pixels. (Default: 400)
+
+ height Image: image height in pixels. (Default: 400)
+
+ bufferSize Mapnik render buffer size. (Default: 128)
+
+
+Commands
+========
+
+ProjectMill accepts the following commands. They can be issued either
+individually or together::
+
+ --mill Generates new tilemill projects based on configuration.
+
+ --render Renders projects that are present in configuration and have been milled.
+
+ --upload Uploads projects that are present in configuration and have been rendered.
+
+
+Options
+=======
+
+We also accept the following options::
+
+ -t Path to the TileMill install
+
+ -c specify a configuration file. (Defaults: ./config.json)
+
+ -p Path to TileMill project folder. (Defaults: ~/Documents/Mapbox)
+
+ -f Replace existing projects (together with mill) or existing projects and exports (together with render).
View
8 projectmill/__init__.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@@ -9,6 +10,8 @@
"""
+from __future__ import with_statement
+
__title__ = 'projectmill'
__version__ = '0.1'
__description__ = 'Python port of https://github.com/mapbox/projectmill'
@@ -18,9 +21,12 @@
__license__ = 'ISC'
__copyright__ = 'Copyright 2012 James Rutherford'
+try:
+ import json
+except ImportError:
+ import simplejson as json
import argparse
-import json
import logging
import os
import shutil
View
16 projectmill/utils.py
@@ -1,14 +1,22 @@
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import with_statement
+
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
import codecs
import copy
-import json
import logging
import os
import re
import shutil
import sqlite3
import subprocess
+import sys
import types
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
@@ -115,7 +123,8 @@ def mill(config):
else:
shutil.copytree(sourcefile, destfile)
- except Exception as ex:
+ except Exception:
+ _, ex, _ = sys.exc_info()
log.exception(
'Error processing project: %s (%s)' %
(config.get('destination'), ex)
@@ -154,7 +163,8 @@ def render(key, config, dest, node_path, tilemill_path):
conn.execute(
'REPLACE INTO metadata (name, value) VALUES (?, ?)', (k, v)
)
- except Exception as ex:
+ except Exception:
+ _, ex, _ = sys.exc_info()
log.warn("sqlite operation failed for %s: %s" % (key, str(ex)))
finally:
conn.close()
View
2 requirements-2.5.txt
@@ -0,0 +1,2 @@
+-r requirements.txt
+simplejson
View
3 requirements.txt
@@ -1,2 +1,3 @@
nose
-git+https://github.com/jimr/testy#egg=testy
+tox
+testy>=0.1.1
View
5 setup.py
@@ -19,15 +19,16 @@ def get_init_val(val, packages=PACKAGES):
name='py-%s' % get_init_val('title'),
version=get_init_val('version'),
description=get_init_val('description'),
- long_description=open('README.md').read(),
+ long_description=open('README.rst').read(),
author=get_init_val('author'),
+ author_email='jim@jimr.org',
url=get_init_val('url'),
- package_data={'': ['LICENSE', 'NOTICE']},
license=get_init_val('license'),
entry_points={
'console_scripts': [
'projectmill = projectmill:main',
]
},
+ install_requires=['testy'],
packages=PACKAGES
)
View
2 tests/test_merge_config.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
+from __future__ import with_statement
+
import copy
import unittest
View
8 tests/test_process_mml.py
@@ -1,7 +1,13 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
-import json
+from __future__ import with_statement
+
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
import os
import unittest
View
8 tests/test_process_mss.py
@@ -1,8 +1,14 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
+from __future__ import with_statement
+
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
import codecs
-import json
import os
import unittest
View
32 tox.ini
@@ -0,0 +1,32 @@
+[base]
+deps =
+ nose
+ testy
+
+[tox]
+envlist = py25,py26,py27,py30,py31,py32,py33
+
+[testenv]
+deps={[base]deps}
+commands=nosetests
+
+[testenv:py25]
+deps =
+ {[base]deps}
+ argparse
+ simplejson
+
+[testenv:py26]
+deps =
+ {[base]deps}
+ argparse
+
+[testenv:py30]
+deps =
+ {[base]deps}
+ argparse
+
+[testenv:py31]
+deps =
+ {[base]deps}
+ argparse

0 comments on commit 7307d0b

Please sign in to comment.