Skip to content

Commit c0fdb95

Browse files
committed
Use CSV on Python3 and improve CLI help #280
* Use cvs and not backports.csv on Pyhton 3 * Reference .ABOUT files consistently * Enable using -h as a help option shortcut * Improve the help for the main entry point and each command * cleanup the setup.py Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent db4427c commit c0fdb95

File tree

9 files changed

+274
-146
lines changed

9 files changed

+274
-146
lines changed

about.ABOUT

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
about_resource: .
22

3-
name: AboutCode
4-
version: 3.0.0.dev4
3+
name: AboutCode-toolkit
4+
version: 3.0.0.dev6
55

66
owner: nexB Inc.
77
author: Jillian Daguil, Chin Yeung Li, Philippe Ombredanne, Thomas Druez
88

9-
home_url: http://dejacode.org
9+
home_url: https://aboutcode.org
1010

1111
vcs_tool: git
1212
vcs_repository: https://github.com/dejacode/about-code-tool.git

setup.py

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
2+
# -*- encoding: utf-8 -*-
33

44
from __future__ import absolute_import
55
from __future__ import print_function
@@ -10,6 +10,9 @@
1010
from os.path import dirname
1111
from os.path import join
1212
from os.path import splitext
13+
import re
14+
import sys
15+
1316
from setuptools import find_packages
1417
from setuptools import setup
1518

@@ -22,10 +25,10 @@ def read(*names, **kwargs):
2225

2326

2427
setup(
25-
name='attributecode',
26-
version='3.0.0.dev4',
28+
name='aboutcode-toolkit',
29+
version='3.0.0.dev6',
2730
license='Apache-2.0',
28-
description=('Document the provenance (origin and license) of '
31+
description=('AboutCode-toolkit is a tool to d_ocument the provenance (origin and license) of '
2932
'third-party software using small text files. '
3033
'Collect inventories, generate attribution documentation.'),
3134
long_description=('AttributeCode provides a simple way to document the'
@@ -46,19 +49,23 @@ def read(*names, **kwargs):
4649
'Programming Language :: Python',
4750
'Programming Language :: Python :: 2',
4851
'Programming Language :: Python :: 2.7',
52+
'Programming Language :: Python :: 3',
53+
'Programming Language :: Python :: 3.6',
54+
'Intended Audience :: Developers',
4955
'License :: OSI Approved :: Apache Software License',
5056
'Operating System :: OS Independent',
51-
'Intended Audience :: Developers',
5257
'Topic :: Software Development',
5358
'Topic :: Software Development :: Documentation',
5459
'Topic :: Software Development :: Quality Assurance',
5560
'Topic :: System :: Software Distribution',
5661
'Topic :: Utilities',
5762
],
5863
keywords=[
59-
'license', 'about', 'metadata', 'package', 'copyright',
64+
'license', 'about', 'metadata', 'package', 'copyright',
6065
'attribution', 'software', 'inventory',
6166
],
67+
# FIXME: we SHOULD NOT use datafiles!!!! whcih is a mine field but
68+
# only package data or use a MANIFEST.in instead for a sdist
6269
data_files=[('about',
6370
[
6471
'about.ABOUT',
@@ -74,31 +81,17 @@ def read(*names, **kwargs):
7481
'USAGE.rst',
7582
]),
7683
],
77-
78-
entry_points='''
79-
[console_scripts]
80-
about-code=attributecode.cmd:cli
81-
''',
8284
install_requires=[
8385
'jinja2 >= 2.9, < 3.0',
8486
'click >= 6.7, < 7.0',
85-
'backports.csv >= 1.0.5, < 2.0.0',
87+
'backports.csv;python_version<"3.6"',
8688
'pyyaml >= 3.11, < 3.13',
8789
'boolean.py >= 3.5, < 4.0',
8890
'license_expression >= 0.94, < 1.0',
89-
],
90-
91-
extras_require={
92-
'base': [
93-
'certifi',
94-
'setuptools',
95-
'wheel',
96-
'pip',
97-
'wincertstore',
98-
],
99-
'dev': [
100-
'pytest',
101-
'py',
102-
],
103-
}
91+
],
92+
entry_points={
93+
'console_scripts': [
94+
'about-code=attributecode.cmd:cli',
95+
]
96+
},
10497
)

src/attributecode/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
basestring = str # Python 3
2828

2929

