Skip to content

Commit

Permalink
Merge pull request #20 from pyscaffold/black
Browse files Browse the repository at this point in the history
Adapt codebase to Black standards
  • Loading branch information
abravalheri committed Aug 17, 2020
2 parents ae6ff8b + f958902 commit 194b7dd
Show file tree
Hide file tree
Showing 18 changed files with 243 additions and 216 deletions.
174 changes: 90 additions & 84 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,47 @@ auto_cancellation: false
env:
PATH: ${HOME}/.local/bin:${PATH}
# ^ add user paths
COVERALLS_REPO_TOKEN: 4UACYLmfItzOy32WE14hotIJZZFZR4QP9
COVERALLS_REPO_TOKEN: ENCRYPTED[9fac4e6abc0e85e179cf0bc9c236f9b2e55281c413f0fc3d92cf4bbbafe0c1ec143f7749ba94b0f2a4ff289dbf9eb5e9]
PIP_CACHE: ${HOME}/.cache/pip
LC_ALL: C.UTF-8
LANG: C.UTF-8

# use custom cloning since otherwise git tags are missing
clone_script: &clone_script |
if [ -z "$CIRRUS_PR" ]; then
git clone --recursive --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git reset --hard $CIRRUS_CHANGE_IN_REPO
else
git clone --recursive https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR
git reset --hard $CIRRUS_CHANGE_IN_REPO
fi

COVERAGE: NO

# This template is used in all tasks
regular_task_template: &REGULAR_TASK_TEMPLATE
.regular_task_template: &REGULAR_TASK_TEMPLATE
tox_install_script:
# Tox is a bit exigent about the name of the python executable,
# (for example, tox requires a `python3.7` to be available)
# and the shape of the directory python is installed to.
# Because of that, some errors might appear in some kinds of installation
# (e.g. OSX with homebrew).
# Luckily, pipx install tox inside its own unique virtualenv, which
# resembles a very standard installation directory.
# So here we install tox using pipx to avoid such problems
- python -m pip install --upgrade pip
- python -m pip install --user pipx
- pipx install tox
prepare_script: &prepare_script
- python -m pip install --upgrade pip setuptools tox
prepare_script: &prepare
# This script is also used in Windows, so the shell is not POSIX
- git config --global user.email "you@example.com"
- git config --global user.name "Your Name"
- git config --system core.longpaths true # Fix for windows git checkout problems
- rm -rf .coverage junit-*.xml
# ^ avoid information carried from one run to the other
test_script:
- tox -e all -- --color yes
clean_workspace_script:
# Avoid information carried from one run to the other
- rm -rf .coverage junit-*.xml .tox
# The following scripts are also used in Windows, be aware the shell is not POSIX
test_script: &test
- python -m tox -- -n 5 -rfEx --durations 10 --color yes --junit-xml junit-test.xml
# ^ tox is better if invoked as a module on Windows/OSX
always: &upload-junit
upload_junit_artifacts:
path: junit-*.xml
format: junit
type: text/xml


# Task definitions:
# ---- Task definitions ----

