diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml new file mode 100644 index 00000000..876005b1 --- /dev/null +++ b/.github/workflows/python.yml @@ -0,0 +1,34 @@ +name: Python package + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + cd ./python + pip install -r requirements.txt + - name: Lint with flake8 + run: | + cd ./python + flake8 ./ + - name: Lint with MyPy + run: | + cd ./python + mypy ./ + - name: Test with unittest + run: | + cd ./python + python -m unittest diff --git a/python/.flake8 b/python/.flake8 new file mode 100644 index 00000000..4b473c63 --- /dev/null +++ b/python/.flake8 @@ -0,0 +1,3 @@ +[flake8] +ignore = E722 +max-line-length = 128 diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 00000000..c792544c --- /dev/null +++ b/python/.gitignore @@ -0,0 +1,206 @@ +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf +*.out + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/python/.vscode/launch.json b/python/.vscode/launch.json new file mode 100644 index 00000000..0a5c8097 --- /dev/null +++ b/python/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python: Текущий файл", + "type": "python", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} diff --git a/python/.vscode/settings.json b/python/.vscode/settings.json new file mode 100644 index 00000000..2597cbc4 --- /dev/null +++ b/python/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "python.linting.pylintEnabled": false, + "python.linting.mypyEnabled": false, + "python.linting.enabled": true, + "python.linting.lintOnSave": true, + "python.linting.flake8Enabled": true, +} diff --git a/python/Pipfile b/python/Pipfile new file mode 100644 index 00000000..0f6a6f34 --- /dev/null +++ b/python/Pipfile @@ -0,0 +1,19 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] +mypy = "*" +flake8 = "*" + +[requires] +python_version = "3.9" + +[scripts] +start = "python ./src/main.py" +test = "python -m unittest" +lint = "flake8 ./" +lintMyPy = "mypy ./" diff --git a/python/Pipfile.lock b/python/Pipfile.lock new file mode 100644 index 00000000..f3145ef9 --- /dev/null +++ b/python/Pipfile.lock @@ -0,0 +1,106 @@ +{ + "_meta": { + "hash": { + "sha256": "4894b22932cc8c76e138c68198ce54cb057a7f4b391476c15e3e05d193ceb7f7" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.9" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": {}, + "develop": { + "flake8": { + "hashes": [ + "sha256:6fbe320aad8d6b95cec8b8e47bc933004678dc63095be98528b7bdd2a9f510db", + "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248" + ], + "index": "pypi", + "version": "==5.0.4" + }, + "mccabe": { + "hashes": [ + "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325", + "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e" + ], + "markers": "python_version >= '3.6'", + "version": "==0.7.0" + }, + "mypy": { + "hashes": [ + "sha256:1021c241e8b6e1ca5a47e4d52601274ac078a89845cfde66c6d5f769819ffa1d", + "sha256:14d53cdd4cf93765aa747a7399f0961a365bcddf7855d9cef6306fa41de01c24", + "sha256:175f292f649a3af7082fe36620369ffc4661a71005aa9f8297ea473df5772046", + "sha256:26ae64555d480ad4b32a267d10cab7aec92ff44de35a7cd95b2b7cb8e64ebe3e", + "sha256:41fd1cf9bc0e1c19b9af13a6580ccb66c381a5ee2cf63ee5ebab747a4badeba3", + "sha256:5085e6f442003fa915aeb0a46d4da58128da69325d8213b4b35cc7054090aed5", + "sha256:58f27ebafe726a8e5ccb58d896451dd9a662a511a3188ff6a8a6a919142ecc20", + "sha256:6389af3e204975d6658de4fb8ac16f58c14e1bacc6142fee86d1b5b26aa52bda", + "sha256:724d36be56444f569c20a629d1d4ee0cb0ad666078d59bb84f8f887952511ca1", + "sha256:75838c649290d83a2b83a88288c1eb60fe7a05b36d46cbea9d22efc790002146", + "sha256:7b35ce03a289480d6544aac85fa3674f493f323d80ea7226410ed065cd46f206", + "sha256:85f7a343542dc8b1ed0a888cdd34dca56462654ef23aa673907305b260b3d746", + "sha256:86ebe67adf4d021b28c3f547da6aa2cce660b57f0432617af2cca932d4d378a6", + "sha256:8ee8c2472e96beb1045e9081de8e92f295b89ac10c4109afdf3a23ad6e644f3e", + "sha256:91781eff1f3f2607519c8b0e8518aad8498af1419e8442d5d0afb108059881fc", + "sha256:a692a8e7d07abe5f4b2dd32d731812a0175626a90a223d4b58f10f458747dd8a", + "sha256:a705a93670c8b74769496280d2fe6cd59961506c64f329bb179970ff1d24f9f8", + "sha256:c6e564f035d25c99fd2b863e13049744d96bd1947e3d3d2f16f5828864506763", + "sha256:cebca7fd333f90b61b3ef7f217ff75ce2e287482206ef4a8b18f32b49927b1a2", + "sha256:d6af646bd46f10d53834a8e8983e130e47d8ab2d4b7a97363e35b24e1d588947", + "sha256:e7aeaa763c7ab86d5b66ff27f68493d672e44c8099af636d433a7f3fa5596d40", + "sha256:eaa97b9ddd1dd9901a22a879491dbb951b5dec75c3b90032e2baa7336777363b", + "sha256:eb7a068e503be3543c4bd329c994103874fa543c1727ba5288393c21d912d795", + "sha256:f793e3dd95e166b66d50e7b63e69e58e88643d80a3dcc3bcd81368e0478b089c" + ], + "index": "pypi", + "version": "==0.982" + }, + "mypy-extensions": { + "hashes": [ + "sha256:090fedd75945a69ae91ce1303b5824f428daf5a028d2f6ab8a299250a846f15d", + "sha256:2d82818f5bb3e369420cb3c4060a7970edba416647068eb4c5343488a6c604a8" + ], + "version": "==0.4.3" + }, + "pycodestyle": { + "hashes": [ + "sha256:2c9607871d58c76354b697b42f5d57e1ada7d261c261efac224b664affdc5785", + "sha256:d1735fc58b418fd7c5f658d28d943854f8a849b01a5d0a1e6f3f3fdd0166804b" + ], + "markers": "python_version >= '3.6'", + "version": "==2.9.1" + }, + "pyflakes": { + "hashes": [ + "sha256:4579f67d887f804e67edb544428f264b7b24f435b263c4614f384135cea553d2", + "sha256:491feb020dca48ccc562a8c0cbe8df07ee13078df59813b83959cbdada312ea3" + ], + "markers": "python_version >= '3.6'", + "version": "==2.5.0" + }, + "tomli": { + "hashes": [ + "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc", + "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f" + ], + "markers": "python_version < '3.11'", + "version": "==2.0.1" + }, + "typing-extensions": { + "hashes": [ + "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa", + "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e" + ], + "markers": "python_version >= '3.7'", + "version": "==4.4.0" + } + } +} diff --git a/python/README.md b/python/README.md new file mode 100644 index 00000000..a3948147 --- /dev/null +++ b/python/README.md @@ -0,0 +1,54 @@ +# Работа с проектом + +`vscode` при старте предложит установить рекомендованныек расширения - с ним лучше согласиться. + + +## Настройка окружения + +### Python + +Установите `python` для соответствующей операционной системы. + +**ВАЖНО** + +При установке в windows - укажите галочку - добавить python в переменную окружения `PATH` + +### Pipenv + +Мы используем виртуальное окружение `pipenv`, для его установки используйте следующую команду: + +```shell +pip install pipenv +``` +Установку требуется сделать только 1 раз, активацию - каждый раз когда вы перезапускаете терминал. + + +Для активации виртуального окружения следует выполнить следующую команду, при этом выполнять ее нужно в каталоге текущего проекта `python` (рядом с текущим `README.md` файлом и содержит `Pipfile`) + +``` +pipenv shell +``` + +После этого необходимо установить зависимости, указанные в `pipenv` файле + + + +После установки pipenv при использовании `vscode` следует выбрать версию интерпретатора, привязанный к проекту. Для этого можно выполнить следующую последовательность действий. Настраивать требуется только 1 раз при настройке виртуального окружения. + +- Нажать комбинацию клавиш `ctrl-shift-p` +- Начать писать `Reload window` +- Начать писать `Python select interpreter` +- Выбрать на уровне рабочей области +- Найти свое окружение, скорее всего в его имени в скобках будет указано `(python-"НАБОР_СИМВОЛОВ")` + +Ваше рабочее окружение настроено и можете его иcпользовать. + +### Доступные команды + +Команды проверок, запускаемые в `github actions` можно также запустить локально выполнением одной из следующих команд + +```shell +pipenv run test +pipenv run lint +pipenv run lintMyPy +``` \ No newline at end of file diff --git a/python/informatics.code-workspace b/python/informatics.code-workspace new file mode 100644 index 00000000..9c3d46e1 --- /dev/null +++ b/python/informatics.code-workspace @@ -0,0 +1,19 @@ +{ + "folders": [ + { + "path": "." + }, + ], + "settings": { + "files.exclude": { + "**/.git": true, + }, + "editor.tabSize": 4, + }, + "extensions": { + "recommendations": [ + "ms-python.python", + "eamodio.gitlens" + ] + } +} diff --git a/python/requirements.txt b/python/requirements.txt new file mode 100644 index 00000000..84a6f385 --- /dev/null +++ b/python/requirements.txt @@ -0,0 +1,18 @@ +astroid==3.0.3 +colorama==0.4.6 +dill==0.3.8 +flake8==7.0.0 +isort==5.13.2 +lazy-object-proxy==1.10.0 +mccabe==0.7.0 +mypy==1.8.0 +mypy-extensions==1.0.0 +platformdirs==4.2.0 +pycodestyle==2.11.1 +pyflakes==3.2.0 +pylint==3.0.3 +tomli==2.0.1 +tomlkit==0.12.3 +typed-ast==1.5.5 +typing_extensions==4.9.0 +wrapt==1.16.0 diff --git a/python/src/__init__.py b/python/src/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/python/src/lab_6/document.py b/python/src/lab_6/document.py new file mode 100644 index 00000000..b36357bb --- /dev/null +++ b/python/src/lab_6/document.py @@ -0,0 +1,80 @@ +# Kozlov Egor 1/278; Variant 11 + +class Document: + def __init__(self, path: str, docType: str, docSize: int): + if not isinstance(path, str): + raise TypeError("path must be str") + + if not isinstance(docType, str): + raise TypeError("docType must be str") + + self.__documentPath = path + self.__documentType = docType + self.documentSize = docSize + + @property + def documentPath(self) -> str: + return self.__documentPath + + @property + def documentType(self) -> str: + return self.__documentType + + @property + def documentSize(self) -> int: + return self.__documentSize + + @documentSize.setter + def documentSize(self, value) -> None: + if not isinstance(value, int): + raise TypeError("docSize must be int") + + if value < 0: + raise ValueError(value) + + self.__documentSize = value + + def __str__(self) -> str: + return f"Document: '{self.documentPath}', '{self.documentType}', {self.documentSize}" + + +if __name__ == "__main__": + print("Test 1") + instance = Document("/media/Files/Script.docx", "docx", 32000) + + print("Test 2") + try: + Document(32, "docx", 32000) # type: ignore + except Exception as e: + print("Catched:", e) + + print("Test 3") + try: + Document("/media/Files/Script.docx", 128, 32000) # type: ignore + except Exception as e: + print("Catched:", e) + + print("Test 4") + try: + Document("/media/Files/Script.docx", "docx", "32000") # type: ignore + except Exception as e: + print("Catched:", e) + + print("Test 5") + try: + Document("/media/Files/Script.docx", "docx", -10) + except Exception as e: + print("Catched:", e) + + print(str(instance)) + + instance.documentSize = 1600 + + print(str(instance)) + + try: + instance.documentSize = -18 + except Exception as e: + print("Catched:", e) + + print(str(instance)) diff --git a/python/tests/__init__.py b/python/tests/__init__.py new file mode 100644 index 00000000..e69de29b