From 92a39a3fc68a572080a8a1c9f6bb340d7b925926 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Wed, 8 Aug 2018 21:09:22 +0200 Subject: [PATCH] support python 3.7 fix new pep8 stype --- .travis.yml | 4 +++- CHANGELOG.rst | 1 + openslides/core/config.py | 8 ++++---- .../core/migrations/0008_changed_logo_fields.py | 1 + openslides/motions/projector.py | 2 +- openslides/utils/access_permissions.py | 2 +- openslides/utils/autoupdate.py | 6 +++--- openslides/utils/collection.py | 14 +++++++------- openslides/utils/main.py | 8 ++++---- openslides/utils/models.py | 6 +++--- requirements.txt | 4 +++- requirements_production.txt | 4 ++-- setup.py | 5 +++-- 13 files changed, 36 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6a33b433d..29b18cb04 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,11 +1,13 @@ language: python -sudo: false +dist: xenial +sudo: true cache: pip: true yarn: true python: - "3.5" - "3.6" + - "3.7" env: - TRAVIS_NODE_VERSION="10.5" before_install: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0ca632926..939fbb21e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,7 @@ Motions: - New table of contents with page numbers and categories in PDF [#3766]. - Updated pdfMake to 0.1.37 [#3766]. - Python 3.4 is not supported anymore [#3777]. + - Support Python 3.7. Version 2.2 (2018-06-06) diff --git a/openslides/core/config.py b/openslides/core/config.py index ab1d6921c..e3129eb55 100644 --- a/openslides/core/config.py +++ b/openslides/core/config.py @@ -253,10 +253,10 @@ class ConfigVariable: the value during setup of the database if the admin uses the respective command line option. """ - def __init__(self, name: str, default_value: T, input_type: str='string', - label: str=None, help_text: str=None, choices: ChoiceCallableType=None, - hidden: bool=False, weight: int=0, group: str=None, subgroup: str=None, - validators: ValidatorsType=None, on_change: OnChangeType=None) -> None: + def __init__(self, name: str, default_value: T, input_type: str = 'string', + label: str = None, help_text: str = None, choices: ChoiceCallableType = None, + hidden: bool = False, weight: int = 0, group: str = None, subgroup: str = None, + validators: ValidatorsType = None, on_change: OnChangeType = None) -> None: if input_type not in INPUT_TYPE_MAPPING: raise ValueError(_('Invalid value for config attribute input_type.')) if input_type == 'choice' and choices is None: diff --git a/openslides/core/migrations/0008_changed_logo_fields.py b/openslides/core/migrations/0008_changed_logo_fields.py index 382515aa4..50a4a16d5 100644 --- a/openslides/core/migrations/0008_changed_logo_fields.py +++ b/openslides/core/migrations/0008_changed_logo_fields.py @@ -42,6 +42,7 @@ def move_old_logo_settings(apps, schema_editor): logo_pdf_L = ConfigStore.objects.get(key=new_value_key) except ConfigStore.DoesNotExist: logo_pdf_L = ConfigStore(key=new_value_key) + logo_pdf_L.value = {} # Move the path to the new configentry logo_pdf_L.value['path'] = logo_pdf.value.get('path', '') diff --git a/openslides/motions/projector.py b/openslides/motions/projector.py index 5532d5061..474a611b7 100644 --- a/openslides/motions/projector.py +++ b/openslides/motions/projector.py @@ -43,7 +43,7 @@ class MotionSlide(ProjectorElement): Keep the motion_syntax syncronized with the MotionStateAndRecommendationParser on the client. """ # get the comments field for state and recommendation - motion_syntax = re.compile('\[motion:(\d+)\]') + motion_syntax = re.compile(r'\[motion:(\d+)\]') fields = config['motions_comments'] state_field_id = None recommendation_field_id = None diff --git a/openslides/utils/access_permissions.py b/openslides/utils/access_permissions.py index 02ae09663..c9a83c4d9 100644 --- a/openslides/utils/access_permissions.py +++ b/openslides/utils/access_permissions.py @@ -20,7 +20,7 @@ class BaseAccessPermissions: """ return False - def get_serializer_class(self, user: CollectionElement=None) -> Serializer: + def get_serializer_class(self, user: CollectionElement = None) -> Serializer: """ Returns different serializer classes according to users permissions. diff --git a/openslides/utils/autoupdate.py b/openslides/utils/autoupdate.py index c8c517826..5f926c954 100644 --- a/openslides/utils/autoupdate.py +++ b/openslides/utils/autoupdate.py @@ -374,7 +374,7 @@ def to_ordered_dict(d: Optional[Dict]) -> Optional[OrderedDict]: return result -def inform_changed_data(instances: Union[Iterable[Model], Model], information: Dict[str, Any]=None) -> None: +def inform_changed_data(instances: Union[Iterable[Model], Model], information: Dict[str, Any] = None) -> None: """ Informs the autoupdate system and the caching system about the creation or update of an element. This is done via the AutoupdateBundleMiddleware. @@ -404,7 +404,7 @@ def inform_changed_data(instances: Union[Iterable[Model], Model], information: D bundle[key] = collection_element -def inform_deleted_data(elements: Iterable[Tuple[str, int]], information: Dict[str, Any]=None) -> None: +def inform_deleted_data(elements: Iterable[Tuple[str, int]], information: Dict[str, Any] = None) -> None: """ Informs the autoupdate system and the caching system about the deletion of elements. This is done via the AutoupdateBundleMiddleware. @@ -426,7 +426,7 @@ def inform_deleted_data(elements: Iterable[Tuple[str, int]], information: Dict[s def inform_data_collection_element_list(collection_elements: List[CollectionElement], - information: Dict[str, Any]=None) -> None: + information: Dict[str, Any] = None) -> None: """ Informs the autoupdate system about some collection elements. This is used just to send some data to all users. diff --git a/openslides/utils/collection.py b/openslides/utils/collection.py index a77e16f84..90d75bdd2 100644 --- a/openslides/utils/collection.py +++ b/openslides/utils/collection.py @@ -51,8 +51,8 @@ ChannelMessageFormat = TypedDict( class CollectionElement: - def __init__(self, instance: Model=None, deleted: bool=False, collection_string: str=None, - id: int=None, full_data: Dict[str, Any]=None, information: Dict[str, Any]=None) -> None: + def __init__(self, instance: Model = None, deleted: bool = False, collection_string: str = None, + id: int = None, full_data: Dict[str, Any] = None, information: Dict[str, Any] = None) -> None: """ Do not use this. Use the methods from_instance() or from_values(). """ @@ -86,7 +86,7 @@ class CollectionElement: self.get_full_data() @classmethod - def from_instance(cls, instance: Model, deleted: bool=False, information: Dict[str, Any]=None) -> 'CollectionElement': + def from_instance(cls, instance: Model, deleted: bool = False, information: Dict[str, Any] = None) -> 'CollectionElement': """ Returns a collection element from a database instance. @@ -97,8 +97,8 @@ class CollectionElement: return cls(instance=instance, deleted=deleted, information=information) @classmethod - def from_values(cls, collection_string: str, id: int, deleted: bool=False, - full_data: Dict[str, Any]=None, information: Dict[str, Any]=None) -> 'CollectionElement': + def from_values(cls, collection_string: str, id: int, deleted: bool = False, + full_data: Dict[str, Any] = None, information: Dict[str, Any] = None) -> 'CollectionElement': """ Returns a collection element from a collection_string and an id. @@ -210,7 +210,7 @@ class Collection: Represents all elements of one collection. """ - def __init__(self, collection_string: str, full_data: List[Dict[str, Any]]=None) -> None: + def __init__(self, collection_string: str, full_data: List[Dict[str, Any]] = None) -> None: """ Initiates a Collection. A collection_string has to be given. If full_data (a list of dictionaries) is not given the method @@ -295,7 +295,7 @@ def get_model_from_collection_string(collection_string: str) -> Type[Model]: return model -def format_for_autoupdate(collection_string: str, id: int, action: str, data: Dict[str, Any]=None) -> AutoupdateFormat: +def format_for_autoupdate(collection_string: str, id: int, action: str, data: Dict[str, Any] = None) -> AutoupdateFormat: """ Returns a dict that can be used for autoupdate. """ diff --git a/openslides/utils/main.py b/openslides/utils/main.py index e89bd40fe..6d20240f9 100644 --- a/openslides/utils/main.py +++ b/openslides/utils/main.py @@ -60,7 +60,7 @@ def detect_openslides_type() -> str: return openslides_type -def get_default_settings_dir(openslides_type: str=None) -> str: +def get_default_settings_dir(openslides_type: str = None) -> str: """ Returns the default settings path according to the OpenSlides type. @@ -91,7 +91,7 @@ def get_local_settings_dir() -> str: return os.path.join('personal_data', 'var') -def setup_django_settings_module(settings_path: str =None, local_installation: bool=False) -> None: +def setup_django_settings_module(settings_path: str = None, local_installation: bool = False) -> None: """ Sets the environment variable ENVIRONMENT_VARIABLE, that means 'DJANGO_SETTINGS_MODULE', to the given settings. @@ -131,7 +131,7 @@ def setup_django_settings_module(settings_path: str =None, local_installation: b os.environ[ENVIRONMENT_VARIABLE] = settings_module_name -def get_default_settings_context(user_data_dir: str=None) -> Dict[str, str]: +def get_default_settings_context(user_data_dir: str = None) -> Dict[str, str]: """ Returns the default context values for the settings template: 'openslides_user_data_path', 'import_function' and 'debug'. @@ -227,7 +227,7 @@ def get_win32_portable_user_data_dir() -> str: return os.path.join(get_win32_portable_dir(), 'openslides') -def write_settings(settings_dir: str=None, settings_filename: str='settings.py', template: str=None, **context: str) -> str: +def write_settings(settings_dir: str = None, settings_filename: str = 'settings.py', template: str = None, **context: str) -> str: """ Creates the settings file at the given dir using the given values for the file template. diff --git a/openslides/utils/models.py b/openslides/utils/models.py index 9cbd82e41..725825f74 100644 --- a/openslides/utils/models.py +++ b/openslides/utils/models.py @@ -12,7 +12,7 @@ class MinMaxIntegerField(models.IntegerField): IntegerField with options to set a min- and a max-value. """ - def __init__(self, min_value: int=None, max_value: int=None, *args: Any, **kwargs: Any) -> None: + def __init__(self, min_value: int = None, max_value: int = None, *args: Any, **kwargs: Any) -> None: self.min_value, self.max_value = min_value, max_value super(MinMaxIntegerField, self).__init__(*args, **kwargs) @@ -67,7 +67,7 @@ class RESTModelMixin: """ return self.pk # type: ignore - def save(self, skip_autoupdate: bool=False, information: Dict[str, str]=None, *args: Any, **kwargs: Any) -> Any: + def save(self, skip_autoupdate: bool = False, information: Dict[str, str] = None, *args: Any, **kwargs: Any) -> Any: """ Calls Django's save() method and afterwards hits the autoupdate system. @@ -88,7 +88,7 @@ class RESTModelMixin: inform_changed_data(self.get_root_rest_element(), information=information) return return_value - def delete(self, skip_autoupdate: bool=False, information: Dict[str, str]=None, *args: Any, **kwargs: Any) -> Any: + def delete(self, skip_autoupdate: bool = False, information: Dict[str, str] = None, *args: Any, **kwargs: Any) -> Any: """ Calls Django's delete() method and afterwards hits the autoupdate system. diff --git a/requirements.txt b/requirements.txt index d9f99809d..0d17f1f97 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,9 @@ # Requirements for development and tests in alphabetical order coverage -flake8 +#flake8 +# Use master of flake8 until flake8 3.6 is released that supports python3.7 +git+https://gitlab.com/pycqa/flake8.git isort==4.2.5 mypy fakeredis diff --git a/requirements_production.txt b/requirements_production.txt index 76a2ad433..edd944dc5 100644 --- a/requirements_production.txt +++ b/requirements_production.txt @@ -2,9 +2,9 @@ bleach>=1.5.0,<2.2 channels>=1.1,<1.2 daphne<2 -Django>=1.10.4,<2.1 +Django>=1.10.4,<2.2 djangorestframework>=3.4,<3.9 -jsonfield>=1.0,<2.1 +jsonfield2>=3.0,<3.1 mypy_extensions>=0.3,<0.4 PyPDF2>=1.26,<1.27 roman>=2.0,<3.1 diff --git a/setup.py b/setup.py index af806da83..b769b8d49 100644 --- a/setup.py +++ b/setup.py @@ -28,13 +28,14 @@ setup( # http://pypi.python.org/pypi?%3Aaction=list_classifiers # 'Development Status :: 3 - Alpha', 'Development Status :: 4 - Beta', - #'Development Status :: 5 - Production/Stable', + # 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Framework :: Django', 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', ], + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', ], packages=find_packages(exclude=['tests', 'tests.*']), include_package_data=True, install_requires=install_requires,