Skip to content

Instantly share code, notes, and snippets.

@MichaelCurrie
Last active April 26, 2021 17:18
Show Gist options
  • Select an option

  • Save MichaelCurrie/802ce28c993ff2dd632c to your computer and use it in GitHub Desktop.

Select an option

Save MichaelCurrie/802ce28c993ff2dd632c to your computer and use it in GitHub Desktop.

Revisions

  1. Michael Currie revised this gist Jan 4, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions autopep8 Travis-CI.md
    Original file line number Diff line number Diff line change
    @@ -72,13 +72,13 @@ I've so far only tested this on a repository that only I can edit. I'm not tota

    http://stackoverflow.com/questions/23277391/how-to-publish-to-github-pages-from-travis-ci

    > 1. Get a Personal Access Token under https://github.com/settings/tokens
    > STEP 1. Get a Personal Access Token under https://github.com/settings/tokens
    > Only enable "public_repo" access for public repositories, "repo" for private.
    > Save the token somewhere as you can only see it once.
    > 2. On the Travis settings for the repository https://travis-ci.org/<me>/<myrepo>/settings create an environment variable:
    > STEP 2. On the Travis settings for the repository https://travis-ci.org/<me>/<myrepo>/settings create an environment variable:
    > `GITHUB_API_KEY=<token>`
    > and make sure to mark "Display value in build log" as "Off".
  2. Michael Currie revised this gist Jan 4, 2016. 1 changed file with 29 additions and 1 deletion.
    30 changes: 29 additions & 1 deletion autopep8 Travis-CI.md
    Original file line number Diff line number Diff line change
    @@ -66,4 +66,32 @@ script:
    # List the remaining errors - these will have to be fixed manually
    - find . -name \*.py -exec pep8 --ignore=E402 {} +

    ```
    ```

    I've so far only tested this on a repository that only I can edit. I'm not totally clear how to get this to work when other people are also making commits. The answer may have to do with these two things, however:

    http://stackoverflow.com/questions/23277391/how-to-publish-to-github-pages-from-travis-ci

    > 1. Get a Personal Access Token under https://github.com/settings/tokens
    > Only enable "public_repo" access for public repositories, "repo" for private.
    > Save the token somewhere as you can only see it once.
    > 2. On the Travis settings for the repository https://travis-ci.org/<me>/<myrepo>/settings create an environment variable:
    > `GITHUB_API_KEY=<token>`
    > and make sure to mark "Display value in build log" as "Off".
    > This is safe because only authorized pushes by you see such environment variables, so if a malicious user tries to make a pull request to get your string, the variable won't be there.
    > Just make sure that you never, ever list your environment variables on your build!
    http://stackoverflow.com/questions/19845679/build-with-travis-ci-and-push-some-files-folder-to-another-repository

    > In summary, we can't control the way Travis-ci clones the repository. This means the remote isn't setup with authentication credentials, so we remove the remote, and add the remote with credentials:
    >```bash
    >cd clonedrepofolder
    >git remote rm origin
    >git remote add origin https://username:${GH_TOKEN}@github.com/username/repo.git
    >```
  3. Michael Currie revised this gist Jan 4, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions autopep8 Travis-CI.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    ## Automatically fix PEP-8 issues using Travis-CI

    [PEP-8](https://www.python.org/dev/peps/pep-0008/) is a set of Python style recommendations. [`pep8`](https://pypi.python.org/pypi/pep8) is a module that checks your `.py` file for violations. To make your Travis-CI build fail if you have any violations, you could add these lines to your `.travis.yml`:

    ```YAML
  4. Michael Currie revised this gist Jan 4, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion autopep8 Travis-CI.md
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,7 @@ script:
    - echo $num_errors_after

    - |
    if [ $num_errors_after < $num_errors_before ]; then
    if (( $num_errors_after < $num_errors_before )); then
    git commit -a -m "PEP-8 Fix"
    git config --global push.default simple # Push only to the current branch.
    # Make sure to make the output quiet, or else the API token will
  5. Michael Currie revised this gist Jan 4, 2016. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions autopep8 Travis-CI.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    PEP-8 is a set of Python style recommendations. pep8 is a module that checks your `.py` file for violations. To make your Travis-CI build fail if you have any violations, you could add these lines to your `.travis.yml`:
    ## Automatically fix PEP-8 issues using Travis-CI

    [PEP-8](https://www.python.org/dev/peps/pep-0008/) is a set of Python style recommendations. [`pep8`](https://pypi.python.org/pypi/pep8) is a module that checks your `.py` file for violations. To make your Travis-CI build fail if you have any violations, you could add these lines to your `.travis.yml`:

    ```YAML
    before_install:
    @@ -11,7 +13,7 @@ script:
    - find . -name \*.py -exec pep8 --ignore=E402 {} +
    ```
    However, since this makes my build fail for very trivial violations, like extra whitespace after a line of code, I find it isn't practical to include this check unless I also automatically fix any issues. autopep8 can perform this fix; now let's get Travis-CI to run it after every build, and if there are corrections, commit and push these changes.
    However, since this makes my build fail for very trivial violations, like extra whitespace after a line of code, I find it isn't practical to include this check unless I also automatically fix any issues. `autopep8`(https://pypi.python.org/pypi/autopep8) can perform this fix; now let's get Travis-CI to run it after every build, and if there are corrections, commit and push these changes.

    ```YAML
    language: python
  6. Michael Currie revised this gist Jan 4, 2016. 1 changed file with 15 additions and 4 deletions.
    19 changes: 15 additions & 4 deletions autopep8 Travis-CI.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,18 @@
    PEP-8 is a set of Python style recommendations. pep8 is a module that checks your `.py` file for violations. To make your Travis-CI build fail if you have any violations, you could add these lines to your `.travis.yml`:

    ```YAML
    before_install:
    - pip install pep8

    script:
    # Run pep8 on all .py files in all subfolders
    # (I ignore "E402: module level import not at top of file"
    # because of use case sys.path.append('..'); import <module>)
    - find . -name \*.py -exec pep8 --ignore=E402 {} +
    ```
    However, since this makes my build fail for very trivial violations, like extra whitespace after a line of code, I find it isn't practical to include this check unless I also automatically fix any issues. autopep8 can perform this fix; now let's get Travis-CI to run it after every build, and if there are corrections, commit and push these changes.
    ```YAML
    language: python
    python:
    @@ -23,8 +38,6 @@ script:
    - num_errors_before=`find . -name \*.py -exec pep8 --ignore=E402 {} + | wc -l`
    - echo $num_errors_before

    #- |
    #if [ -n "$GITHUB_API_KEY" ]; then
    - cd "$TRAVIS_BUILD_DIR"
    - git config --global user.email "[email protected]"
    # From https://help.github.com/articles/setting-your-username-in-git/:
    @@ -34,8 +47,6 @@ script:
    # with a GitHub account, we'll use your GitHub username, instead of
    # this name.
    - git config --global user.name "Travis"
    #- git clone -q https://MichaelCurrie:$GITHUB_API_KEY@$GH_REF
    #- git clone -q https://Travis:[email protected]/$TRAVIS_REPO_SLUG
    - git checkout $TRAVIS_BRANCH

    - find . -name \*.py -exec autopep8 --recursive --aggressive --aggressive --in-place {} +
  7. Michael Currie created this gist Jan 4, 2016.
    58 changes: 58 additions & 0 deletions autopep8 Travis-CI.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    ```YAML
    language: python
    python:
    - 2.7
    - 3.3
    - 3.4
    - 3.5
    notifications:
    email: false

    before_install:
    - sudo apt-get update
    - sudo apt-get -y install python-pip
    - sudo pip install --upgrade pip
    - pip install --upgrade pip
    - pip install pep8
    - pip install autopep8

    script:
    # Run pep8 on all .py files in all subfolders
    # We must ignore E402 module level import not at top of file
    # because of use case sys.path.append('..'); import <module>
    - num_errors_before=`find . -name \*.py -exec pep8 --ignore=E402 {} + | wc -l`
    - echo $num_errors_before

    #- |
    #if [ -n "$GITHUB_API_KEY" ]; then
    - cd "$TRAVIS_BUILD_DIR"
    - git config --global user.email "[email protected]"
    # From https://help.github.com/articles/setting-your-username-in-git/:
    # "Tip: You don't have to use your real name--any name works. Git
    # actually associates commits by email address; the username is only
    # used for identification. If you use your email address associated
    # with a GitHub account, we'll use your GitHub username, instead of
    # this name.
    - git config --global user.name "Travis"
    #- git clone -q https://MichaelCurrie:$GITHUB_API_KEY@$GH_REF
    #- git clone -q https://Travis:[email protected]/$TRAVIS_REPO_SLUG
    - git checkout $TRAVIS_BRANCH

    - find . -name \*.py -exec autopep8 --recursive --aggressive --aggressive --in-place {} +
    - num_errors_after=`find . -name \*.py -exec pep8 --ignore=E402 {} + | wc -l`
    - echo $num_errors_after

    - |
    if [ $num_errors_after < $num_errors_before ]; then
    git commit -a -m "PEP-8 Fix"
    git config --global push.default simple # Push only to the current branch.
    # Make sure to make the output quiet, or else the API token will
    # leak! This works because the API key can replace your password.
    git push --quiet
    fi
    - cd "$TRAVIS_BUILD_DIR"

    # List the remaining errors - these will have to be fixed manually
    - find . -name \*.py -exec pep8 --ignore=E402 {} +

    ```