diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index aa1b08d..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1,17 +0,0 @@ - -include AUTHORS.rst - -include CONTRIBUTING.rst -include HISTORY.rst -include LICENSE -include README.rst - -recursive-include changelogs/custom/pypi * -recursive-include changelogs/custom/npm * -recursive-include changelogs/custom/gem * - -recursive-include tests * -recursive-exclude * __pycache__ -recursive-exclude * *.py[co] - -recursive-include docs *.rst conf.py Makefile make.bat *.jpg *.png *.gif diff --git a/changelogs/changelogs.py b/changelogs/changelogs.py index cabbb97..951f8f9 100644 --- a/changelogs/changelogs.py +++ b/changelogs/changelogs.py @@ -2,7 +2,7 @@ import functools import subprocess from tempfile import mkdtemp -import imp +from importlib.util import module_from_spec, spec_from_file_location import requests import os import re @@ -30,7 +30,7 @@ def _load_custom_functions(vendor, name): functions = {} # Some packages have dash in their name, replace them with underscore # E.g. python-ldap to python_ldap - filename = "{}.py".format(name.replace("-", "_").lower()) + filename = f"{name.replace('-', '_').lower()}.py" path = os.path.join( os.path.dirname(os.path.realpath(__file__)), # current working dir "custom", # /dir/parser @@ -38,12 +38,19 @@ def _load_custom_functions(vendor, name): filename # /dir/parser/pypi/django.py ) if os.path.isfile(path): - module_name = "parser.{vendor}.{name}".format(vendor=vendor, name=name) - module = imp.load_source(module_name, path) - functions = dict( - (function, getattr(module, function, None)) for function in ALLOWED_CUSTOM_FUNCTIONS + module_name = f"parser.{vendor}.{name}" + spec = spec_from_file_location(module_name, path) + if spec is None or spec.loader is None: + return functions + + module = module_from_spec(spec) + spec.loader.exec_module(module) + + functions = { + function: getattr(module, function) + for function in ALLOWED_CUSTOM_FUNCTIONS if hasattr(module, function) - ) + } return functions @@ -235,7 +242,7 @@ def get_limited_content_entry(session, url, chars_limit): # Avoid https://github.com/psf/requests/issues/3359 if not resp.encoding: resp.encoding = 'utf-8' - limited_content = resp.iter_content(chunk_size=chars_limit, + limited_content = resp.iter_content(chunk_size=chars_limit, decode_unicode=True).__next__() except StopIteration: pass @@ -280,11 +287,11 @@ def get_content(session, urls, chars_limit): else: content += "\n\n" + get_limited_content_entry(session, url, chars_limit) - + # To avoid exceeding the content limit by accumulation if len(content) > chars_limit: - break - + break + except requests.ConnectionError: pass return content diff --git a/changelogs/cli.py b/changelogs/cli.py index b6395bb..0dbab05 100644 --- a/changelogs/cli.py +++ b/changelogs/cli.py @@ -15,6 +15,8 @@ def main(): action="store_true") parser.add_argument("-c", "--commits", help="", action="store_true") + parser.add_argument("-r", "--reverse", help="list changelogs from older to newer", action="store_false") + parser.add_argument("-n", help="only show the n first results (defaults to all)", type=int) args = parser.parse_args() if args.verbose: @@ -25,7 +27,7 @@ def main(): else: data = changelogs.get(args.package, vendor=args.vendor) - for release in sorted(data.keys(), key=lambda v: parse(v), reverse=True): + for release in sorted(data.keys(), key=lambda v: parse(v), reverse=args.reverse)[:args.n]: print(release) print(data[release]) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..fd895fa --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,80 @@ +[build-system] +requires = ["setuptools>=69"] +build-backend = "setuptools.build_meta" + +[project] +name = "changelogs" +version = "0.15.1-dev" +description = "A changelog finder and parser." +requires-python = ">=3.6" +authors = [ + { name = "pyup.io", email = "support@pyup.io" } +] +# readme = { file = ["README.rst", "HISTORY.rst"], content-type = "text/x-rst" } +readme = "README.rst" +license = "MIT" +license-files=["LICENSE", "AUTHORS.rst"] +keywords = ["changelogs"] +classifiers = [ + 'Development Status :: 2 - Pre-Alpha', + 'Intended Audience :: Developers', + 'Natural Language :: English', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', +] + +dependencies = [ + "requests", + "validators", + "packaging", + "lxml", + "gitchangelog", +] + +[project.scripts] +changelogs = "changelogs.cli:main" + +[project.urls] +Homepage = "https://github.com/pyupio/changelogs" + +[project.optional-dependencies] +test = [ + "mock", + "pytest", + "pytest-cov", + "betamax", + "betamax-serializers", +] + +dev = [ + "mock", + "pytest", + "pytest-cov", + "betamax", + "betamax-serializers", + "flake8", + "tox", +] + +[tool.setuptools.packages.find] +include = ["changelogs*"] + +[tool.setuptools.package-data] +changelogs = [ + "custom/pypi/**/*", + "custom/npm/**/*", + "custom/gem/**/*", +] + +[tool.flake8] +exclude = [ + "docs", + ".*", + "vcr", + "*.egg-info", + "build", + "dist", +] +max-line-length = 110 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 3ae0258..0000000 --- a/setup.cfg +++ /dev/null @@ -1,12 +0,0 @@ -[bdist_wheel] -universal = 1 - -[flake8] -exclude = - docs - .* - vcr - *.egg-info - build - dist -max-line-length = 110 diff --git a/setup.py b/setup.py deleted file mode 100644 index f73f907..0000000 --- a/setup.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from setuptools import setup - -with open('README.rst') as readme_file: - readme = readme_file.read() - -with open('HISTORY.rst') as history_file: - history = history_file.read() - -requirements = [ - 'requests', - 'validators', - 'packaging', - 'lxml', - 'gitchangelog' -] - -test_requirements = [ - 'mock', - 'pytest', - 'pytest-cov', - 'betamax', - 'betamax-serializers' -] - -dev_requirements = test_requirements + [ - 'flake8', - 'tox', -] - -extras_requirements = { - 'test': test_requirements, - 'dev': dev_requirements, -} - -setup( - name='changelogs', - version='0.15.1-dev', - description="A changelog finder and parser.", - long_description_content_type='text/x-rst', - long_description=readme + '\n\n' + history, - author="pyup.io", - author_email='support@pyup.io', - url='https://github.com/pyupio/changelogs', - packages=[ - 'changelogs', - ], - package_dir={'changelogs': - 'changelogs'}, - entry_points={ - 'console_scripts': [ - 'changelogs=changelogs.cli:main' - ] - }, - include_package_data=True, - install_requires=requirements, - license="MIT license", - zip_safe=False, - keywords='changelogs', - classifiers=[ - 'Development Status :: 2 - Pre-Alpha', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Natural Language :: English', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - ], - test_suite='tests', - tests_require=test_requirements, - extras_require=extras_requirements, -)