diff --git a/doc/ExtendingLimits.md b/doc/ExtendingLimits.md index c18a37c..b022b30 100644 --- a/doc/ExtendingLimits.md +++ b/doc/ExtendingLimits.md @@ -24,7 +24,7 @@ constants of full-`constexpr` enums. To extend: replacement macros for `enum.h` to use. Pick a name for this file and a location somewhere in your include path. I will assume that this file is `common/enum_macros.h` in your project. - 4. Run `python make_macros.py 512 64 > common/enum_macros.h`. + 4. Run `python3 make_macros.py 512 64 > common/enum_macros.h`. 5. Define `BETTER_ENUMS_MACRO_FILE ` before including `enum.h`. This is typically done by supplying extra flags to the compiler on the command line: diff --git a/doc/Makefile b/doc/Makefile index ad7ec9b..8d0db89 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -5,7 +5,7 @@ SOURCE_CXX := $(foreach md,$(SOURCE_MARKDOWN),$(call toexample,$(md))) .PHONY : html html : - python docs.py + python3 docs.py @echo "See html/index.html" .PHONY : publish @@ -19,14 +19,14 @@ prepare : examples web .PHONY : web web : examples - python docs.py --web + python3 docs.py --web .PHONY : examples examples : $(SOURCE_CXX) define EXAMPLE $(1) : $(2) - python transform.py --o-cxx $(1) $(2) + python3 transform.py --o-cxx $(1) $(2) endef $(foreach md,$(SOURCE_MARKDOWN), \ diff --git a/doc/docs.py b/doc/docs.py index 724e365..3dc4a55 100755 --- a/doc/docs.py +++ b/doc/docs.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#!/usr/bin/env python3 import glob import re @@ -8,7 +8,7 @@ import transform import os import os.path import sys -import urllib +import urllib.parse TEMPLATE_DIRECTORY = "template" OUTPUT_DIRECTORY = "html" @@ -85,8 +85,8 @@ def compose_page(relative_path, definitions): definitions["canonical"] = canonical definitions["prefix"] = prefix - definitions["quoted_url"] = urllib.quote(definitions["canonical"], "") - definitions["quoted_title"] = urllib.quote(definitions["title"], "") + definitions["quoted_url"] = urllib.parse.quote(definitions["canonical"], "") + definitions["quoted_title"] = urllib.parse.quote(definitions["title"], "") if "class" not in definitions: definitions["class"] = "" @@ -140,9 +140,7 @@ def compose_general_page(relative_path): write_page(relative_path, text) def list_general_pages(): - return filter( - lambda s: not os.path.splitext(os.path.basename(s))[0].isupper(), - glob.glob("*.md")) + return [s for s in glob.glob("*.md") if not os.path.splitext(os.path.basename(s))[0].isupper()] def process_threaded(directory): sources = glob.glob(os.path.join(directory, "*.md")) diff --git a/doc/mistune.py b/doc/mistune.py index 34860d9..ba1fed6 100755 --- a/doc/mistune.py +++ b/doc/mistune.py @@ -944,7 +944,7 @@ class Markdown(object): if not self.footnotes: return out - footnotes = filter(lambda o: keys.get(o['key']), self.footnotes) + footnotes = [o for o in self.footnotes if keys.get(o['key'])] self.footnotes = sorted( footnotes, key=lambda o: keys.get(o['key']), reverse=True ) diff --git a/doc/transform.py b/doc/transform.py index 04652f2..59332bb 100755 --- a/doc/transform.py +++ b/doc/transform.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#!/usr/bin/env python3 # Reads mixed source/text markdown files and outputs HTML and/or C++ source. # Usage: @@ -48,9 +48,9 @@ def pretty_print(text, prefix, start_with_prefix = True): def camel_case(text): components = re.split("[ -]+", text) - components = map(lambda s: s.capitalize(), components) + components = [s.capitalize() for s in components] result = "".join(components) - result = filter(lambda c: c not in ",!:-$()?", result) + result = "".join([c for c in result if c not in ",!:-$()?"]) return result class HtmlRenderer(mistune.Renderer): diff --git a/script/make_macros.py b/script/make_macros.py index 88d9288..479387a 100755 --- a/script/make_macros.py +++ b/script/make_macros.py @@ -1,4 +1,4 @@ -#! /usr/bin/env python +#!/usr/bin/env python3 # This file is part of Better Enums, released under the BSD 2-clause license. # See LICENSE for details, or visit http://github.com/aantron/better-enums. @@ -25,7 +25,7 @@ # # 0. MACRO_FILE is the name of the external macro file. Make sure you put it # somewhere in your include path. -# 1. Run python make_macros.py 512 128 > MACRO_FILE +# 1. Run python3 make_macros.py 512 128 > MACRO_FILE # 2. Build your code with an additional compiler flag: # - for gcc and clang, -DBETTER_ENUMS_MACRO_FILE='' # - for VC++, /DBETTER_ENUMS_MACRO_FILE='' @@ -53,7 +53,7 @@ class MultiLine(object): break_line = True if break_line: - print >> self._stream, ' ' * (self._columns_left - 1) + '\\' + print(' ' * (self._columns_left - 1) + '\\', file=self._stream) self._stream.write(' ' * self._indent) self._columns_left = self._columns - self._indent token = token.lstrip() @@ -62,42 +62,42 @@ class MultiLine(object): self._columns_left -= len(token) def generate(stream, constants, length, script): - print >> stream, '// This file was automatically generated by ' + script + print('// This file was automatically generated by ' + script, file=stream) - print >> stream, '' - print >> stream, '#pragma once' - print >> stream, '' - print >> stream, '#ifndef BETTER_ENUMS_MACRO_FILE_H' - print >> stream, '#define BETTER_ENUMS_MACRO_FILE_H' + print('', file=stream) + print('#pragma once', file=stream) + print('', file=stream) + print('#ifndef BETTER_ENUMS_MACRO_FILE_H', file=stream) + print('#define BETTER_ENUMS_MACRO_FILE_H', file=stream) - print >> stream, '' - print >> stream, '#define BETTER_ENUMS_PP_MAP(macro, data, ...) \\' - print >> stream, ' BETTER_ENUMS_ID( \\' - print >> stream, ' BETTER_ENUMS_APPLY( \\' - print >> stream, ' BETTER_ENUMS_PP_MAP_VAR_COUNT, \\' - print >> stream, ' BETTER_ENUMS_PP_COUNT(__VA_ARGS__)) \\' - print >> stream, ' (macro, data, __VA_ARGS__))' + print('', file=stream) + print('#define BETTER_ENUMS_PP_MAP(macro, data, ...) \\', file=stream) + print(' BETTER_ENUMS_ID( \\', file=stream) + print(' BETTER_ENUMS_APPLY( \\', file=stream) + print(' BETTER_ENUMS_PP_MAP_VAR_COUNT, \\', file=stream) + print(' BETTER_ENUMS_PP_COUNT(__VA_ARGS__)) \\', file=stream) + print(' (macro, data, __VA_ARGS__))', file=stream) - print >> stream, '' - print >> stream, '#define BETTER_ENUMS_PP_MAP_VAR_COUNT(count) ' + \ - 'BETTER_ENUMS_M ## count' + print('', file=stream) + print('#define BETTER_ENUMS_PP_MAP_VAR_COUNT(count) ' + + 'BETTER_ENUMS_M ## count', file=stream) - print >> stream, '' - print >> stream, '#define BETTER_ENUMS_APPLY(macro, ...) ' + \ - 'BETTER_ENUMS_ID(macro(__VA_ARGS__))' + print('', file=stream) + print('#define BETTER_ENUMS_APPLY(macro, ...) ' + + 'BETTER_ENUMS_ID(macro(__VA_ARGS__))', file=stream) - print >> stream, '' - print >> stream, '#define BETTER_ENUMS_ID(x) x' + print('', file=stream) + print('#define BETTER_ENUMS_ID(x) x', file=stream) - print >> stream, '' - print >> stream, '#define BETTER_ENUMS_M1(m, d, x) m(d,0,x)' + print('', file=stream) + print('#define BETTER_ENUMS_M1(m, d, x) m(d,0,x)', file=stream) for index in range(2, constants + 1): - print >> stream, '#define BETTER_ENUMS_M' + str(index) + \ - '(m,d,x,...) m(d,' + str(index - 1) + ',x) \\' - print >> stream, ' BETTER_ENUMS_ID(BETTER_ENUMS_M' + \ - str(index - 1) + '(m,d,__VA_ARGS__))' + print('#define BETTER_ENUMS_M' + str(index) + + '(m,d,x,...) m(d,' + str(index - 1) + ',x) \\', file=stream) + print(' BETTER_ENUMS_ID(BETTER_ENUMS_M' + + str(index - 1) + '(m,d,__VA_ARGS__))', file=stream) - print >> stream, '' + print('', file=stream) pp_count_impl_prefix = '#define BETTER_ENUMS_PP_COUNT_IMPL(_1,' stream.write(pp_count_impl_prefix) pp_count_impl = MultiLine(stream = stream, indent = 4, @@ -107,10 +107,10 @@ def generate(stream, constants, length, script): pp_count_impl.write(' count,') pp_count_impl.write(' ...)') pp_count_impl.write(' count', last = True) - print >> stream, '' + print('', file=stream) - print >> stream, '' - print >> stream, '#define BETTER_ENUMS_PP_COUNT(...) \\' + print('', file=stream) + print('#define BETTER_ENUMS_PP_COUNT(...) \\', file=stream) pp_count_prefix = \ ' BETTER_ENUMS_ID(BETTER_ENUMS_PP_COUNT_IMPL(__VA_ARGS__,' stream.write(pp_count_prefix) @@ -119,28 +119,27 @@ def generate(stream, constants, length, script): for index in range(0, constants - 1): pp_count.write(' ' + str(constants - index) + ',') pp_count.write(' 1))', last = True) - print >> stream, '' + print('', file=stream) - print >> stream, '' + print('', file=stream) iterate_prefix = '#define BETTER_ENUMS_ITERATE(X, f, l)' stream.write(iterate_prefix) iterate = MultiLine(stream = stream, indent = 4, initial_column = len(iterate_prefix)) for index in range(0, length): iterate.write(' X(f, l, %i)' % index) - print >> stream, '' + print('', file=stream) - print >> stream, '' - print >> stream, '#endif // #ifndef BETTER_ENUMS_MACRO_FILE_H' + print('', file=stream) + print('#endif // #ifndef BETTER_ENUMS_MACRO_FILE_H', file=stream) if __name__ == '__main__': if len(sys.argv) != 3: - print >> sys.stderr, \ - 'Usage: ' + sys.argv[0] + ' CONSTANTS LENGTH > FILE' - print >> sys.stderr, '' - print >> sys.stderr, 'Prints map macro definition to FILE.' - print >> sys.stderr, 'CONSTANTS is the number of constants to support.' - print >> sys.stderr, 'LENGTH is the maximum length of a constant name.' + print('Usage: ' + sys.argv[0] + ' CONSTANTS LENGTH > FILE', file=sys.stderr) + print('', file=sys.stderr) + print('Prints map macro definition to FILE.', file=sys.stderr) + print('CONSTANTS is the number of constants to support.', file=sys.stderr) + print('LENGTH is the maximum length of a constant name.', file=sys.stderr) sys.exit(1) generate(sys.stdout, int(sys.argv[1]), int(sys.argv[2]), diff --git a/test/Makefile b/test/Makefile index 719a85e..6bfb0fc 100644 --- a/test/Makefile +++ b/test/Makefile @@ -36,7 +36,7 @@ define PATH_FIX sed 's!include "/!include "C:/cygwin/!g' $1 > $$$$ && mv $$$$ $1 endef SUFFIX := .exe -CXXTESTGEN := python `which cxxtestgen | sed -E 's!(/cygdrive)?/c/!c:/!'` +CXXTESTGEN := python3 `which cxxtestgen | sed -E 's!(/cygdrive)?/c/!c:/!'` endif