linux_mac_task:
# use custom cloning since otherwise git tags are missing
clone_script: *clone_script
# Use custom cloning since otherwise git tags are missing
clone_script: &clone |
if [ -z "$CIRRUS_PR" ]; then
git clone --recursive --branch=$CIRRUS_BRANCH https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git reset --hard $CIRRUS_CHANGE_IN_REPO
else
git clone --recursive https://x-access-token:${CIRRUS_REPO_CLONE_TOKEN}@github.com/${CIRRUS_REPO_FULL_NAME}.git $CIRRUS_WORKING_DIR
git fetch origin pull/$CIRRUS_PR/head:pull/$CIRRUS_PR
git reset --hard $CIRRUS_CHANGE_IN_REPO
fi
matrix:
- name: test (Linux - 3.5)
container: {image: "python:3.5-buster"}
Expand All @@ -64,16 +60,29 @@ linux_mac_task:
container: {image: "python:3.7-buster"}
pip_cache: *pip-cache
install_script: *debian-install
- name: test (Linux - 3.8)
container: {image: "python:3.8-buster"}
pip_cache: *pip-cache
install_script: *debian-install
- name: test (Linux - 3.9)
allow_failures: true # Python version is not stable
container: {image: "python:3.9-rc-buster"}
pip_cache: *pip-cache
install_script: *debian-install
- name: test (Linux - Anaconda)
container: {image: "continuumio/anaconda3:2019.03"}
pip_cache: *pip-cache
install_script: *debian-install
extra_install_script:
- apt-get update
- apt-get install -y --fix-missing gcc python3-dev
# ^ required by a weird conda bug...
# https://cirrus-ci.com/task/5049814234693632?command=test#L251
- name: test (OS X)
osx_instance: {image: "mojave-xcode-10.2"}
osx_instance: {image: "catalina-xcode"}
env:
PYTHON_VERSION: 3.7
# ^ it is important to update this env vars when the default version
# of python in homebrew changes
# ^ update when the default version of python in homebrew changes
PATH: "${HOME}/.local/bin:${HOME}/Library/Python/${PYTHON_VERSION}/bin:/usr/local/opt/python/libexec/bin:${PATH}"
# ^ add user and homebrew paths
PIP_CACHE: "${HOME}/Library/Caches/pip"
Expand All @@ -83,92 +92,89 @@ linux_mac_task:
install_script:
- brew install python gnu-tar
- brew cleanup
<< : *REGULAR_TASK_TEMPLATE
<<: *REGULAR_TASK_TEMPLATE


