Skip to content

Commit ee4581b

Browse files
authored
Merge pull request #37 from creativecommons/fix-lint-issues
Fix lint issues (reformat with black and fix flake8 errors)
2 parents 3e0ea21 + 844b9f6 commit ee4581b

File tree

6 files changed

+102
-89
lines changed

6 files changed

+102
-89
lines changed

.flake8

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[flake8]
2+
exclude =
3+
.git,
4+
base-images,
5+
www

pyproject.toml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.black]
2+
line-length = 79
3+
exclude = '''
4+
/(
5+
\.git
6+
| \base-images
7+
| \www
8+
)/
9+
'''

scripts/cc/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__import__('pkg_resources').declare_namespace(__name__)
1+
__import__("pkg_resources").declare_namespace(__name__)

scripts/cc/image_tools/imgsplat.py

+50-45
Original file line numberDiff line numberDiff line change
@@ -19,62 +19,67 @@
1919
NS_FOAF = Namespace("http://xmlns.com/foaf/0.1/")
2020

2121
MONEY = {
22-
'at': 'euro',
23-
'be': 'euro',
24-
'fi': 'euro',
25-
'de': 'euro',
26-
'es': 'euro',
27-
'fr': 'euro',
28-
'gr': 'euro',
29-
'ie': 'euro',
30-
'it': 'euro',
31-
'lu': 'euro',
32-
'nl': 'euro',
33-
'pt': 'euro'}
22+
"at": "euro",
23+
"be": "euro",
24+
"fi": "euro",
25+
"de": "euro",
26+
"es": "euro",
27+
"fr": "euro",
28+
"gr": "euro",
29+
"ie": "euro",
30+
"it": "euro",
31+
"lu": "euro",
32+
"nl": "euro",
33+
"pt": "euro",
34+
}
3435

3536

3637
def checkout_base():
3738
"""Return the base destination path. Note that this assumes you're
3839
running the tool from a Subversion checkout (or that your filesystem
3940
layout is the same as our repository)."""
4041

41-
4242
return os.path.abspath(
43-
os.path.join(os.path.dirname(__file__), '..', '..', '..')
44-
)
43+
os.path.join(os.path.dirname(__file__), "..", "..", "..")
44+
)
45+
4546

4647
def load_graph(filename):
4748
"""Load the specified filename; return a graph."""
4849

4950
store = Graph()
5051
store.bind("cc", "http://creativecommons.org/ns#")
5152
store.bind("dc", "http://purl.org/dc/elements/1.1/")
52-
store.bind("dcq","http://purl.org/dc/terms/")
53-
store.bind("rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#")
53+
store.bind("dcq", "http://purl.org/dc/terms/")
54+
store.bind("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
5455

5556
store.load(filename)
5657

5758
return store
5859

60+
5961
def copyto(source, dest, code, size, jurisdiction, money=MONEY):
6062
# Make the destination directory, if necessary
6163
dest_dir = os.path.dirname(dest)
62-
if (not os.access(dest_dir, os.F_OK)):
64+
if not os.access(dest_dir, os.F_OK):
6365
os.makedirs(dest_dir)
6466

6567
# If NC (and not the 80x15 icon), use the appropriate currency icon.
66-
if ((string.find(code, 'nc') != -1
67-
and money.has_key(jurisdiction)
68-
and size != '80x15'
69-
and not 'somerights1' in source)):
70-
source += '_' + money[jurisdiction]
68+
if (
69+
string.find(code, "nc") != -1
70+
and jurisdiction in money
71+
and size != "80x15"
72+
and "somerights1" not in source
73+
):
74+
source += "_" + money[jurisdiction]
7175

72-
source += '.png'
76+
source += ".png"
7377

7478
try:
7579
shutil.copy2(source, dest)
76-
except:
77-
print 'Failed to copy '+source+' to '+dest
80+
except: # noqa: E722 (FIXME)
81+
# Flake8 lint runs via Python 3 so skip following E999
82+
print "Failed to copy", source, "to", dest # noqa: E999
7883

7984

8085
def splat(license_graph):
@@ -84,34 +89,34 @@ def splat(license_graph):
8489
for s, p, logo in license_graph.triples((uri, NS_FOAF.logo, None)):
8590
# Get the dest_path, which is base-images and
8691
# everything after 'http://i.creativecommons.org/'
87-
dest_path = os.path.join(
88-
checkout_base(), 'www', str(logo)[29:])
92+
dest_path = os.path.join(checkout_base(), "www", str(logo)[29:])
8993

9094
m = re.search(
91-
'^http://i.creativecommons.org/'
92-
'(?P<group>l|p)/'
93-
'(?P<code>.*?)/'
94-
'((?P<version>.*?)/'
95-
'((?P<jurisdiction>.*?)/)?)?'
96-
'(?P<size>.*)\.png$', str(logo))
97-
98-
code = m.group('code')
99-
jurisdiction = m.group('jurisdiction')
100-
size = m.group('size')
95+
"^http://i.creativecommons.org/"
96+
"(?P<group>l|p)/"
97+
"(?P<code>.*?)/"
98+
"((?P<version>.*?)/"
99+
"((?P<jurisdiction>.*?)/)?)?"
100+
r"(?P<size>.*)\.png$",
101+
str(logo),
102+
)
103+
104+
code = m.group("code")
105+
jurisdiction = m.group("jurisdiction")
106+
size = m.group("size")
101107

