-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ryan-rs/feature/ASC-457/implement_flake8_p…
…lugin ASC-457 Enforce Python Filename Formatting
- Loading branch information
Showing
22 changed files
with
712 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Config file for automatic testing at travis-ci.org | ||
|
||
language: python | ||
python: | ||
- 3.6 | ||
- 3.5 | ||
- 3.4 | ||
- 2.7 | ||
|
||
# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors | ||
install: pip install -U tox-travis | ||
|
||
# Command to run tests, e.g. python setup.py test | ||
script: tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
======= | ||
History | ||
======= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include CONTRIBUTING.rst | ||
include HISTORY.rst | ||
include LICENSE | ||
include README.rst | ||
|
||
recursive-include tests * | ||
recursive-exclude * __pycache__ | ||
recursive-exclude * *.py[co] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
.PHONY: clean clean-test clean-pyc clean-build clean-venv check-venv help install-editable | ||
.DEFAULT_GOAL := help | ||
|
||
SHELL := /bin/bash | ||
export VIRTUALENVWRAPPER_PYTHON := /usr/bin/python | ||
|
||
define BROWSER_PYSCRIPT | ||
import os, webbrowser, sys | ||
|
||
try: | ||
from urllib import pathname2url | ||
except: | ||
from urllib.request import pathname2url | ||
|
||
webbrowser.open("file://" + pathname2url(os.path.abspath(sys.argv[1]))) | ||
endef | ||
export BROWSER_PYSCRIPT | ||
|
||
define PRINT_HELP_PYSCRIPT | ||
import re, sys | ||
|
||
for line in sys.stdin: | ||
match = re.match(r'^([a-zA-Z_-]+):.*?## (.*)$$', line) | ||
if match: | ||
target, help = match.groups() | ||
print("%-20s %s" % (target, help)) | ||
endef | ||
export PRINT_HELP_PYSCRIPT | ||
|
||
BROWSER := python -c "$$BROWSER_PYSCRIPT" | ||
|
||
help: | ||
@python -c "$$PRINT_HELP_PYSCRIPT" < $(MAKEFILE_LIST) | ||
|
||
check-venv: ## verify that the user is running in a Python virtual environment | ||
@if [ -z "$(VIRTUALENVWRAPPER_SCRIPT)" ]; then echo 'Python virtualenvwrapper not installed!' && exit 1; fi | ||
@if [ -z "$(VIRTUAL_ENV)" ]; then echo 'Not running within a virtual environment!' && exit 1; fi | ||
|
||
clean: clean-build clean-pyc clean-test ## remove all build, test, coverage, artifacts and wipe virtualenv | ||
|
||
clean-build: ## remove build artifacts | ||
rm -fr build/ | ||
rm -fr dist/ | ||
rm -fr .eggs/ | ||
find . -name '*.egg-info' -exec rm -fr {} + | ||
find . -name '*.egg' -exec rm -f {} + | ||
|
||
clean-pyc: ## remove Python file artifacts | ||
find . -name '*.pyc' -exec rm -f {} + | ||
find . -name '*.pyo' -exec rm -f {} + | ||
find . -name '*~' -exec rm -f {} + | ||
find . -name '__pycache__' -exec rm -fr {} + | ||
|
||
clean-test: ## remove test and coverage artifacts | ||
rm -fr .tox/ | ||
rm -f .coverage | ||
rm -fr htmlcov/ | ||
rm -fr .pytest_cache/ | ||
|
||
clean-venv: uninstall check-venv ## remove all packages from current virtual environment | ||
@source virtualenvwrapper.sh && wipeenv || echo "Skipping wipe of environment" | ||
|
||
lint: ## check style with flake8 | ||
flake8 flake8_filename setup.py tests --ignore N | ||
|
||
test: ## run tests quickly with the default Python | ||
py.test | ||
|
||
test-all: ## run tests on every Python version with tox | ||
tox | ||
|
||
install: clean build uninstall ## install the package to the active Python's site-packages | ||
pip install dist/*.whl | ||
|
||
install-editable: ## install the package in editable mode | ||
if pip list -e | grep 'flake8-filename'; then echo 'Editable package already installed'; else pip install -e .; fi | ||
|
||
install-dev-requirements: ## install the requirements for development | ||
pip install -r requirements.txt | ||
|
||
develop: clean install-dev-requirements install-editable ## install necessary packages to setup a dev environment | ||
|
||
build: ## build a wheel | ||
python setup.py bdist_wheel | ||
|
||
publish: ## publish package to PyPI | ||
twine upload dist/*.whl | ||
|
||
bump-major: ## bumps the version of by major | ||
bumpversion major | ||
|
||
bump-minor: ## bumps the version of by minor | ||
bumpversion minor | ||
|
||
bump-patch: ## bumps the version of by patch | ||
bumpversion patch | ||
|
||
uninstall: ## remove this package | ||
pip uninstall flake8-filename -y || echo 'flake8-filename not installed' | ||
|
||
release-major: install-dev-requirements bump-major lint install test publish ## package and upload a major release | ||
echo 'Successfully released!' | ||
echo 'Please push the newly created tag and commit to GitHub.' | ||
|
||
release-minor: install-dev-requirements bump-minor lint install test publish ## package and upload a minor release | ||
echo 'Successfully released!' | ||
echo 'Please push the newly created tag and commit to GitHub.' | ||
|
||
release-patch: install-dev-requirements bump-patch lint install test publish ## package and upload a patch release | ||
echo 'Successfully released!' | ||
echo 'Please push the newly created tag and commit to GitHub.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
=============== | ||
flake8-filename | ||
=============== | ||
|
||
.. image:: https://img.shields.io/travis/rcbops/flake8-filename.svg | ||
:target: https://travis-ci.org/rcbops/flake8-filename | ||
|
||
A flake8 linter plug-in for validating that certain Python files comply with a user defined pattern. | ||
|
||
Quick Start Guide | ||
----------------- | ||
|
||
1. Install ``flake8-filename`` from PyPI with pip:: | ||
|
||
$ pip install flake8-filename | ||
|
||
2. Configure a mark that you would like to validate:: | ||
|
||
$ cd project_root/ | ||
$ vi .flake8 | ||
|
||
.. code-block:: ini | ||
[flake8] | ||
filename_check1 = filter_regex=test_.+ | ||
filename_regex=test_[\w-]+$ | ||
3. Run flake8:: | ||
|
||
$ flake8 tests/ | ||
|
||
Gotchas | ||
------- | ||
|
||
1. It is highly recommended to use this plugin inside of a virtualenv | ||
2. A configuration is required by this plugin, if none is found the plugin will throw a N401 validation error for every file | ||
|
||
Violation Codes | ||
--------------- | ||
|
||
All possible violation codes are documented in violation_codes_ | ||
|
||
|
||
Example Configurations | ||
---------------------- | ||
|
||
More example configurations can be found in configuration_ | ||
|
||
Credits | ||
------- | ||
|
||
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template. | ||
|
||
.. _CONTRIBUTING.rst: CONTRIBUTING.rst | ||
.. _configuration: docs/configuration.rst | ||
.. _violation_codes: docs/violation_codes.rst | ||
.. _Cookiecutter: https://github.com/audreyr/cookiecutter | ||
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flake8>=3.5.0 | ||
pip<10.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
============= | ||
Configuration | ||
============= | ||
|
||
Location | ||
======== | ||
The flake8-filename plug-in loads its configuration options from the same source as standard flake8 configuration. | ||
Flake8 supports storing its configuration in the following places: | ||
|
||
Your top-level user directory In your project in one of ``setup.cfg``, ``tox.ini``, or ``.flake8``.For more information | ||
on configuration locations see: | ||
|
||
Flake8_configuration_ | ||
|
||
Configuration | ||
============= | ||
You may configure up to 50 filename validators. | ||
|
||
+---------------------+----------------------------------------------+-------------------------------------------------+ | ||
| Param Name + Valid Argument + Explanation + | ||
+=====================+==============================================+=================================================+ | ||
| filter_regex + any valid regex that does not contain spaces + A regex to filter on certain Python files | | ||
+---------------------+----------------------------------------------+-------------------------------------------------+ | ||
| filename_regex + any valid regex that does not contain spaces | A regex to validate filtered Python filenames | | ||
+---------------------+----------------------------------------------+-------------------------------------------------+ | ||
|
||
**This plug-in will automatically strip the leading path and extension for the Python files under evaluation.** | ||
|
||
Examples: | ||
========= | ||
All examples assume running against the following test file. | ||
|
||
|
||
**test_example.py** : An example pytest:: | ||
|
||
def test_thing(): | ||
pass | ||
|
||
**.flake8** : A simple configuration to validate that Python files that begin with "test\_" have "fun" in the name:: | ||
|
||
[flake8] | ||
filename_check1 = filter_regex=test_.+ | ||
filename_regex=test_fun.* | ||
|
||
**Shell Output** : evaluate if the filename contains "fun":: | ||
|
||
./test_example.py:1:1: N501 filename failed regex validation 'test_fun.*' | ||
|
||
.. _Flake8_configuration: http://flake8.pycqa.org/en/latest/user/configuration.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[flake8] | ||
filename_check1 = filter_regex=test_.+ | ||
filename_regex=test_[\w-]+$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
=============== | ||
Release Process | ||
=============== | ||
|
||
The easiest way to release a new version of flake8-filename is to use make. | ||
|
||
1. First you will need to know the username and password for the account you want to use to release to PyPI shared_accounts_ | ||
|
||
2. You will need to make sure that you are on the master branch, your working directory is clean and up to date. | ||
|
||
3. Decide if you are going to increment the major, minor, or patch version. You can refer to semver_ to help you make that decision. | ||
|
||
4. Use the `release-major`, `release-minor`, or `release-patch`. | ||
|
||
**make release** :: | ||
|
||
make release-minor | ||
|
||
5. The task will stop and prompt you for your PyPI username and password if you don't have these set in your `.pypirc` file. | ||
|
||
6. Once the task has successfully completed you need to push the tag and commit. | ||
|
||
**push tag** :: | ||
|
||
git push origin && git push origin refs/tags/<tagname> | ||
|
||
7. Create a release on GitHub. GitHub_release_ | ||
|
||
.. _semver: https://semver.org | ||
.. _shared_accounts: https://rpc-openstack.atlassian.net/wiki/spaces/ASC/pages/143949893/Useful+Links#UsefulLinks-SharedAccounts | ||
.. _GitHub_release: https://help.github.com/articles/creating-releases/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Error / Violation Codes | ||
======================= | ||
|
||
flake8-filename is a flake8 plugin that validates that certain Python files comply with a user defined pattern. | ||
All error codes generated by this plugin begin with N. Here are all possible codes: | ||
|
||
+---------------------------------------------------------------------------------------------------------+ | ||
| Code | Example Message | | ||
+======+==================================================================================================+ | ||
| N401 + no configuration found ... please provide filename configuration in a flake8 config | | ||
+------+--------------------------------------------------------------------------------------------------+ | ||
| N5XX | filename fails user defined regex pattern | | ||
+------+--------------------------------------------------------------------------------------------------+ | ||
|
||
The codes referenced in the table above that end in XX are configurable. Up to 50 instances may be created. |
Oops, something went wrong.