windows_task:
name: test (Windows)
tools_cache:
folder: 'C:\tools'
fingerprint_script:
- ps: echo "$env:CIRRUS_OS - nuget v5.6.0 - git v2.27.0"
populate_script:
- ps: (mkdir 'C:\tools')
# ^ use parentheses to suppress errors
- ps: Invoke-WebRequest -OutFile 'C:\tools\nuget.exe' 'https://dist.nuget.org/win-x86-commandline/v5.6.0/nuget.exe'
- ps: nuget install GitForWindows -Version 2.27.0 -NonInteractive -OutputDirectory 'C:\tools'
workaround_git_script:
- git config --system core.longpaths true # Fix for windows git checkout problems
clone_script:
# Use custom cloning since otherwise git tags are missing
CMD.exe /C ECHO ON &
IF NOT DEFINED CIRRUS_PR (
git clone --recursive --branch=%CIRRUS_BRANCH% https://x-access-token:%CIRRUS_REPO_CLONE_TOKEN%@github.com/%CIRRUS_REPO_FULL_NAME%.git %CIRRUS_WORKING_DIR% &
git reset --hard %CIRRUS_CHANGE_IN_REPO%
git clone --recursive --branch=%CIRRUS_BRANCH% https://x-access-token:%CIRRUS_REPO_CLONE_TOKEN%@github.com/%CIRRUS_REPO_FULL_NAME%.git %CIRRUS_WORKING_DIR% &
git reset --hard %CIRRUS_CHANGE_IN_REPO%
) ELSE (
git clone --recursive https://x-access-token:%CIRRUS_REPO_CLONE_TOKEN%@github.com/%CIRRUS_REPO_FULL_NAME%.git %CIRRUS_WORKING_DIR% &
git fetch origin pull/%CIRRUS_PR%/head:pull/%CIRRUS_PR% &
git reset --hard %CIRRUS_CHANGE_IN_REPO%
git clone --recursive https://x-access-token:%CIRRUS_REPO_CLONE_TOKEN%@github.com/%CIRRUS_REPO_FULL_NAME%.git %CIRRUS_WORKING_DIR% &
git fetch origin pull/%CIRRUS_PR%/head:pull/%CIRRUS_PR% &
git reset --hard %CIRRUS_CHANGE_IN_REPO%
)
windows_container:
image: "cirrusci/windowsservercore:cmake"
# ^ this image have MSYS2 pre-installed, which means we can use some
# of the GNU tools (like the `rm` command)
image: "python:3.8-windowsservercore"
os_version: 2019
env:
# Single quotes are used bellow to escape Windows backslash and %
# (YAML restrictions).
PYTHON_HOME: 'C:\Python37'
PYTHON_APPDATA: '%APPDATA%\Python\Python37'
# ^ it is important to update these 2 env vars when the default version
# of python in chocolatey changes
MSYS_HOME: 'C:\tools\msys64'
# Single quotes are used bellow to escape Windows backslash and % (YAML restrictions).
PYTHON_HOME: 'C:\Python'
PYTHON_APPDATA: '%APPDATA%\Python\Python38'
# ^ update when python version changes
GIT_HOME: 'C:\tools\GitForWindows.2.27.0\tools'
# ^ update when git version changes
HOME: '%USERPROFILE%'
USERNAME: 'ContainerAdministrator'
# ^ Ensure USERNAME is set in Windows, so the getpass module doesn't
# raise exceptions
ToolsDir: 'C:\tools'
PATH: '%HOME%\.local\bin\;%PYTHON_APPDATA%\Scripts\;%PYTHON_HOME%\;%PYTHON_HOME%\Scripts\;%MSYS_HOME%\bin\;%MSYS_HOME%\usr\bin\;%MSYS_HOME%\usr\local\bin\;%PATH%'
# ^ add user, chocolatey and msys paths
CHOCOLATEY_CACHE: '%LocalAppData%\chocolatey\Cache'
USERNAME: ContainerAdministrator
# ^ ensure USERNAME is set in Windows, so the getpass module doesn't raise exceptions
PATH: '%HOME%\.local\bin\;%PYTHON_APPDATA%\Scripts\;%PYTHON_HOME%\;%PYTHON_HOME%\Scripts\;C:\tools\;%GIT_HOME%\cmd\;%GIT_HOME%\usr\bin\;%PATH%'
# ^ add user paths
PIP_CACHE: '%LocalAppData%\pip\Cache'
PIP_TRUSTED_HOST: 'pypi.org pypi.python.org files.pythonhosted.org'
PIP_CONFIG_FILE: '%AppData%\pip\pip.ini'
COVERAGE: 'NO'
chocolatey_cache:
folder: '%CHOCOLATEY_CACHE%'
pip_cache:
folder: '%PIP_CACHE%'
install_script:
# Activate long file paths to avoid some errors
- REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem /v LongPathsEnabled /t REG_DWORD /d 1 /f
# Set Windows encoding to UTF-8
- REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Command Processor" /v Autorun /t REG_SZ /d "@chcp 65001>nul" /f
- choco config set cacheLocation %CHOCOLATEY_CACHE%
- choco install --no-progress -y python --version 3.7
- python -m pip install -U --user pip setuptools certifi
- python -m pip install -U --user tox pytest-cov pytest-xdist pytest-virtualenv pytest-shutil pytest-fixture-config cookiecutter django
- python -m pip list
prepare_script: *prepare_script
windows_clean_script:
# use parentheses to suppress errors
- ps: (rm junit-*.xml)
- ps: (rm -Recurse -Force .tox)
test_script:
- ps: python -m tox -e all -- --color yes

- python -m ensurepip
- python -m pip install --upgrade --user pip setuptools certifi tox
prepare_script: *prepare
clean_workspace_script:
# Avoid information carried from one run to the other
# CMD is not capable of globbing, so we have to use PowerShell
- ps: (rm -Recurse -Force -ErrorAction SilentlyContinue .tox,junit-*.xml)
test_script: *test
always: *upload-junit