30-
__version__ = '3.0.0.dev5'
30+
__version__ = '3.0.0.dev6'
31+
3132

3233
__about_spec_version__ = '2.0.0.dev2'
3334

@@ -44,6 +45,7 @@
4445
limitations under the License.
4546
"""
4647

48+
4749
class Error(namedtuple('Error', ['severity', 'message'])):
4850
"""
4951
An Error data with a severity and message.

src/attributecode/attrib.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
def generate(abouts, template_string=None):
4040
"""
41-
Generate and return attribution text from a list of ABOUT objects and a
41+
Generate and return attribution text from a list of About objects and a
4242
template string.
4343
The returned rendered text may contain template processing error messages.
4444
"""
@@ -127,7 +127,7 @@ def check_template(template_string):
127127

128128
def generate_from_file(abouts, template_loc=None):
129129
"""
130-
Generate and return attribution string from a list of ABOUT objects and a
130+
Generate and return attribution string from a list of About objects and a
131131
template location.
132132
"""
133133
if not template_loc:
@@ -138,12 +138,18 @@ def generate_from_file(abouts, template_loc=None):
138138
return generate(abouts, template_string=tpls)
139139

140140

141-
def generate_and_save(abouts, output_location, use_mapping=False,
141+
def generate_and_save(abouts, output_location, use_mapping=False,
142142
template_loc=None, inventory_location=None):
143143
"""
144-
Generate attribution using template and save at output_location.
145-
Filter the list of about object based on the inventory CSV at
146-
inventory_location.
144+
Generate attribution file using the `abouts` list of About object
145+
at `output_location`.
146+
147+
Use the optional `template_loc` custom temaplte or a default template.
148+
149+
Optionally filter `abouts` object based on the inventory JSON or
150+
CSV at `inventory_location`.
151+
152+
Optionally use the mapping.config file is `use_mapping` is True
147153
"""
148154
updated_abouts = []
149155
lstrip_afp = []
@@ -156,22 +162,28 @@ def generate_and_save(abouts, output_location, use_mapping=False,
156162
# Do the following if an filter list (inventory_location) is provided
157163
else:
158164
if not exists(inventory_location):
159-
msg = (u'"INVENTORY_LOCATOIN" does not exist. Generation halted.')
165+
# FIXME: this message does not make sense
166+
msg = (u'"INVENTORY_LOCATION" does not exist. Generation halted.')
160167
errors.append(Error(ERROR, msg))
161168
return errors
162169

163170
if inventory_location.endswith('.csv') or inventory_location.endswith('.json'):
171+
# FIXME: we should use the same inventory lodaing that we use everywhere!!!!
172+
164173
try:
165174
# Return a list which contains only the about file path
166175
about_list = attributecode.util.get_about_file_path(
167176
inventory_location, use_mapping=use_mapping)
177+
# FIXME: why catching all exceptions?
168178
except Exception:
169179
# 'about_file_path' key/column doesn't exist
180+
170181
msg = u"The required key: 'about_file_path' does not exist. Generation halted."
171182
errors.append(Error(ERROR, msg))
172183
return errors
173184
else:
174-
msg = u'Only .csv and .json are supported for the "INVENTORY_LOCATOIN". Generation halted.'
185+
# FIXME: this message does not make sense
186+
msg = u'Only .csv and .json are supported for the "INVENTORY_LOCATION". Generation halted.'
175187
errors.append(Error(ERROR, msg))
176188
return errors
177189

@@ -225,16 +237,19 @@ def generate_and_save(abouts, output_location, use_mapping=False,
225237

226238
return errors
227239

240+
228241
def as_about_paths(paths):
229242
"""
230-
Given a list of paths, return a list of paths that point all to .ABOUT files.
243+
Return a list of paths to .ABOUT files from a list of `paths`
244+
strings.
231245
"""
232-
normalized_paths = []
246+
about_paths = []
233247
for path in paths:
234248
if path.endswith('.ABOUT'):
235-
normalized_paths.append(path)
249+
about_paths.append(path)
236250
else:
251+
# FIXME: this is not the way to check that a path is a directory, too weak
237252
if path.endswith('/'):
238253
path += basename(dirname(path))
239-
normalized_paths.append(path + '.ABOUT')
240-
return normalized_paths
254+
about_paths.append(path + '.ABOUT')
255+
return about_paths

0 commit comments

Comments
 (0)