102108
code2 = code
103-
if (code == 'by-nd-nc'):
104-
code2 = 'by-nc-nd'
105-
elif code in ('nc', 'nd', 'sa', 'nd-nc', 'nc-sa'):
106-
code2 = 'somerights1'
109+
if code == "by-nd-nc":
110+
code2 = "by-nc-nd"
111+
elif code in ("nc", "nd", "sa", "nd-nc", "nc-sa"):
112+
code2 = "somerights1"
107113

108-
source = os.path.join(
109-
checkout_base(), 'base-images', size, code2)
114+
source = os.path.join(checkout_base(), "base-images", size, code2)
110115

111116
copyto(source, dest_path, code, size, jurisdiction)
112117

113118

114119
def cli():
115120
"""imgsplat command line interface."""
116121

117-
splat(load_graph('http://creativecommons.org/licenses/index.rdf'))
122+
splat(load_graph("http://creativecommons.org/licenses/index.rdf"))

scripts/genicons.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import cairo
1616
import gi
1717

18-
gi.require_version("PangoCairo", "1.0") # noqa: E402
19-
from gi.repository import PangoCairo as pangocairo
18+
gi.require_version("PangoCairo", "1.0")
19+
from gi.repository import PangoCairo as pangocairo # noqa: E402
2020

2121

2222
SUITES = {

scripts/setup.py

+35-41
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
# Copyright (c) 2007 Nathan R. Yergler, Creative Commons
2-
3-
## Permission is hereby granted, free of charge, to any person obtaining
4-
## a copy of this software and associated documentation files (the "Software"),
5-
## to deal in the Software without restriction, including without limitation
6-
## the rights to use, copy, modify, merge, publish, distribute, sublicense,
7-
## and/or sell copies of the Software, and to permit persons to whom the
8-
## Software is furnished to do so, subject to the following conditions:
9-
10-
## The above copyright notice and this permission notice shall be included in
11-
## all copies or substantial portions of the Software.
12-
13-
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18-
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19-
## DEALINGS IN THE SOFTWARE.
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining
4+
# a copy of this software and associated documentation files (the "Software"),
5+
# to deal in the Software without restriction, including without limitation
6+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7+
# and/or sell copies of the Software, and to permit persons to whom the
8+
# Software is furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
# DEALINGS IN THE SOFTWARE.
2020

2121
from setuptools import setup
2222

2323
setup(
24-
name = "cc.image_tools",
25-
version = "1.0",
26-
packages = ['cc.image_tools'],
27-
28-
entry_points = {'console_scripts' :
29-
['imgsplat = cc.image_tools.imgsplat:cli',
30-
]
31-
},
32-
33-
install_requires = ['setuptools',
34-
'rdflib<3.0',
35-
],
36-
37-
include_package_data = True,
38-
zip_safe = True,
39-
40-
author = 'Mike Linksvayer',
41-
author_email = 'ml@creativecommons.org',
42-
description = 'Tools for managing i.creativecommons.org.',
43-
license = 'MIT',
44-
url = 'http://wiki.creativecommons.org/Developer',
45-
46-
)
24+
name="cc.image_tools",
25+
version="1.0",
26+
packages=["cc.image_tools"],
27+
entry_points={
28+
"console_scripts": [
29+
"imgsplat = cc.image_tools.imgsplat:cli",
30+
] # (increase line length for black/flake8 harmony)
31+
},
32+
install_requires=["setuptools", "rdflib<3.0",], # noqa: E231
33+
include_package_data=True,
34+
zip_safe=True,
35+
author="Mike Linksvayer",
36+
author_email="ml@creativecommons.org",
37+
description="Tools for managing i.creativecommons.org.",
38+
license="MIT",
39+
url="http://wiki.creativecommons.org/Developer",
40+
)

0 commit comments

Comments
 (0)