[python-mapnik] 01/06: Imported Upstream version 0.0~20150909-1489d53

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sun Sep 20 13:07:29 UTC 2015


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

sebastic pushed a commit to branch master
in repository python-mapnik.

commit f6c85f3bd8c8fb7e00989d2f2a6aefee31d8ea6d
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sun Sep 13 01:20:58 2015 +0200

    Imported Upstream version 0.0~20150909-1489d53
---
 CONTRIBUTING.md       | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++
 setup.py              |  75 +++++++++++++++++++++---
 src/mapnik_logger.cpp |   2 +-
 3 files changed, 224 insertions(+), 10 deletions(-)

diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..5dfb3ce
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,157 @@
+# Contributing
+
+General guidelines for contributing to python-mapnik
+
+## Coding Conventions
+
+Much of python Mapnik is written in C++, and we try to follow general coding guidelines.
+
+If you see bits of code around that do not follow these please don't hesitate to flag the issue or correct it yourself.
+
+### C++ Style Guide
+
+#### Prefix cmath functions with std::
+
+The avoids ambiguity and potential bugs of using old C library math directly.
+
+So always do `std::abs()` instead of `abs()`. Here is a script to fix your code in one fell swoop:
+
+
+```sh
+DIR=./bindings
+for i in {abs,fabs,tan,sin,cos,floor,ceil,atan2,acos,asin}; do
+    find $DIR -type f -name '*.cpp' -or -name '*.h' -or -name '*.hpp' | xargs perl -i -p -e "s/ $i\(/ std::$i\(/g;"
+    find $DIR -type f -name '*.cpp' -or -name '*.h' -or -name '*.hpp' | xargs perl -i -p -e "s/\($i\(/\(std::$i\(/g;"
+done
+```
+
+#### Avoid boost::lexical_cast
+
+It's slow both to compile and at runtime.
+
+#### Avoid sstream objects if possible
+
+They should never be used in performance critical code because they trigger std::locale usage
+which triggers locks
+
+#### Spaces not tabs, and avoid trailing whitespace
+
+#### Indentation is four spaces
+
+#### Use C++ style casts
+
+    static_cast<int>(value); // yes
+
+    (int)value; // no
+
+
+#### Use const keyword after the type
+
+    std::string const& variable_name // preferred, for consistency
+
+    const std::string & variable_name // no
+
+
+#### Pass built-in types by value, all others by const&
+
+    void my_function(int double val); // if int, char, double, etc pass by value
+
+    void my_function(std::string const& val); // if std::string or user type, pass by const&
+
+#### Use unique_ptr instead of new/delete
+
+#### Use std::copy instead of memcpy
+
+#### When to use shared_ptr and unique_ptr
+
+Sparingly, always prefer passing objects as const& except where using share_ptr or unique_ptr express more clearly your intent. See http://herbsutter.com/2013/06/05/gotw-91-solution-smart-pointer-parameters/ for more details.
+
+#### Shared pointers should be created with std::make_shared.
+
+#### Use assignment operator for zero initialized numbers
+
+    double num = 0; // please
+
+    double num(0); // no
+
+
+#### Function definitions should not be separated from their arguments:
+
+    void foo(int a) // please
+
+    void foo (int a) // no
+
+
+#### Separate arguments by a single space:
+
+    void foo(int a, float b) // please
+
+    void foo(int a,float b) // no
+
+
+#### Space between operators:
+
+    if (a == b) // please
+
+    if(a==b) // no
+
+
+#### Braces should always be used:
+
+    if (!file)
+    {
+        throw mapnik::datasource_exception("not found"); // please    
+    }
+
+    if (!file)
+        throw mapnik::datasource_exception("not found"); // no
+
+
+#### Braces should be on a separate line:
+
+    if (a == b)
+    {
+        int z = 5;
+        // more...
+    }
+
+
+#### Prefer `empty()` over `size() == 0` if container supports it
+
+This avoids implicit conversions to bool and reduces compiler warnings.
+
+    if (container.empty()) // please
+
+    if (container.size() == 0) // no
+
+
+### Other C++ style resources
+
+Many also follow the useful [Google style guide](http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml) which mostly fits our style. However, Google obviously has to maintain a lot of aging codebases. Mapnik can move faster, so we don't follow all of those style recommendations.
+
+### Python Style Guide
+
+All python code should follow PEP8 as closely as possible. However, we do not strictly enforce all PEP8 such as 80 characters per line.
+
+## Testing
+
+In order for any code to be pulled into master it must contain tests for **100%** of all lines. The only lines that are not required to be tested are those that cover extreme cases which can not be tested with regularity, such as race conditions. 
+
+If this case does occur you can put a comment block such as shown below to exclude the lines from test coverage.
+
+```C++
+// LCOV_EXCL_START
+can_not_reach_code();
+// LCOV_EXCL_END
+```
+
+## Releasing
+
+To release a new python-mapnik version:
+
+Currently just hit up @flippmoke, this section will be filled out ASAP!
+
+### Documentation
+
+TODO: Write documentation on how to update documentation.
+
diff --git a/setup.py b/setup.py
index 15a70fa..8832a48 100755
--- a/setup.py
+++ b/setup.py
@@ -1,15 +1,17 @@
 #! /usr/bin/env python
 
 import os
