Coder Social home page Coder Social logo

flake8-copyright's Introduction

Flake8 Copyright plugin

Checks for copyright notices in all python files. It runs a simple regular expression search for strings like:

Copyright 2014 <author>
Copyright (C) 2014 <author>

<author> can be anything unless you specify it with the copyright-author option (see below).

Install

Install with pip:

pip install flake8-copyright

Then, activate copyright checks in your flake8 configuration with:

copyright-check = True
# C errors are not selected by default, so add them to your selection
select = E,F,W,C

Further options

copyright-min-file-size

Minimum number of characters in a file before requiring a copyright notice. This is to avoid forcing yourself to add copyright notices to very small or empty files. Default: 0.

copyright-author

Checks for a specific author in the copyright notice.

copyright-regexp

If you're not happy with the regexp that is ran to look for copyright notices, you can change it with this option. Default: Copyright\s+(\(C\)\s+)?\d{4}([-,]\d{4})*\s+%(author)s. %(author)s is replaced by the contents of copyright-author.

flake8-copyright's People

Contributors

dobesv avatar dopplershift avatar leon-barrett avatar maximest-pierre avatar mrodriguezg1991 avatar vrigal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flake8-copyright's Issues

Update License

Update License configuration in the repo, so that pylic does not see the license as unknown and then mark it as an unsafe_package.

Unable to run with flake8 3.0.4

I can't get the plugin to flag files where I've removed the copyright notice. This is running on:

3.0.4 (flake8-bugbear: 16.11.0, pycodestyle: 2.0.0, naming: 0.4.1, flake-mutable: 1.0.5, mccabe: 0.5.0, flake8_copyright: 0.2.0, flake8_quotes: 0.8.1, pyflakes: 1.2.3, import-order: 0.11) CPython 3.5.2 on Darwin

I noticed that if I change the entrypoint from flake8_copyright to C80 (matching what the plugins I have working do), I now get a message about a missing copyright statement. Did flake8 3.x change something there?

Exception trace if falek8-copyright is enabled

It seems like the plugin is reporting the error on line 0 which causes this error:

Traceback (most recent call last):
  File "/usr/local/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/flake8/main.py", line 36, in main
    report = flake8_style.check_files()
  File "/usr/local/lib/python2.7/dist-packages/flake8/engine.py", line 181, in check_files
    return self._retry_serial(self._styleguide.check_files, paths=paths)
  File "/usr/local/lib/python2.7/dist-packages/flake8/engine.py", line 172, in _retry_serial
    return func(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pep8.py", line 1842, in check_files
    runner(path)
  File "/usr/local/lib/python2.7/dist-packages/flake8/engine.py", line 126, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File "/usr/local/lib/python2.7/dist-packages/pep8.py", line 1619, in check_all
    return self.report.get_file_results()
  File "/usr/local/lib/python2.7/dist-packages/flake8/reporter.py", line 144, in get_file_results
    line = self.lines[line_number - 1]
IndexError: list index out of range

No support for flake8 3.0

I just tried using this with flake8 3.0.0b1 and got:

Traceback (most recent call last):
  File "/usr/lib64/python3.5/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib64/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/__main__.py", line 4, in <module>
    cli.main()
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/main/application.py", line 292, in run
    self._run(argv)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/main/application.py", line 278, in _run
    self.initialize(argv)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/main/application.py", line 269, in initialize
    self.register_plugin_options()
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/main/application.py", line 149, in register_plugin_options
    self.check_plugins.register_options(self.option_manager)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/plugins/manager.py", line 378, in register_options
    list(self.manager.map(call_register_options))
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/plugins/manager.py", line 252, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/plugins/manager.py", line 348, in generated_function
    return method(optmanager, *args, **kwargs)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8/plugins/manager.py", line 198, in register_options
    add_options(optmanager)
  File "/home/florian/proj/qutebrowser/git/.tox/flake8/lib/python3.5/site-packages/flake8_copyright.py", line 39, in add_options
    parser.config_options.append('copyright-check')
AttributeError: 'OptionManager' object has no attribute 'config_options'

flake8 documentation about the change: http://flake8.pycqa.org/en/latest/plugin-development/cross-compatibility.html#option-handling-on-flake8-2-and-3

Related fixes in pep8-naming:

PyCQA/pep8-naming@b4c3ebd
PyCQA/pep8-naming@dd623fc

plugin code for flake8-copyright does not match regex

Hello,

for information, the plugin is no usable anymore through last flake8 version.
Seems that flake8 have constrained the plugin code possibilities through a regex.
We are going to desactivate flake8-copyright in our software.

Linting flake8 check
There was a critical error during execution of Flake8:
plugin code for `flake8-copyright[flake8_copyright]` does not match ^[A-Z]{1,3}[0-9]{0,3}$

Interested if this bug is resolved
Cordially,
Emmanuel

UnicodeDecodeError error on Windows when dealing with UTF-8 characters

When running flake8-copyright on Windows on files which contain unicode characters, I get the following error:
File "..\lib\site-packages\flake8_copyright.py", line 86, in run top_of_file = open(self.filename).read(toread) File "..\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 5141: character maps to <undefined>
@maximest-pierre

Support a range of years by default

The regex for copyright year would be nice if it would support multiple years, e.g. 2015-2016, or 2011,2012,2013

Could be as simple as looking for \d{4}([-,]\d{4})*.

Obviously, end-users can override this themselves but it would be handy if it was the default.

Problem with flake8 v6.0.0

It appears that the latest flake8 is causing trouble with the flake8-copyright plugin. When we run flake8 we get a stacktrace along these lines:

(fairlearn-39) PS C:\Users\ME\source\repos\fairlearn> flake8 .
Traceback (most recent call last):
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\Scripts\flake8.exe\__main__.py", line 7, in <module>
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8\main\cli.py", line 23, in main
    app.run(argv)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8\main\application.py", line 198, in run
    self._run(argv)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8\main\application.py", line 186, in _run
    self.initialize(argv)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8\main\application.py", line 165, in initialize
    self.plugins, self.options = parse_args(argv)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8\options\parse_args.py", line 51, in parse_args
    option_manager.register_plugins(plugins)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8\options\manager.py", line 259, in register_plugins
    add_options(self)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8_copyright.py", line 56, in add_options
    register_opt(
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8_copyright.py", line 30, in register_opt
    parser.add_option(*args, **kwargs)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\site-packages\flake8\options\manager.py", line 281, in add_option
    self._current_group.add_argument(*option_args, **option_kwargs)
  File "C:\Users\ME\Miniconda3\envs\fairlearn-39\lib\argparse.py", line 1427, in add_argument
    raise ValueError('%r is not callable' % (type_func,))
ValueError: 'int' is not callable

This issue suggests it's a problem with the plugin:
PyCQA/flake8#1760

Doesn't work with flake8 3.5.0

Doesn't work correctly with following file. I don't get any error message for command flake8 --copyright-check dummy_file.py

import numpy as np

a = np.zeros((1, 2, 3))
print(a)

flake8 --version:

$ flake8 --version
3.5.0 (flake8-comprehensions: 1.4.1, flake8-docstrings: 1.3.0, pydocstyle: 2.1.1, flake8_commas: 2.0.0, flake8_copyright: 0.2.0, flake8_quotes: 1.0.0, mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 3.5.2 on Linux

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.