From 2f41683e8580d29dcc8005e984c43cad1554423f Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Fri, 29 Nov 2019 23:09:18 +0100 Subject: [PATCH 1/3] Including example Travis CI configuration from examples/ directory in docs/setup.md --- .../mkdocs_include_markdown_plugin/plugin.py | 16 +++++++-- docs/setup.md | 34 +++---------------- 2 files changed, 18 insertions(+), 32 deletions(-) diff --git a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py index 69409318..b1f05cd8 100644 --- a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py +++ b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py @@ -9,6 +9,8 @@ TAG_REGEX_PATTERN = re.compile( "(?P[^"]+)" # "filename" (?:\s+start="(?P[^"]+)")? # optional start expression (?:\s+end="(?P[^"]+)")? # optional end expression + (?:\s+before="(?P[^"]+)")? # optional preceding text to add + (?:\s+after="(?P[^"]+)")? # optional succeeding text to add \s* %} # closing tag ''', @@ -23,6 +25,8 @@ class ImportMarkdownPlugin(mkdocs.plugins.BasePlugin): filename = match.group('filename') start = match.group('start') end = match.group('end') + before = match.group('before') + after = match.group('after') file_path_abs = os.path.join(os.path.dirname(page_src_path), filename) @@ -38,12 +42,18 @@ class ImportMarkdownPlugin(mkdocs.plugins.BasePlugin): if end: text_to_include, _, _ = text_to_include.partition(end) + if before: + text_to_include = before.replace('\\n', '\n') + text_to_include + + if after: + text_to_include = text_to_include + after.replace('\\n', '\n') + return ( - '' % ( - filename, cgi.escape(start), cgi.escape(end) + '\n' % ( + filename, cgi.escape(start or ''), cgi.escape(end or '') ) + text_to_include - + '' + + '\n' ) markdown = re.sub(TAG_REGEX_PATTERN, found_import_markdown_tag, markdown) diff --git a/docs/setup.md b/docs/setup.md index bcb1542f..8af222e3 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -52,35 +52,11 @@ Wheels will be stored for you and available through the Pipelines interface. For To build Linux, Mac, and Windows wheels on Travis CI, create a `.travis.yml` file in your repo. > .travis.yml -```yaml -language: python - -jobs: - include: - # perform a linux build - - services: docker - # and a mac build - - os: osx - language: shell - # and a windows build - - os: windows - language: shell - before_install: - - choco install python --version 3.8.0 - - export PATH="/c/Python38:/c/Python38/Scripts:$PATH" - -env: - global: - - TWINE_USERNAME=joerick - # Note: TWINE_PASSWORD is set in Travis settings - -install: - - python -m pip install twine cibuildwheel==1.1.0 - -script: - # build the wheels, put them into './wheelhouse' - - python -m cibuildwheel --output-dir wheelhouse -``` +{% + includemarkdown "../examples/travis-ci-deploy-only.yml" + before="```yaml\n" + after="```\n" +%} Note that building Windows Python 2.7 wheels on Travis is unsupported. From 472fa32d9fc1f5867b2a38cae037b5c91a227497 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 8 Dec 2019 23:46:20 +0100 Subject: [PATCH 2/3] Added {% include ... %} directive for including examples/travis-ci-minimal.yml in docs/setup.md --- .../mkdocs_include_markdown_plugin/plugin.py | 44 +++++++++++++------ docs/setup.md | 8 ++-- examples/travis-ci-minimal.yml | 22 ++++++++++ 3 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 examples/travis-ci-minimal.yml diff --git a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py index b1f05cd8..0060eec5 100644 --- a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py +++ b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py @@ -1,6 +1,19 @@ import mkdocs, re, os, io, cgi -TAG_REGEX_PATTERN = re.compile( +INCLUDE_TAG_REGEX = re.compile( + r''' + {% # opening tag + \s* + include # directive name + \s+ + "(?P[^"]+)" # "filename" + \s* + %} # closing tag + ''', + flags=re.VERBOSE, +) + +INCLUDEMARKDOWN_TAG_REGEX = re.compile( r''' {% # opening tag \s* @@ -9,8 +22,6 @@ TAG_REGEX_PATTERN = re.compile( "(?P[^"]+)" # "filename" (?:\s+start="(?P[^"]+)")? # optional start expression (?:\s+end="(?P[^"]+)")? # optional end expression - (?:\s+before="(?P[^"]+)")? # optional preceding text to add - (?:\s+after="(?P[^"]+)")? # optional succeeding text to add \s* %} # closing tag ''', @@ -21,12 +32,24 @@ class ImportMarkdownPlugin(mkdocs.plugins.BasePlugin): def on_page_markdown(self, markdown, page, **kwargs): page_src_path = page.file.abs_src_path - def found_import_markdown_tag(match): + def found_include_tag(match): + filename = match.group('filename') + + file_path_abs = os.path.join(os.path.dirname(page_src_path), filename) + + if not os.path.exists(file_path_abs): + raise ValueError('file not found', filename) + + with io.open(file_path_abs, encoding='utf8') as f: + text_to_include = f.read() + + return text_to_include + + + def found_includemarkdown_tag(match): filename = match.group('filename') start = match.group('start') end = match.group('end') - before = match.group('before') - after = match.group('after') file_path_abs = os.path.join(os.path.dirname(page_src_path), filename) @@ -42,12 +65,6 @@ class ImportMarkdownPlugin(mkdocs.plugins.BasePlugin): if end: text_to_include, _, _ = text_to_include.partition(end) - if before: - text_to_include = before.replace('\\n', '\n') + text_to_include - - if after: - text_to_include = text_to_include + after.replace('\\n', '\n') - return ( '\n' % ( filename, cgi.escape(start or ''), cgi.escape(end or '') @@ -56,6 +73,7 @@ class ImportMarkdownPlugin(mkdocs.plugins.BasePlugin): + '\n' ) - markdown = re.sub(TAG_REGEX_PATTERN, found_import_markdown_tag, markdown) + markdown = re.sub(INCLUDE_TAG_REGEX, found_include_tag, markdown) + markdown = re.sub(INCLUDEMARKDOWN_TAG_REGEX, found_includemarkdown_tag, markdown) return markdown \ No newline at end of file diff --git a/docs/setup.md b/docs/setup.md index 8af222e3..2c1ed02c 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -52,11 +52,9 @@ Wheels will be stored for you and available through the Pipelines interface. For To build Linux, Mac, and Windows wheels on Travis CI, create a `.travis.yml` file in your repo. > .travis.yml -{% - includemarkdown "../examples/travis-ci-deploy-only.yml" - before="```yaml\n" - after="```\n" -%} +```yaml +{% include "../examples/travis-ci-minimal.yml" %} +``` Note that building Windows Python 2.7 wheels on Travis is unsupported. diff --git a/examples/travis-ci-minimal.yml b/examples/travis-ci-minimal.yml new file mode 100644 index 00000000..f1abc204 --- /dev/null +++ b/examples/travis-ci-minimal.yml @@ -0,0 +1,22 @@ +language: python + +jobs: + include: + # perform a linux build + - services: docker + # and a mac build + - os: osx + language: shell + # and a windows build + - os: windows + language: shell + before_install: + - choco install python --version 3.8.0 + - export PATH="/c/Python38:/c/Python38/Scripts:$PATH" + +install: + - python -m pip install cibuildwheel==1.1.0 + +script: + # build the wheels, put them into './wheelhouse' + - python -m cibuildwheel --output-dir wheelhouse \ No newline at end of file From eda3dc1a4f1fa047778f18b6c4a9e919b043751a Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Tue, 10 Dec 2019 14:57:25 +0100 Subject: [PATCH 3/3] Moving Azure, AppVeyor, and CircleCI minimal examples in docs also to their own file under examples/ --- .../mkdocs_include_markdown_plugin/plugin.py | 6 +- docs/setup.md | 87 +------------------ examples/appveyor-minimal.yml | 15 ++++ examples/azure-pipelines-minimal.yml | 35 ++++++++ examples/circleci-minimal.yml | 38 ++++++++ examples/travis-ci-minimal.yml | 2 +- examples/travis-ci-test-and-deploy.yml | 1 - 7 files changed, 97 insertions(+), 87 deletions(-) create mode 100644 examples/appveyor-minimal.yml create mode 100644 examples/azure-pipelines-minimal.yml create mode 100644 examples/circleci-minimal.yml diff --git a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py index 0060eec5..55fadf2f 100644 --- a/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py +++ b/docs/mkdocs_include_markdown_plugin/mkdocs_include_markdown_plugin/plugin.py @@ -42,7 +42,11 @@ class ImportMarkdownPlugin(mkdocs.plugins.BasePlugin): with io.open(file_path_abs, encoding='utf8') as f: text_to_include = f.read() - + + # Allow good practice of having a final newline in the file + if text_to_include.endswith('\n'): + text_to_include = text_to_include[:-1] + return text_to_include diff --git a/docs/setup.md b/docs/setup.md index 2c1ed02c..01580747 100644 --- a/docs/setup.md +++ b/docs/setup.md @@ -8,39 +8,7 @@ Using Azure pipelines, you can build all three platforms on the same service. Cr > azure-pipelines.yml ```yaml -jobs: -- job: linux - pool: {vmImage: 'Ubuntu-16.04'} - steps: - - task: UsePythonVersion@0 - - bash: | - python -m pip install --upgrade pip - pip install cibuildwheel==1.1.0 - cibuildwheel --output-dir wheelhouse . - - task: PublishBuildArtifacts@1 - inputs: {pathtoPublish: 'wheelhouse'} -- job: macos - pool: {vmImage: 'macOS-10.13'} - steps: - - task: UsePythonVersion@0 - - bash: | - python -m pip install --upgrade pip - pip install cibuildwheel==1.1.0 - cibuildwheel --output-dir wheelhouse . - - task: PublishBuildArtifacts@1 - inputs: {pathtoPublish: 'wheelhouse'} -- job: windows - pool: {vmImage: 'vs2017-win2016'} - steps: - - task: UsePythonVersion@0 - - script: choco install vcpython27 -f -y - displayName: Install Visual C++ for Python 2.7 - - bash: | - python -m pip install --upgrade pip - pip install cibuildwheel==1.1.0 - cibuildwheel --output-dir wheelhouse . - - task: PublishBuildArtifacts@1 - inputs: {pathtoPublish: 'wheelhouse'} +{% include "../examples/azure-pipelines-minimal.yml" %} ``` Commit this file, enable building of your repo on Azure Pipelines, and push. @@ -68,44 +36,7 @@ To build Linux and Mac wheels on CircleCI, create a `.circleci/config.yml` file > .circleci/config.yml ```yaml -version: 2 - -jobs: - linux-wheels: - working_directory: ~/linux-wheels - docker: - - image: circleci/python:3.6 - steps: - - checkout - - setup_remote_docker - - run: - name: Build the Linux wheels. - command: | - pip install --user cibuildwheel==1.1.0 - cibuildwheel --output-dir wheelhouse - - store_artifacts: - path: wheelhouse/ - - osx-wheels: - working_directory: ~/osx-wheels - macos: - xcode: "10.0.0" - steps: - - checkout - - run: - name: Build the OS X wheels. - command: | - pip install --user cibuildwheel==1.1.0 - cibuildwheel --output-dir wheelhouse - - store_artifacts: - path: wheelhouse/ - -workflows: - version: 2 - all-tests: - jobs: - - linux-wheels - - osx-wheels +{% include "../examples/circleci-minimal.yml" %} ``` Commit this file, enable building of your repo on CircleCI, and push. @@ -122,19 +53,7 @@ To build Linux and Windows wheels on AppVeyor, create an `appveyor.yml` file in > appveyor.yml ```yaml -image: - - Ubuntu - - Visual Studio 2015 -build_script: - # windows - - cmd: pip install cibuildwheel==1.1.0 - - cmd: cibuildwheel --output-dir wheelhouse - # linux - - sh: "${HOME}/.localpython3.7.4/bin/python3 -m pip install cibuildwheel==1.1.0" - - sh: "${HOME}/.localpython3.7.4/bin/python3 -m cibuildwheel --output-dir wheelhouse" -artifacts: - - path: "wheelhouse\\*.whl" - name: Wheels +{% include "../examples/appveyor-minimal.yml" %} ``` Commit this file, enable building of your repo on AppVeyor, and push. diff --git a/examples/appveyor-minimal.yml b/examples/appveyor-minimal.yml new file mode 100644 index 00000000..b0503233 --- /dev/null +++ b/examples/appveyor-minimal.yml @@ -0,0 +1,15 @@ +image: + - Ubuntu + - Visual Studio 2015 + +build_script: + # windows + - cmd: pip install cibuildwheel==1.1.0 + - cmd: cibuildwheel --output-dir wheelhouse + # linux + - sh: "${HOME}/.localpython3.7.4/bin/python3 -m pip install cibuildwheel==1.1.0" + - sh: "${HOME}/.localpython3.7.4/bin/python3 -m cibuildwheel --output-dir wheelhouse" + +artifacts: + - path: "wheelhouse\\*.whl" + name: Wheels diff --git a/examples/azure-pipelines-minimal.yml b/examples/azure-pipelines-minimal.yml new file mode 100644 index 00000000..567d6302 --- /dev/null +++ b/examples/azure-pipelines-minimal.yml @@ -0,0 +1,35 @@ +jobs: +- job: linux + pool: {vmImage: 'Ubuntu-16.04'} + steps: + - task: UsePythonVersion@0 + - bash: | + python -m pip install --upgrade pip + pip install cibuildwheel==1.1.0 + cibuildwheel --output-dir wheelhouse . + - task: PublishBuildArtifacts@1 + inputs: {pathtoPublish: 'wheelhouse'} + +- job: macos + pool: {vmImage: 'macOS-10.13'} + steps: + - task: UsePythonVersion@0 + - bash: | + python -m pip install --upgrade pip + pip install cibuildwheel==1.1.0 + cibuildwheel --output-dir wheelhouse . + - task: PublishBuildArtifacts@1 + inputs: {pathtoPublish: 'wheelhouse'} + +- job: windows + pool: {vmImage: 'vs2017-win2016'} + steps: + - task: UsePythonVersion@0 + - script: choco install vcpython27 -f -y + displayName: Install Visual C++ for Python 2.7 + - bash: | + python -m pip install --upgrade pip + pip install cibuildwheel==1.1.0 + cibuildwheel --output-dir wheelhouse . + - task: PublishBuildArtifacts@1 + inputs: {pathtoPublish: 'wheelhouse'} diff --git a/examples/circleci-minimal.yml b/examples/circleci-minimal.yml new file mode 100644 index 00000000..053966d9 --- /dev/null +++ b/examples/circleci-minimal.yml @@ -0,0 +1,38 @@ +version: 2 + +jobs: + linux-wheels: + working_directory: ~/linux-wheels + docker: + - image: circleci/python:3.6 + steps: + - checkout + - setup_remote_docker + - run: + name: Build the Linux wheels. + command: | + pip install --user cibuildwheel==1.1.0 + cibuildwheel --output-dir wheelhouse + - store_artifacts: + path: wheelhouse/ + + osx-wheels: + working_directory: ~/osx-wheels + macos: + xcode: "10.0.0" + steps: + - checkout + - run: + name: Build the OS X wheels. + command: | + pip install --user cibuildwheel==1.1.0 + cibuildwheel --output-dir wheelhouse + - store_artifacts: + path: wheelhouse/ + +workflows: + version: 2 + all-tests: + jobs: + - linux-wheels + - osx-wheels diff --git a/examples/travis-ci-minimal.yml b/examples/travis-ci-minimal.yml index f1abc204..e71772b7 100644 --- a/examples/travis-ci-minimal.yml +++ b/examples/travis-ci-minimal.yml @@ -19,4 +19,4 @@ install: script: # build the wheels, put them into './wheelhouse' - - python -m cibuildwheel --output-dir wheelhouse \ No newline at end of file + - python -m cibuildwheel --output-dir wheelhouse diff --git a/examples/travis-ci-test-and-deploy.yml b/examples/travis-ci-test-and-deploy.yml index 9a31da96..2609921f 100644 --- a/examples/travis-ci-test-and-deploy.yml +++ b/examples/travis-ci-test-and-deploy.yml @@ -74,4 +74,3 @@ env: global: - TWINE_USERNAME=joerick # Note: TWINE_PASSWORD is set in Travis settings -