├── .circleci └── config.yml ├── .github └── workflows │ ├── cd.yaml │ └── ci.yaml ├── .gitignore ├── .travis.yml ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── docs ├── build.py ├── images │ ├── bg_hr.png │ ├── blacktocat.png │ ├── icon_download.png │ └── sprite_download.png ├── index.html.tmpl ├── style.css └── test-ϋnicodé,fîleñämӛ.html ├── ghp_import.py └── setup.py /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | jobs: 4 | test: 5 | docker: 6 | - image: circleci/python 7 | steps: 8 | - checkout 9 | - run: make install 10 | - run: git config --global user.name "ghp-import-bot" && git config --global user.email "ghp@import.bot" 11 | - run: make -e DOCS_BRANCH="test-circleci-$CIRCLE_BUILD_NUM" docs clean 12 | 13 | workflows: 14 | version: 2 15 | main: 16 | jobs: 17 | - test: 18 | filters: 19 | branches: 20 | only: 21 | - master 22 | -------------------------------------------------------------------------------- /.github/workflows/cd.yaml: -------------------------------------------------------------------------------- 1 | name: CD 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | gh-pages: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - uses: actions/setup-python@v2 14 | with: 15 | python-version: '3.9' 16 | - run: git remote set-url --push origin "https://:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}" 17 | env: 18 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 19 | - run: make install 20 | - run: make docs 21 | 22 | pypi: 23 | runs-on: ubuntu-latest 24 | if: "startsWith(github.event.head_commit.message, 'This is ')" 25 | 26 | steps: 27 | - uses: actions/checkout@v2 28 | - uses: actions/setup-python@v2 29 | with: 30 | python-version: '3.9' 31 | - run: make install 32 | - run: make release 33 | env: 34 | TWINE_USERNAME: __token__ 35 | TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }} 36 | -------------------------------------------------------------------------------- /.github/workflows/ci.yaml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: [pull_request] 4 | 5 | jobs: 6 | ci: 7 | runs-on: ${{ matrix.os }}-latest 8 | strategy: 9 | matrix: 10 | python-version: ['2.7', '3.9'] 11 | os: [ubuntu, windows, macos] 12 | opts: ['--shell', ''] 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-python@v2 17 | with: 18 | python-version: ${{ matrix.python-version }} 19 | - run: make install 20 | - run: make lint 21 | - run: make -e DOCS_OPTS="${{ matrix.opts }}" docs 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vscode/ 3 | build/ 4 | dist/ 5 | venv/ 6 | *.pyc 7 | __pycache__/ 8 | ghp_import.egg-info/ 9 | docs/index.html 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | branches: 4 | only: 5 | - master 6 | 7 | install: 8 | - make install 9 | 10 | before_script: 11 | - git remote add github "https://${GITHUB_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git" 2>&1 >/dev/null 12 | - export GIT_COMMITTER_NAME="ghp-import-bot" 13 | - export GIT_COMMITTER_EMAIL="ghp@import.bot" 14 | 15 | script: 16 | - make -e DOCS_BRANCH="test-travis-${TRAVIS_BUILD_NUMBER}" -e DOCS_REMOTE=github docs clean 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [2020] [Paul Davis ] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE 2 | include README.md 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | DOCS_BRANCH := gh-pages 2 | DOCS_REMOTE := origin 3 | DOCS_OPTS := -p 4 | 5 | install: 6 | pip install -e .[dev] 7 | 8 | lint: 9 | flake8 ./ghp_import.py ./setup.py ./docs/build.py 10 | 11 | docs: 12 | python ./docs/build.py 13 | ghp-import $(DOCS_OPTS) docs/ -b $(DOCS_BRANCH) -r $(DOCS_REMOTE) -m "Update docs [skip ci]" -o 14 | 15 | clean: 16 | python -c "import os; os.remove(os.path.join('docs', 'index.html'))" 17 | git branch -D $(DOCS_BRANCH) 18 | git push $(DOCS_REMOTE) --delete $(DOCS_BRANCH) 19 | 20 | release: 21 | python setup.py sdist bdist_wheel 22 | twine upload --skip-existing --non-interactive ./dist/* 23 | 24 | .PHONY: docs lint install clean release 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GitHub Pages Import 2 | =================== 3 | 4 | [![CI status](https://github.com/davisp/ghp-import/workflows/CI/badge.svg)](https://github.com/davisp/ghp-import/actions?query=workflow%3Aci) 5 | [![CircleCI](https://circleci.com/gh/c-w/ghp-import/tree/master.svg?style=svg)](https://circleci.com/gh/c-w/ghp-import/tree/master) 6 | [![TravisCI](https://travis-ci.org/c-w/ghp-import.svg?branch=master)](https://travis-ci.org/c-w/ghp-import) 7 | 8 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 9 | [![Version](https://img.shields.io/pypi/v/ghp-import.svg)](https://pypi.org/project/ghp-import/) 10 | 11 | As part of [gunicorn][gunicorn], [Benoit Chesneau][benoit] and [Paul Davis][davisp] 12 | were looking at how to host documentation. There's the obvious method of 13 | using [GitHub's post-receive hook][github-post] to trigger doc builds and rsync 14 | to a webserver, but we ended up wanting to try out github's hosting to make the 15 | whole interface a bit more robust. 16 | 17 | [GitHub Pages][gh-pages] is a pretty awesome service that GitHub provides for 18 | hosting project documentation. The only thing is that it requires a 19 | `gh-pages` branch that is the site's document root. This means that keeping 20 | documentation sources in the branch with code is a bit difficult. And it really 21 | turns into a head scratcher for things like [Sphinx][sphinx] that want to 22 | access documentation sources and code sources at the same time. 23 | 24 | Then we stumbled across an interesting looking package called 25 | [github-tools][github-tools] that looked almost like what we wanted. It was a tad 26 | complicated and more involved than we wanted but it gave us an idea. Why not 27 | just write a script that can copy a directory to the `gh-pages` branch of the 28 | repository. This saves us from even having to think about the branch and 29 | everything becomes magical. 30 | 31 | This is what `ghp-import` was written for. 32 | 33 | [gunicorn]: http://www.gunicorn.com/ "Gunicorn" 34 | [benoit]: http://github.com/benoitc "Benoît Chesneau" 35 | [davisp]: http://github.com/davisp "Paul J. Davis" 36 | [github-post]: https://help.github.com/articles/post-receive-hooks "GitHub Post-Receive Hook" 37 | [gh-pages]: http://pages.github.com/ "GitHub Pages" 38 | [sphinx]: http://sphinx.pocoo.org/ "Sphinx Documentation" 39 | [github-tools]: http://dinoboff.github.io/github-tools/ "github-tools" 40 | 41 | 42 | Big Fat Warning 43 | --------------- 44 | 45 | This will **DESTROY** your `gh-pages` branch. If you love it, you'll want to 46 | take backups before playing with this. This script assumes that `gh-pages` is 47 | 100% derivative. You should never edit files in your `gh-pages` branch by hand 48 | if you're using this script because you will lose your work. 49 | 50 | When used with a prefix, only files below the set prefix will be destroyed, limiting the 51 | above warning to just that directory and everything below it. 52 | 53 | Usage 54 | ----- 55 | 56 | ``` 57 | Usage: ghp-import [OPTIONS] DIRECTORY 58 | 59 | Options: 60 | -n, --no-jekyll Include a .nojekyll file in the branch. 61 | -c CNAME, --cname=CNAME 62 | Write a CNAME file with the given CNAME. 63 | -m MESG, --message=MESG 64 | The commit message to use on the target branch. 65 | -p, --push Push the branch to origin/{branch} after committing. 66 | -x PREFIX, --prefix=PREFIX 67 | The prefix to add to each file that gets pushed to the 68 | remote. Only files below this prefix will be cleared 69 | out. [none] 70 | -f, --force Force the push to the repository. 71 | -o, --no-history Force new commit without parent history. 72 | -r REMOTE, --remote=REMOTE 73 | The name of the remote to push to. [origin] 74 | -b BRANCH, --branch=BRANCH 75 | Name of the branch to write to. [gh-pages] 76 | -s, --shell Use the shell when invoking Git. [False] 77 | -l, --follow-links Follow symlinks when adding files. [False] 78 | -h, --help show this help message and exit 79 | ``` 80 | 81 | Its pretty simple. Inside your repository just run `ghp-import $DOCS_DIR` 82 | where `$DOCS_DIR` is the path to the **built** documentation. This will write a 83 | commit to your `gh-pages` branch with the current documents in it. 84 | 85 | If you specify `-p` it will also attempt to push the `gh-pages` branch to 86 | GitHub. By default it'll just run `git push origin gh-pages`. You can specify 87 | a different remote using the `-r` flag. 88 | 89 | The `-o` option will discard any previous history and ensure that only a 90 | single commit is always pushed to the `gh-pages` branch. This is useful to 91 | avoid bloating the repository size and is **highly recommended**. 92 | 93 | You can specify a different branch with `-b`. This is useful for user and 94 | organization page, which are served from the `master` branch. 95 | 96 | Some Windows users report needing to pass Git commands through the shell which can be accomplished by passing `-s`. 97 | 98 | The `-l` option will cause the import to follow symlinks for users that have odd configurations that include symlinking outside of their documentation directory. 99 | 100 | Python Usage 101 | ------------ 102 | 103 | You can also call ghp_import directly from your Python code as a library. The 104 | library has one public function `ghp_import.ghp_import`, which accepts the 105 | following arguments: 106 | 107 | * `srcdir`: The path to the **built** documentation (required). 108 | * `remote`: The name of the remote to push to. Default: `origin`. 109 | * `branch`: Name of the branch to write to. Default: `gh-pages`. 110 | * `mesg`: The commit message to use on the target branch. Default: `Update documentation`. 111 | * `push`: Push the branch to {remote}/{branch} after committing. Default: `False`. 112 | * `prefix`: The prefix to add to each file that gets pushed to the remote. Default: `None`. 113 | * `force`: Force the push to the repository. Default: `False`. 114 | * `no_history`: Force new commit without parent history. Default: `False`. 115 | * `use_shell`: Default: Use the shell when invoking Git. `False`. 116 | * `followlinks`: Follow symlinks when adding files. Default: `False`. 117 | * `cname`: Write a CNAME file with the given CNAME. Default: `None`. 118 | * `nojekyll`: Include a .nojekyll file in the branch. Default: `False`. 119 | 120 | With Python's current working directory (cwd) inside your repository, do the 121 | following: 122 | 123 | ```python 124 | from ghp_import import ghp_import 125 | ghp_import('docs', push=True, cname='example.com') 126 | ``` 127 | -------------------------------------------------------------------------------- /docs/build.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import io 4 | import os 5 | 6 | from markdown import markdown 7 | 8 | 9 | def main(): 10 | base = os.path.abspath(os.path.dirname(__file__)) 11 | 12 | readme_path = os.path.join(os.path.dirname(base), "README.md") 13 | with io.open(readme_path, encoding="utf-8") as fobj: 14 | readme = fobj.read() 15 | 16 | template_path = os.path.join(base, "index.html.tmpl") 17 | with io.open(template_path, encoding="utf-8") as fobj: 18 | template = fobj.read() 19 | 20 | index_path = os.path.join(base, "index.html") 21 | with io.open(index_path, mode="w", encoding="utf-8") as fobj: 22 | html = markdown(readme, extensions=["fenced_code"]) 23 | fobj.write(template.format(body=html)) 24 | 25 | 26 | if __name__ == "__main__": 27 | main() 28 | -------------------------------------------------------------------------------- /docs/images/bg_hr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c-w/ghp-import/5219f00fc83606ff426b978a9920ea746923dcb7/docs/images/bg_hr.png -------------------------------------------------------------------------------- /docs/images/blacktocat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c-w/ghp-import/5219f00fc83606ff426b978a9920ea746923dcb7/docs/images/blacktocat.png -------------------------------------------------------------------------------- /docs/images/icon_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c-w/ghp-import/5219f00fc83606ff426b978a9920ea746923dcb7/docs/images/icon_download.png -------------------------------------------------------------------------------- /docs/images/sprite_download.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/c-w/ghp-import/5219f00fc83606ff426b978a9920ea746923dcb7/docs/images/sprite_download.png -------------------------------------------------------------------------------- /docs/index.html.tmpl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | ghp-import - GitHub Pages import tool 10 | 11 | 12 | 13 | 14 |
15 |
16 | View on GitHub 17 | 18 |

ghp-import

19 |

Easily import docs to your gh-pages branch.

20 |
21 | Download this project as a .zip file 22 | Download this project as a tar.gz file 23 |
24 |
25 |
26 | 27 | 28 |
29 |
30 | {body} 31 |
32 |
33 | 34 | 35 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /docs/style.css: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | Slate Theme for GitHub Pages 3 | by Jason Costello, @jsncostello 4 | *******************************************************************************/ 5 | 6 | @import url(pygment_trac.css); 7 | 8 | /******************************************************************************* 9 | MeyerWeb Reset 10 | *******************************************************************************/ 11 | 12 | html, body, div, span, applet, object, iframe, 13 | h1, h2, h3, h4, h5, h6, p, blockquote, pre, 14 | a, abbr, acronym, address, big, cite, code, 15 | del, dfn, em, img, ins, kbd, q, s, samp, 16 | small, strike, strong, sub, sup, tt, var, 17 | b, u, i, center, 18 | dl, dt, dd, ol, ul, li, 19 | fieldset, form, label, legend, 20 | table, caption, tbody, tfoot, thead, tr, th, td, 21 | article, aside, canvas, details, embed, 22 | figure, figcaption, footer, header, hgroup, 23 | menu, nav, output, ruby, section, summary, 24 | time, mark, audio, video { 25 | margin: 0; 26 | padding: 0; 27 | border: 0; 28 | font: inherit; 29 | vertical-align: baseline; 30 | } 31 | 32 | /* HTML5 display-role reset for older browsers */ 33 | article, aside, details, figcaption, figure, 34 | footer, header, hgroup, menu, nav, section { 35 | display: block; 36 | } 37 | 38 | ol, ul { 39 | list-style: none; 40 | } 41 | 42 | blockquote, q { 43 | } 44 | 45 | table { 46 | border-collapse: collapse; 47 | border-spacing: 0; 48 | } 49 | 50 | a:focus { 51 | outline: none; 52 | } 53 | 54 | /******************************************************************************* 55 | Theme Styles 56 | *******************************************************************************/ 57 | 58 | body { 59 | box-sizing: border-box; 60 | color:#373737; 61 | background: #212121; 62 | font-size: 16px; 63 | font-family: 'Myriad Pro', Calibri, Helvetica, Arial, sans-serif; 64 | line-height: 1.5; 65 | -webkit-font-smoothing: antialiased; 66 | } 67 | 68 | h1, h2, h3, h4, h5, h6 { 69 | margin: 10px 0; 70 | font-weight: 700; 71 | color:#222222; 72 | font-family: 'Lucida Grande', 'Calibri', Helvetica, Arial, sans-serif; 73 | letter-spacing: -1px; 74 | } 75 | 76 | h1 { 77 | font-size: 36px; 78 | font-weight: 700; 79 | } 80 | 81 | h2 { 82 | padding-bottom: 10px; 83 | font-size: 32px; 84 | background: url('../images/bg_hr.png') repeat-x bottom; 85 | } 86 | 87 | h3 { 88 | font-size: 24px; 89 | } 90 | 91 | h4 { 92 | font-size: 21px; 93 | } 94 | 95 | h5 { 96 | font-size: 18px; 97 | } 98 | 99 | h6 { 100 | font-size: 16px; 101 | } 102 | 103 | p { 104 | margin: 10px 0 15px 0; 105 | } 106 | 107 | footer p { 108 | color: #f2f2f2; 109 | } 110 | 111 | a { 112 | text-decoration: none; 113 | color: #007edf; 114 | text-shadow: none; 115 | 116 | transition: color 0.5s ease; 117 | transition: text-shadow 0.5s ease; 118 | -webkit-transition: color 0.5s ease; 119 | -webkit-transition: text-shadow 0.5s ease; 120 | -moz-transition: color 0.5s ease; 121 | -moz-transition: text-shadow 0.5s ease; 122 | -o-transition: color 0.5s ease; 123 | -o-transition: text-shadow 0.5s ease; 124 | -ms-transition: color 0.5s ease; 125 | -ms-transition: text-shadow 0.5s ease; 126 | } 127 | 128 | #main_content a:hover { 129 | color: #0069ba; 130 | text-shadow: #0090ff 0px 0px 2px; 131 | } 132 | 133 | footer a:hover { 134 | color: #43adff; 135 | text-shadow: #0090ff 0px 0px 2px; 136 | } 137 | 138 | em { 139 | font-style: italic; 140 | } 141 | 142 | strong { 143 | font-weight: bold; 144 | } 145 | 146 | img { 147 | position: relative; 148 | margin: 0 auto; 149 | max-width: 739px; 150 | padding: 5px; 151 | margin: 10px 0 10px 0; 152 | border: 1px solid #ebebeb; 153 | 154 | box-shadow: 0 0 5px #ebebeb; 155 | -webkit-box-shadow: 0 0 5px #ebebeb; 156 | -moz-box-shadow: 0 0 5px #ebebeb; 157 | -o-box-shadow: 0 0 5px #ebebeb; 158 | -ms-box-shadow: 0 0 5px #ebebeb; 159 | } 160 | 161 | pre, code { 162 | width: 100%; 163 | color: #222; 164 | background-color: #fff; 165 | 166 | font-family: Monaco, "Bitstream Vera Sans Mono", "Lucida Console", Terminal, monospace; 167 | font-size: 14px; 168 | 169 | border-radius: 2px; 170 | -moz-border-radius: 2px; 171 | -webkit-border-radius: 2px; 172 | 173 | 174 | 175 | } 176 | 177 | pre { 178 | width: 100%; 179 | padding: 10px; 180 | box-shadow: 0 0 10px rgba(0,0,0,.1); 181 | overflow: auto; 182 | } 183 | 184 | code { 185 | padding: 3px; 186 | margin: 0 3px; 187 | box-shadow: 0 0 10px rgba(0,0,0,.1); 188 | } 189 | 190 | pre code { 191 | display: block; 192 | box-shadow: none; 193 | } 194 | 195 | blockquote { 196 | color: #666; 197 | margin-bottom: 20px; 198 | padding: 0 0 0 20px; 199 | border-left: 3px solid #bbb; 200 | } 201 | 202 | ul, ol, dl { 203 | margin-bottom: 15px 204 | } 205 | 206 | ul li { 207 | list-style: inside; 208 | padding-left: 20px; 209 | } 210 | 211 | ol li { 212 | list-style: decimal inside; 213 | padding-left: 20px; 214 | } 215 | 216 | dl dt { 217 | font-weight: bold; 218 | } 219 | 220 | dl dd { 221 | padding-left: 20px; 222 | font-style: italic; 223 | } 224 | 225 | dl p { 226 | padding-left: 20px; 227 | font-style: italic; 228 | } 229 | 230 | hr { 231 | height: 1px; 232 | margin-bottom: 5px; 233 | border: none; 234 | background: url('../images/bg_hr.png') repeat-x center; 235 | } 236 | 237 | table { 238 | border: 1px solid #373737; 239 | margin-bottom: 20px; 240 | text-align: left; 241 | } 242 | 243 | th { 244 | font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif; 245 | padding: 10px; 246 | background: #373737; 247 | color: #fff; 248 | } 249 | 250 | td { 251 | padding: 10px; 252 | border: 1px solid #373737; 253 | } 254 | 255 | form { 256 | background: #f2f2f2; 257 | padding: 20px; 258 | } 259 | 260 | /******************************************************************************* 261 | Full-Width Styles 262 | *******************************************************************************/ 263 | 264 | .outer { 265 | width: 100%; 266 | } 267 | 268 | .inner { 269 | position: relative; 270 | max-width: 640px; 271 | padding: 20px 10px; 272 | margin: 0 auto; 273 | } 274 | 275 | #forkme_banner { 276 | display: block; 277 | position: absolute; 278 | top:0; 279 | right: 10px; 280 | z-index: 10; 281 | padding: 10px 50px 10px 10px; 282 | color: #fff; 283 | background: url('../images/blacktocat.png') #0090ff no-repeat 95% 50%; 284 | font-weight: 700; 285 | box-shadow: 0 0 10px rgba(0,0,0,.5); 286 | border-bottom-left-radius: 2px; 287 | border-bottom-right-radius: 2px; 288 | } 289 | 290 | #header_wrap { 291 | background: #212121; 292 | background: -moz-linear-gradient(top, #373737, #212121); 293 | background: -webkit-linear-gradient(top, #373737, #212121); 294 | background: -ms-linear-gradient(top, #373737, #212121); 295 | background: -o-linear-gradient(top, #373737, #212121); 296 | background: linear-gradient(top, #373737, #212121); 297 | } 298 | 299 | #header_wrap .inner { 300 | padding: 50px 10px 30px 10px; 301 | } 302 | 303 | #project_title { 304 | margin: 0; 305 | color: #fff; 306 | font-size: 42px; 307 | font-weight: 700; 308 | text-shadow: #111 0px 0px 10px; 309 | } 310 | 311 | #project_tagline { 312 | color: #fff; 313 | font-size: 24px; 314 | font-weight: 300; 315 | background: none; 316 | text-shadow: #111 0px 0px 10px; 317 | } 318 | 319 | #downloads { 320 | position: absolute; 321 | width: 210px; 322 | z-index: 10; 323 | bottom: -40px; 324 | right: 0; 325 | height: 70px; 326 | background: url('../images/icon_download.png') no-repeat 0% 90%; 327 | } 328 | 329 | .zip_download_link { 330 | display: block; 331 | float: right; 332 | width: 90px; 333 | height:70px; 334 | text-indent: -5000px; 335 | overflow: hidden; 336 | background: url(../images/sprite_download.png) no-repeat bottom left; 337 | } 338 | 339 | .tar_download_link { 340 | display: block; 341 | float: right; 342 | width: 90px; 343 | height:70px; 344 | text-indent: -5000px; 345 | overflow: hidden; 346 | background: url(../images/sprite_download.png) no-repeat bottom right; 347 | margin-left: 10px; 348 | } 349 | 350 | .zip_download_link:hover { 351 | background: url(../images/sprite_download.png) no-repeat top left; 352 | } 353 | 354 | .tar_download_link:hover { 355 | background: url(../images/sprite_download.png) no-repeat top right; 356 | } 357 | 358 | #main_content_wrap { 359 | background: #f2f2f2; 360 | border-top: 1px solid #111; 361 | border-bottom: 1px solid #111; 362 | } 363 | 364 | #main_content { 365 | padding-top: 40px; 366 | } 367 | 368 | #footer_wrap { 369 | background: #212121; 370 | } 371 | 372 | 373 | 374 | /******************************************************************************* 375 | Small Device Styles 376 | *******************************************************************************/ 377 | 378 | @media screen and (max-width: 480px) { 379 | body { 380 | font-size:14px; 381 | } 382 | 383 | #downloads { 384 | display: none; 385 | } 386 | 387 | .inner { 388 | min-width: 320px; 389 | max-width: 480px; 390 | } 391 | 392 | #project_title { 393 | font-size: 32px; 394 | } 395 | 396 | h1 { 397 | font-size: 28px; 398 | } 399 | 400 | h2 { 401 | font-size: 24px; 402 | } 403 | 404 | h3 { 405 | font-size: 21px; 406 | } 407 | 408 | h4 { 409 | font-size: 18px; 410 | } 411 | 412 | h5 { 413 | font-size: 14px; 414 | } 415 | 416 | h6 { 417 | font-size: 12px; 418 | } 419 | 420 | code, pre { 421 | min-width: 320px; 422 | max-width: 480px; 423 | font-size: 11px; 424 | } 425 | 426 | } 427 | -------------------------------------------------------------------------------- /docs/test-ϋnicodé,fîleñämӛ.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ghp_import.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | 3 | import errno 4 | import os 5 | import subprocess as sp 6 | import sys 7 | import time 8 | from dateutil import tz 9 | from datetime import datetime 10 | 11 | try: 12 | from shlex import quote 13 | except ImportError: 14 | from pipes import quote 15 | 16 | __all__ = ['ghp_import'] 17 | __version__ = "2.1.0" 18 | 19 | 20 | class GhpError(Exception): 21 | def __init__(self, message): 22 | self.message = message 23 | 24 | 25 | if sys.version_info[0] == 3: 26 | def enc(text): 27 | if isinstance(text, bytes): 28 | return text 29 | return text.encode() 30 | 31 | def dec(text): 32 | if isinstance(text, bytes): 33 | return text.decode('utf-8') 34 | return text 35 | 36 | def write(pipe, data): 37 | try: 38 | pipe.stdin.write(data) 39 | except IOError as e: 40 | if e.errno != errno.EPIPE: 41 | raise 42 | else: 43 | def enc(text): 44 | if isinstance(text, unicode): # noqa F821 45 | return text.encode('utf-8') 46 | return text 47 | 48 | def dec(text): 49 | if isinstance(text, unicode): # noqa F821 50 | return text 51 | return text.decode('utf-8') 52 | 53 | def write(pipe, data): 54 | pipe.stdin.write(data) 55 | 56 | 57 | class Git(object): 58 | def __init__(self, use_shell=False): 59 | self.use_shell = use_shell 60 | 61 | self.cmd = None 62 | self.pipe = None 63 | self.stderr = None 64 | self.stdout = None 65 | 66 | def check_repo(self): 67 | if self.call('rev-parse') != 0: 68 | error = self.stderr 69 | if not error: 70 | error = "Unknown Git error" 71 | error = dec(error) 72 | if error.startswith("fatal: "): 73 | error = error[len("fatal: "):] 74 | raise GhpError(error) 75 | 76 | def try_rebase(self, remote, branch, no_history=False): 77 | rc = self.call('rev-list', '--max-count=1', '%s/%s' % (remote, branch)) 78 | if rc != 0: 79 | return True 80 | rev = dec(self.stdout.strip()) 81 | if no_history: 82 | rc = self.call('update-ref', '-d', 'refs/heads/%s' % branch) 83 | else: 84 | rc = self.call('update-ref', 'refs/heads/%s' % branch, rev) 85 | if rc != 0: 86 | return False 87 | return True 88 | 89 | def get_config(self, key): 90 | self.call('config', key) 91 | return self.stdout.strip() 92 | 93 | def get_prev_commit(self, branch): 94 | rc = self.call('rev-list', '--max-count=1', branch, '--') 95 | if rc != 0: 96 | return None 97 | return dec(self.stdout).strip() 98 | 99 | def open(self, *args, **kwargs): 100 | if self.use_shell: 101 | self.cmd = 'git ' + ' '.join(map(quote, args)) 102 | else: 103 | self.cmd = ['git'] + list(args) 104 | if sys.version_info >= (3, 2, 0): 105 | kwargs['universal_newlines'] = False 106 | for k in 'stdin stdout stderr'.split(): 107 | kwargs.setdefault(k, sp.PIPE) 108 | kwargs['shell'] = self.use_shell 109 | self.pipe = sp.Popen(self.cmd, **kwargs) 110 | return self.pipe 111 | 112 | def call(self, *args, **kwargs): 113 | self.open(*args, **kwargs) 114 | (self.stdout, self.stderr) = self.pipe.communicate() 115 | return self.pipe.wait() 116 | 117 | def check_call(self, *args, **kwargs): 118 | kwargs["shell"] = self.use_shell 119 | sp.check_call(['git'] + list(args), **kwargs) 120 | 121 | 122 | def mk_when(timestamp=None): 123 | if timestamp is None: 124 | timestamp = int(time.time()) 125 | currtz = datetime.now(tz.tzlocal()).strftime('%z') 126 | return "%s %s" % (timestamp, currtz) 127 | 128 | 129 | def start_commit(pipe, git, branch, message, prefix=None): 130 | uname = os.getenv('GIT_COMMITTER_NAME', dec(git.get_config('user.name'))) 131 | email = os.getenv('GIT_COMMITTER_EMAIL', dec(git.get_config('user.email'))) 132 | when = os.getenv('GIT_COMMITTER_DATE', mk_when()) 133 | write(pipe, enc('commit refs/heads/%s\n' % branch)) 134 | write(pipe, enc('committer %s <%s> %s\n' % (uname, email, when))) 135 | write(pipe, enc('data %d\n%s\n' % (len(enc(message)), message))) 136 | head = git.get_prev_commit(branch) 137 | if head: 138 | write(pipe, enc('from %s\n' % head)) 139 | if prefix: 140 | write(pipe, enc('D %s\n' % prefix)) 141 | else: 142 | write(pipe, enc('deleteall\n')) 143 | 144 | 145 | def add_file(pipe, srcpath, tgtpath): 146 | with open(srcpath, "rb") as handle: 147 | if os.access(srcpath, os.X_OK): 148 | write(pipe, enc('M 100755 inline %s\n' % tgtpath)) 149 | else: 150 | write(pipe, enc('M 100644 inline %s\n' % tgtpath)) 151 | data = handle.read() 152 | write(pipe, enc('data %d\n' % len(data))) 153 | write(pipe, enc(data)) 154 | write(pipe, enc('\n')) 155 | 156 | 157 | def add_nojekyll(pipe, prefix=None): 158 | if prefix: 159 | fpath = os.path.join(prefix, '.nojekyll') 160 | else: 161 | fpath = '.nojekyll' 162 | write(pipe, enc('M 100644 inline %s\n' % fpath)) 163 | write(pipe, enc('data 0\n')) 164 | write(pipe, enc('\n')) 165 | 166 | 167 | def add_cname(pipe, cname): 168 | write(pipe, enc('M 100644 inline CNAME\n')) 169 | write(pipe, enc('data %d\n%s\n' % (len(enc(cname)), cname))) 170 | 171 | 172 | def gitpath(fname): 173 | norm = os.path.normpath(fname) 174 | return "/".join(norm.split(os.path.sep)) 175 | 176 | 177 | def run_import(git, srcdir, **opts): 178 | srcdir = dec(srcdir) 179 | pipe = git.open('fast-import', '--date-format=rfc2822', '--quiet', 180 | stdin=sp.PIPE, stdout=None, stderr=None) 181 | start_commit(pipe, git, opts['branch'], opts['mesg'], opts['prefix']) 182 | for path, _, fnames in os.walk(srcdir, followlinks=opts['followlinks']): 183 | for fn in fnames: 184 | fpath = os.path.join(path, fn) 185 | gpath = gitpath(os.path.relpath(fpath, start=srcdir)) 186 | if opts['prefix']: 187 | gpath = os.path.join(opts['prefix'], gpath) 188 | add_file(pipe, fpath, gpath) 189 | if opts['nojekyll']: 190 | add_nojekyll(pipe, opts['prefix']) 191 | if opts['cname'] is not None: 192 | add_cname(pipe, opts['cname']) 193 | write(pipe, enc('\n')) 194 | pipe.stdin.close() 195 | if pipe.wait() != 0: 196 | sys.stdout.write(enc("Failed to process commit.\n")) 197 | 198 | 199 | def options(): 200 | return [ 201 | (('-n', '--no-jekyll'), dict( 202 | dest='nojekyll', 203 | default=False, 204 | action="store_true", 205 | help='Include a .nojekyll file in the branch.', 206 | )), 207 | (('-c', '--cname'), dict( 208 | dest='cname', 209 | default=None, 210 | help='Write a CNAME file with the given CNAME.', 211 | )), 212 | (('-m', '--message'), dict( 213 | dest='mesg', 214 | default='Update documentation', 215 | help='The commit message to use on the target branch.', 216 | )), 217 | (('-p', '--push'), dict( 218 | dest='push', 219 | default=False, 220 | action='store_true', 221 | help='Push the branch to origin/{branch} after committing.', 222 | )), 223 | (('-x', '--prefix'), dict( 224 | dest='prefix', 225 | default=None, 226 | help='The prefix to add to each file that gets pushed to the ' 227 | 'remote. Only files below this prefix will be cleared ' 228 | 'out. [%(default)s]', 229 | )), 230 | (('-f', '--force'), dict( 231 | dest='force', 232 | default=False, action='store_true', 233 | help='Force the push to the repository.', 234 | )), 235 | (('-o', '--no-history'), dict( 236 | dest='no_history', 237 | default=False, 238 | action='store_true', 239 | help='Force new commit without parent history.', 240 | )), 241 | (('-r', '--remote'), dict( 242 | dest='remote', 243 | default='origin', 244 | help='The name of the remote to push to. [%(default)s]', 245 | )), 246 | (('-b', '--branch'), dict( 247 | dest='branch', 248 | default='gh-pages', 249 | help='Name of the branch to write to. [%(default)s]', 250 | )), 251 | (('-s', '--shell'), dict( 252 | dest='use_shell', 253 | default=False, 254 | action='store_true', 255 | help='Use the shell when invoking Git. [%(default)s]', 256 | )), 257 | (('-l', '--follow-links'), dict( 258 | dest='followlinks', 259 | default=False, 260 | action='store_true', 261 | help='Follow symlinks when adding files. [%(default)s]', 262 | )) 263 | ] 264 | 265 | 266 | def ghp_import(srcdir, **kwargs): 267 | if not os.path.isdir(srcdir): 268 | raise GhpError("Not a directory: %s" % srcdir) 269 | 270 | opts = {kwargs["dest"]: kwargs["default"] for _, kwargs in options()} 271 | opts.update(kwargs) 272 | 273 | git = Git(use_shell=opts['use_shell']) 274 | git.check_repo() 275 | 276 | if not git.try_rebase(opts['remote'], opts['branch'], opts['no_history']): 277 | raise GhpError("Failed to rebase %s branch." % opts['branch']) 278 | 279 | run_import(git, srcdir, **opts) 280 | 281 | if opts['push']: 282 | if opts['force'] or opts['no_history']: 283 | git.check_call('push', opts['remote'], opts['branch'], '--force') 284 | else: 285 | git.check_call('push', opts['remote'], opts['branch']) 286 | 287 | 288 | def main(): 289 | from argparse import ArgumentParser 290 | 291 | parser = ArgumentParser() 292 | parser.add_argument("--version", action="version", version=__version__) 293 | parser.add_argument("directory") 294 | for args, kwargs in options(): 295 | parser.add_argument(*args, **kwargs) 296 | 297 | args = parser.parse_args().__dict__ 298 | 299 | try: 300 | ghp_import(args.pop("directory"), **args) 301 | except GhpError as e: 302 | parser.error(e.message) 303 | 304 | 305 | if __name__ == '__main__': 306 | main() 307 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import io 2 | import os 3 | import re 4 | 5 | try: 6 | from setuptools import setup 7 | except ImportError: 8 | from distutils.core import setup 9 | 10 | HERE = os.path.dirname(__file__) 11 | LONG_DESC_PATH = os.path.join(HERE, "README.md") 12 | LONG_DESC = io.open(LONG_DESC_PATH, encoding="utf-8").read() 13 | 14 | with io.open(os.path.join(HERE, "ghp_import.py"), encoding="utf-8") as fobj: 15 | for line in fobj: 16 | match = re.match( 17 | r"^__version__\s*=\s*['\"](?P[\d.]+)['\"]$", 18 | line.strip() 19 | ) 20 | if match: 21 | VERSION = match.group("version") 22 | break 23 | 24 | setup( 25 | name="ghp-import", 26 | version=VERSION, 27 | description="Copy your docs directly to the gh-pages branch.", 28 | long_description=LONG_DESC, 29 | long_description_content_type="text/markdown", 30 | author="Paul Joseph Davis", 31 | author_email="paul.joseph.davis@gmail.com", 32 | license="Apache Software License", 33 | url="https://github.com/c-w/ghp-import", 34 | zip_safe=False, 35 | 36 | install_requires=[ 37 | "python-dateutil>=2.8.1", 38 | ], 39 | 40 | extras_require={ 41 | "dev": [ 42 | "twine", 43 | "markdown", 44 | "flake8", 45 | "wheel", 46 | ], 47 | }, 48 | 49 | classifiers=[ 50 | "Development Status :: 5 - Production/Stable", 51 | "License :: OSI Approved :: Apache Software License", 52 | "Intended Audience :: Developers", 53 | "Natural Language :: English", 54 | "Operating System :: OS Independent", 55 | "Programming Language :: Python", 56 | "Programming Language :: Python :: 2", 57 | "Programming Language :: Python :: 3", 58 | ], 59 | 60 | py_modules=["ghp_import"], 61 | 62 | entry_points={ 63 | "console_scripts": [ 64 | "ghp-import = ghp_import:main", 65 | ], 66 | } 67 | ) 68 | --------------------------------------------------------------------------------