coverage_task:
name: coverage (Linux)
clone_script: *clone_script
clone_script: *clone
container: {image: "python:3.6-buster"}
env:
COVERAGE: yes
COVERAGE: yes
pip_cache: *pip-cache
depends_on:
- test (Linux - 3.6)
- test (Linux - 3.7)
- test (Linux - 3.8)
- test (Linux - Anaconda)
- test (OS X)
- test (Windows)
install_script: *debian-install
pip_install_script:
pip install --user --upgrade
pytest pytest-cov pytest-virtualenv
coverage coveralls
flake8 pre-commit
pip install --user --upgrade coverage coveralls pre-commit
precommit_script:
- pre-commit install
- pre-commit run --all-files
<< : *REGULAR_TASK_TEMPLATE
<<: *REGULAR_TASK_TEMPLATE
coverage_script:
- coverage combine .coverage
- coveralls
12 changes: 3 additions & 9 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[settings]
line_length=79
indent=' '
skip=.tox,.venv,build,dist
known_standard_library=setuptools,pkg_resources
known_test=pytest
known_first_party=pyscaffoldext
sections=FUTURE,STDLIB,COMPAT,TEST,THIRDPARTY,FIRSTPARTY,LOCALFOLDER
default_section=THIRDPARTY
multi_line_output=3
profile = black
extra_standard_library = setuptools
known_first_party = pyscaffoldext
25 changes: 21 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: '^docs/conf.py'

repos:
- repo: git://github.com/pre-commit/pre-commit-hooks
rev: v1.3.0
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand All @@ -16,9 +16,26 @@ repos:
- id: requirements-txt-fixer
- id: mixed-line-ending
args: ['--fix=no']
- id: flake8

- repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.4
- repo: http://github.com/timothycrosley/isort
rev: 5.4.2
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
language_version: python3

- repo: https://github.com/asottile/blacken-docs
rev: v1.8.0
hooks:
- id: blacken-docs
additional_dependencies: [black]

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Contributors

* Simone Robutti <simone.robutti@teraki.com>
* Florian Wilhelm <florian.wilhelm@gmail.com>
* Anderson Bravalheri <andersonbravalheri@gmail.com>
18 changes: 8 additions & 10 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ name = pyscaffoldext-custom-extension
description = PyScaffold extension to create a custom PyScaffold extension
author = Simone Robutti
author-email = simone.robutti@teraki.com
license = mit
license = MIT
url = https://github.com/pyscaffold/pyscaffoldext-custom-extension
project-urls =
Documentation = https://pyscaffoldext-custom-extension.readthedocs.io/
Source = https://github.com/pyscaffold/pyscaffoldext-custom-extension/
Tracker = https://github.com/pyscaffold/pyscaffoldext-custom-extension/issues
Download = https://pypi.org/project/pyscaffoldext-custom-extension/#files
Twitter = https://twitter.com/PyScaffold
long-description = file: README.rst
# Change if running only on Windows, Mac or Linux (comma-separated)
Expand All @@ -23,10 +26,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.4
Programming Language :: Python :: 3.5
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Environment :: Console
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Expand All @@ -46,13 +45,10 @@ install_requires =
pyaml
pyscaffold>=3.2a0,<4.0a0

tests_require = pytest; pytest-cov

[options.entry_points]
pyscaffold.cli =
custom_extension = pyscaffoldext.custom_extension.extension:CustomExtension


[options.packages.find]
where = src
exclude =
Expand Down Expand Up @@ -112,15 +108,17 @@ formats = bdist_wheel

[flake8]
# Some sane defaults for the code style checker flake8
max-line-length = 88
extend-ignore = E203, W503
# ^ Black-compatible
# E203 and W503 have edge cases handled by black
exclude =
.tox
build
dist
.eggs
docs/conf.py

max-line-length = 79

[pyscaffold]
# PyScaffold's parameters when the project was created.
# This will be used when updating. Do not change!
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
Learn more under: https://pyscaffold.org/
"""
import sys
from pkg_resources import VersionConflict, require
from setuptools import setup

from pkg_resources import VersionConflict, require

try:
require('setuptools>=38.3')
require("setuptools>=38.3")
except VersionConflict:
print("Error: version of setuptools is too old (<38.3)!")
sys.exit(1)
Expand Down
2 changes: 1 addition & 1 deletion src/pyscaffoldext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__import__('pkg_resources').declare_namespace(__name__)
__import__("pkg_resources").declare_namespace(__name__)

0 comments on commit 194b7dd

Please sign in to comment.