diff --git a/.gitignore b/.gitignore index 88d0060..5bcf01b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,25 +1,26 @@ .idea* .cache +__pycache__ *.py[cod] # C extensions *.so # Packages -*.egg -*.egg-info -dist -build -eggs -parts -bin -var -sdist -develop-eggs +/*.egg +/*.egg-info +/dist +/build +/eggs +/parts +/bin +/var +/sdist +/develop-eggs .installed.cfg -lib -lib64 +/lib +/lib64 # Installer logs pip-log.txt diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..503e3e5 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,57 @@ +#image: pypy:latest +image: registry.gitlab.com/kolanich-subgroups/docker-images/fixed_python:latest +stages: + - dependencies + - build + - test + - trigger + +variables: + DOCKER_DRIVER: overlay2 + SAST_ANALYZER_IMAGE_TAG: latest + SAST_DISABLE_DIND: "true" + +include: + - template: SAST.gitlab-ci.yml + #- template: DAST.gitlab-ci.yml + #- template: License-Management.gitlab-ci.yml + #- template: Container-Scanning.gitlab-ci.yml + #- template: Dependency-Scanning.gitlab-ci.yml + - template: Code-Quality.gitlab-ci.yml + + +build: + tags: + - shared + stage: build + variables: + GIT_DEPTH: "1" + PYTHONUSERBASE: "${CI_PROJECT_DIR}/python_user_packages" + + before_script: + - export PYTHON_MODULES_DIR=${PYTHONUSERBASE}/lib/python3.8 + - export EXECUTABLE_DEPENDENCIES_DIR=${PYTHONUSERBASE}/bin + - export PATH="$PATH:$EXECUTABLE_DEPENDENCIES_DIR" # don't move into `variables` any of them, it is unordered + - mkdir ./wheels + + script: + - python3 ./setup.py bdist_wheel + - mv ./dist/*.whl ./wheels/debparse-0.CI_python-py3-none-any.whl + - pip3 install --upgrade --pre --user ./wheels/debparse-0.CI_python-py3-none-any.whl + - coverage run --source=debparse --branch -m pytest --junitxml=./rspec.xml ./tests/tests.py + - coverage report -m + - coveralls || true + - codecov || true + + coverage: '/^TOTAL\\s+.+?(\\d{1,3}%)$/' + + cache: + paths: + - $PYTHONUSERBASE + + artifacts: + paths: + - wheels + reports: + junit: ./rspec.xml + diff --git a/debparse/api.py b/debparse/api.py index a742bc0..3117685 100644 --- a/debparse/api.py +++ b/debparse/api.py @@ -1,2 +1,2 @@ # coding: utf-8 -from __future__ import unicode_literals + diff --git a/debparse/deb_control/__init__.py b/debparse/deb_control/__init__.py index 04d0585..84bb88a 100644 --- a/debparse/deb_control/__init__.py +++ b/debparse/deb_control/__init__.py @@ -1,5 +1,5 @@ # coding: utf-8 -from __future__ import unicode_literals + from debparse import utils @@ -16,7 +16,7 @@ def parse(path=None, data=None): data = utils.get_file_contents(path) raw_paragraphs = paragraphs.get_raw_paragraphs(data) - parsed_paragraphs = map(paragraphs.parse_paragraph, raw_paragraphs) + parsed_paragraphs = list(map(paragraphs.parse_paragraph, raw_paragraphs)) return classes.ControlData( _raw=data, _path=path, diff --git a/debparse/deb_control/classes.py b/debparse/deb_control/classes.py index 8f9cf24..236a3eb 100644 --- a/debparse/deb_control/classes.py +++ b/debparse/deb_control/classes.py @@ -1,5 +1,5 @@ # coding: utf-8 -from __future__ import unicode_literals + import collections @@ -12,11 +12,13 @@ class Stub(object): valid_attribures = ANY def __init__(self, *args, **kwargs): - for key, value in kwargs.items(): + new_kwargs = type(kwargs)() + for key, value in list(kwargs.items()): if self.valid_attribures == ANY or key in self.valid_attribures: - kwargs.pop(key) setattr(self, key, value) - super(Stub, self).__init__(*args, **kwargs) + else: + new_kwargs[key] = value + super(Stub, self).__init__(*args, **new_kwargs) def __repr__(self): return '<%s: %s>' % ( @@ -61,7 +63,7 @@ class Package(Stub, collections.OrderedDict): ) def __getitem__(self, item): - if not isinstance(item, basestring): + if not isinstance(item, str): raise TypeError(item) for key in self: if item.lower() == key.lower(): @@ -69,7 +71,7 @@ def __getitem__(self, item): raise KeyError(item) def _repr_data(self): - return str(self.keys()) + return str(list(self.keys())) @property def type(self): diff --git a/debparse/deb_control/fields.py b/debparse/deb_control/fields.py index 218f953..0c150cb 100644 --- a/debparse/deb_control/fields.py +++ b/debparse/deb_control/fields.py @@ -1,5 +1,5 @@ # coding: utf-8 -from __future__ import unicode_literals + import re import logging @@ -57,7 +57,7 @@ def get_raw_key_value(data): def lookup_field_spec(key): - for canonical_name, spec in FIELDS.items(): + for canonical_name, spec in list(FIELDS.items()): if key.lower() == canonical_name.lower(): return canonical_name, spec return 'Unknown', 'single/simple' @@ -106,15 +106,14 @@ def parse_field_type_simple(raw_value, meta=None): text=raw_value ) - +personRx = re.compile(r"^\s*(.+)\s*(?:<\s*([^>]+?)\s*>)?\s*$") def parse_field_type_contact(raw_value, meta=None): - name, email = raw_value.rsplit(' ', 1) - parsed_email = email.strip('<>') + name, email = personRx.match(raw_value).groups() return classes.ContactField( _raw=raw_value, meta=meta, name=name, - email=parsed_email, + email=email, ) diff --git a/debparse/deb_control/paragraphs.py b/debparse/deb_control/paragraphs.py index 4758fa0..5a9a183 100644 --- a/debparse/deb_control/paragraphs.py +++ b/debparse/deb_control/paragraphs.py @@ -3,7 +3,7 @@ About debian control file format read https://www.debian.org/doc/debian-policy/ch-controlfields.html """ -from __future__ import unicode_literals + from debparse import utils @@ -40,7 +40,7 @@ def get_raw_paragraphs(data): if lines_buffer: raw_paragraphs.append(lines_buffer) - return map(utils.join_string_list_with_newline, raw_paragraphs) + return list(map(utils.join_string_list_with_newline, raw_paragraphs)) def parse_paragraph(data): @@ -49,7 +49,7 @@ def parse_paragraph(data): Each paragraph consists of a series of data fields. """ raw_fields = get_raw_fields(data) - parsed_fields = map(fields.parse_field, raw_fields) + parsed_fields = list(map(fields.parse_field, raw_fields)) return classes.Package( parsed_fields, _raw=data, @@ -82,7 +82,7 @@ def get_raw_fields(data): if lines_buffer: raw_fields.append(lines_buffer) - return map(utils.join_string_list_with_space, raw_fields) + return list(map(utils.join_string_list_with_space, raw_fields)) diff --git a/debparse/utils.py b/debparse/utils.py index 7a1d98a..de297e7 100644 --- a/debparse/utils.py +++ b/debparse/utils.py @@ -1,5 +1,5 @@ # coding: utf-8 -from __future__ import unicode_literals + import codecs diff --git a/setup.cfg b/setup.cfg index 0a8df87..c50d0cb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,34 @@ +[metadata] +name = debparse +version = 0.1.0 +author = Kirill Sibirev +author_email = l0kix2@gmail.com +license = BSD +description = Parse and inspect debian source files +keywords = debparse +url = https://github.com/l0kix2/debparse +long_description = file: README.rst, HISTORY.rst +classifiers = + Development Status :: 2 - Pre-Alpha + Intended Audience :: Developers + License :: OSI Approved :: BSD License + Natural Language :: English + Programming Language :: Python :: 2 + Programming Language :: Python :: 2.6 + Programming Language :: Python :: 2.7 + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.3 + Programming Language :: Python :: 3.4 + +[options] +packages = debparse +zip_safe = False +install_requires = +include_package_data = True +tests_require = pytest; ipdb + +[options.extras_require] +tests = pytest; ipdb + [wheel] -universal = 1 \ No newline at end of file +universal = 1 diff --git a/setup.py b/setup.py index b4e34ed..57e6ccd 100755 --- a/setup.py +++ b/setup.py @@ -1,61 +1,5 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- +#!/usr/bin/env python3 +from setuptools import setup - -try: - from setuptools import setup -except ImportError: - from distutils.core import setup - - -with open('README.rst') as readme_file: - readme = readme_file.read() - -with open('HISTORY.rst') as history_file: - history = history_file.read().replace('.. :changelog:', '') - -requirements = [ - # TODO: put package requirements here -] - -test_requirements = [ - 'pytest', - 'ipdb', -] - -setup( - name='debparse', - version='0.1.0', - description="Parse and inspect debian source files", - long_description=readme + '\n\n' + history, - author="Kirill Sibirev", - author_email='l0kix2@gmail.com', - url='https://github.com/l0kix2/debparse', - packages=[ - 'debparse', - ], - package_dir={'debparse': - 'debparse'}, - include_package_data=True, - install_requires=requirements, - license="BSD", - zip_safe=False, - keywords='debparse', - classifiers=[ - 'Development Status :: 2 - Pre-Alpha', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Natural Language :: English', - "Programming Language :: Python :: 2", - 'Programming Language :: Python :: 2.6', - 'Programming Language :: Python :: 2.7', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.3', - 'Programming Language :: Python :: 3.4', - ], - test_suite='tests', - tests_require=test_requirements, - extras_require={ - 'tests': test_requirements, - } -) +if __name__ == "__main__": + setup(use_scm_version=True)