Skip to content

Commit

Permalink
addressing #1
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsb42 committed Oct 9, 2017
1 parent 3321cb2 commit b0679c6
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
5 changes: 3 additions & 2 deletions park.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
author: Matt Bullock
author_email: matt.s.b.42@gmail.com
url: https://github.com/mattsb42/pypi-parker
version: 0.0.1
version: 0.0.9
license: Apache License 2.0
description:
description: parked
long_description:
This package is parked by {author} to protect against typo misdirection.
See {url} for more information.
Did you mean to install "pypi-parker"?
Expand Down
25 changes: 17 additions & 8 deletions src/pypi_parker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
__all__ = ('load_config',)
FALLBACK_VALUES = dict(
classifiers=['Development Status :: 7 - Inactive'],
description=(
'This package has been parked either for future use or to protect against typo misdirection.'
' If you believe that it has been parked in error, please contact the package owner.'
description='parked using pypi-parker',
long_description=(
'This package has been parked either for future use or to protect against typo misdirection.\n'
'If you believe that it has been parked in error, please contact the package owner.'
)
)
STRING_LITERAL_KEYS = ('classifiers',)
Expand All @@ -30,9 +31,14 @@ def _update_description(setup_base: SETUP_CONFIG) -> None:
try:
description_keys = _string_literal_to_lines(setup_base.pop('description_keys'))
description_setup = {key: str(setup_base[key]) for key in description_keys} # type: Dict[str, str]
setup_base['description'] = str(setup_base['description']).format(**description_setup)
except KeyError:
pass
return

for field in ('description', 'long_description'):
try:
setup_base[field] = str(setup_base[field]).format(**description_setup)
except KeyError:
pass


def _update_string_literal_values(setup_base: SETUP_CONFIG) -> None:
Expand All @@ -46,13 +52,13 @@ def _update_string_literal_values(setup_base: SETUP_CONFIG) -> None:

def _update_fallback_values(setup_base: SETUP_CONFIG) -> None:
"""Update ``setup_base`` with fallback values."""
if 'long_description' not in setup_base and 'description' in setup_base:
setup_base['long_description'] = setup_base['description']

for key, value in FALLBACK_VALUES.items():
if key not in setup_base:
setup_base[key] = value

if 'long_description' not in setup_base:
setup_base['long_description'] = setup_base['description']


def _generate_setup(config: configparser.ConfigParser, name: str) -> SETUP_CONFIG:
"""Generate a ``setuptools.setup`` call for ``name`` from ``config``.
Expand All @@ -74,6 +80,9 @@ def _generate_setup(config: configparser.ConfigParser, name: str) -> SETUP_CONFI
_update_string_literal_values(setup_base)
_update_fallback_values(setup_base)

if len(setup_base['description'].splitlines()) > 1:
raise ValueError('Package "description" must be a single line.')

return setup_base


Expand Down
9 changes: 7 additions & 2 deletions test/functional/test_f_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def test_generate_setup(name):
@pytest.mark.parametrize('name', TEST_PACKAGE_NAMES)
def test_load_config(name):
loaded_configs = [i for i in config.load_config(os.path.join(HERE, 'vectors', 'park.cfg'))]
print(loaded_configs)
print(read_setup_config(name))

assert read_setup_config(name) in loaded_configs


def test_load_config_newline_in_description():
with pytest.raises(ValueError) as excinfo:
[i for i in config.load_config(os.path.join(HERE, 'vectors', 'bad_description.cfg'))]

excinfo.match(r'Package "description" must be a single line.')
2 changes: 1 addition & 1 deletion test/functional/vectors/another-test-package.setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "pypi-parker",
"author_email": "park-email@example-url.co.net",
"url": "example-url.co.net",
"description": "This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.",
"description": "parked using pypi-parker",
"long_description": "\nWoo!\nOverriding the long description but not the short description.",
"classifiers": ["another thing", "thing 1"],
"version": "3.1.4"
Expand Down
4 changes: 2 additions & 2 deletions test/functional/vectors/another-test-package.setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

args = ' '.join(sys.argv).strip()
if not any(args.endswith(suffix) for suffix in ['setup.py check -r -s', 'setup.py sdist']):
raise ImportError('This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.',)
raise ImportError('parked using pypi-parker',)

setup(
author='pypi-parker',
author_email='park-email@example-url.co.net',
classifiers=['another thing', 'thing 1'],
description='This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.',
description='parked using pypi-parker',
long_description='\nWoo!\nOverriding the long description but not the short description.',
name='another-test-package',
url='example-url.co.net',
Expand Down
11 changes: 11 additions & 0 deletions test/functional/vectors/bad_description.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[DEFAULT]
version: 3.1.4
author: pypi-parker
author_email: park-email@example-url.co.net
url: example-url.co.net
description:
multiple
lines

[names]
my-test-package:
4 changes: 2 additions & 2 deletions test/functional/vectors/my-test-package.setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"author": "pypi-parker",
"author_email": "park-email@example-url.co.net",
"url": "example-url.co.net",
"description": "This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.",
"long_description": "This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.",
"description": "parked using pypi-parker",
"long_description": "This package has been parked either for future use or to protect against typo misdirection.\nIf you believe that it has been parked in error, please contact the package owner.",
"classifiers": ["Development Status :: 7 - Inactive"],
"version": "3.1.4"
}
6 changes: 3 additions & 3 deletions test/functional/vectors/my-test-package.setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

args = ' '.join(sys.argv).strip()
if not any(args.endswith(suffix) for suffix in ['setup.py check -r -s', 'setup.py sdist']):
raise ImportError('This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.',)
raise ImportError('parked using pypi-parker',)

setup(
author='pypi-parker',
author_email='park-email@example-url.co.net',
classifiers=['Development Status :: 7 - Inactive'],
description='This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.',
long_description='This package has been parked either for future use or to protect against typo misdirection. If you believe that it has been parked in error, please contact the package owner.',
description='parked using pypi-parker',
long_description='This package has been parked either for future use or to protect against typo misdirection.\nIf you believe that it has been parked in error, please contact the package owner.',
name='my-test-package',
url='example-url.co.net',
version='3.1.4'
Expand Down

0 comments on commit b0679c6

Please sign in to comment.