+import os.path
 import re
 import shutil
 import subprocess
 import sys
 from distutils import sysconfig
+from ctypes.util import find_library
 
-from setuptools import Extension, setup
+from setuptools import Command, Extension, setup
 
-PYTHON3 = sys.version_info[0] == 3
+PYTHON3 = sys.version_info.major == 3
 
 
 # Utils
@@ -21,6 +23,64 @@ def check_output(args):
     return output.rstrip('\n')
 
 
+def clean_boost_name(name):
+    name = name.split('.')[0]
+    if name.startswith('lib'):
+        name = name[3:]
+    return name
+
+
+def find_boost_library(_id):
+    suffixes = [
+        "",  # standard naming
+        "-mt"  # former naming schema for multithreading build
+    ]
+    if "python" in _id:
+        # Debian naming convention for versions installed in parallel
+        suffixes.insert(0, "-py%d%d" % (sys.version_info.major,
+                                        sys.version_info.minor))
+        # standard suffix for Python3
+        suffixes.insert(1, sys.version_info.major)
+    for suf in suffixes:
+        name = "%s%s" % (_id, suf)
+        lib = find_library(name)
+        if lib is not None:
+            return name
+
+
+def get_boost_library_names():
+    wanted = ['boost_python', 'boost_system', 'boost_thread']
+    found = []
+    missing = []
+    for _id in wanted:
+        name = os.environ.get("%s_LIB" % _id.upper(), find_boost_library(_id))
+        if name:
+            found.append(name)
+        else:
+            missing.append(_id)
+    if missing:
+        msg = ""
+        for name in missing:
+            msg += ("\nMissing {} boost library, try to add its name with "
+                    "{}_LIB environment var.").format(name, name.upper())
+        raise EnvironmentError(msg)
+    return found
+
+
+class WhichBoostCommand(Command):
+    description = 'Output found boost names. Useful for debug.'
+    user_options = []
+
+    def initialize_options(self):
+        pass
+
+    def finalize_options(self):
+        pass
+
+    def run(self):
+        print("\n".join(get_boost_library_names()))
+
+
 cflags = sysconfig.get_config_var('CFLAGS')
 sysconfig._config_vars['CFLAGS'] = re.sub(
     ' +', ' ', cflags.replace('-g', '').replace('-Os', '').replace('-arch i386', ''))
@@ -48,9 +108,6 @@ else:
     mapnik_config = 'mapnik-config'
     mason_build = False
 
-boost_python_lib = os.environ.get("BOOST_PYTHON_LIB", 'boost_python-mt')
-boost_system_lib = os.environ.get("BOOST_SYSTEM_LIB", 'boost_system-mt')
-boost_thread_lib = os.environ.get("BOOST_THREAD_LIB", 'boost_thread-mt')
 
 try:
     linkflags = check_output([mapnik_config, '--libs']).split(' ')
@@ -204,6 +261,9 @@ setup(
         'mapnik': ['libmapnik.*', 'plugins/*/*'],
     },
     test_suite='nose.collector',
+    cmdclass={
+        'whichboost': WhichBoostCommand,
+    },
     ext_modules=[
         Extension('mapnik._mapnik', [
             'src/mapnik_color.cpp',
@@ -247,10 +307,7 @@ setup(
                 'mapnik',
                 'mapnik-wkt',
                 'mapnik-json',
-                boost_python_lib,
-                boost_thread_lib,
-                boost_system_lib
-        ],
+            ] + get_boost_library_names(),
             extra_compile_args=extra_comp_args,
             extra_link_args=linkflags,
         )
diff --git a/src/mapnik_logger.cpp b/src/mapnik_logger.cpp
index 16baf0f..aa1b037 100644
--- a/src/mapnik_logger.cpp
+++ b/src/mapnik_logger.cpp
@@ -67,7 +67,7 @@ void export_logger()
         .def("get_object_severity", &logger::get_object_severity)
         .def("set_object_severity", &logger::set_object_severity)
         .def("clear_object_severity", &logger::clear_object_severity)
-        .def("get_format", &logger::get_format)
+        .def("get_format", &logger::get_format,return_value_policy<reference_existing_object>())
         .def("set_format", &logger::set_format)
         .def("str", &logger::str)
         .def("use_file", &logger::use_file)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/python-mapnik.git



More information about the Pkg-grass-devel mailing list