Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vdurm introduction #31

Open
wants to merge 3 commits into
base: vdurm_master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

376 changes: 256 additions & 120 deletions Introduction/Python_basic_with_numpy/Python Basics With Numpy v3.ipynb

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions Introduction/python_highlighter/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Oleksii

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
95 changes: 95 additions & 0 deletions Introduction/python_highlighter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Highlighter
===

Sample Python application that demonstrate the possibility to find and mark text sequence in web page

## Table of contents

- [Before you go](#before-you-go)
- [Install](#install)
- [How to un](#how-to-run)
- [Tests](#tests)
- [Code style check](#code-style-check)
- [TODO](#todo)

## Before you go

Before to go you should set up your local environment.

- Fork repository by clicking the **Fork** button on the upper right-hand side of the repository’s page. See an example [here](https://help.github.com/en/articles/fork-a-repo#fork-an-example-repository) **NOTE!** All actions described below **MUST** be applied to the **!!!FORKED!!!** repository!!!
- Clone forked repository to your local system ([hint](https://help.github.com/en/articles/fork-a-repo#step-2-create-a-local-clone-of-your-fork)).
- Go to the project' directory

```buildoutcfg
cd python_highlighter
```


## Install

To install dependencies run:

```buildoutcfg
pip install -r requirements.txt
```

(Optionally) install highlighter:

```buildoutcfg
pip install -e .
```

## How to run

To run highlighter app (On Windows use **set** instead of **export**):
```buildoutcfg
export FLASK_APP=highlighter
flask run
```

then go to [localhost:5000](localhost:5000)

![image](example.png)

## Tests
The application contains tests. To run tests:
```buildoutcfg
pytest -v
```

## Code style check
Code **must** satisfy [PEP008](https://www.python.org/dev/peps/pep-0008/) code style requirements

```buildoutcfg
pylint -r y **/*.py
```
## TODO

**NOTE**
Before to start your work you must should perform all steps described in [Before you go](#before-you-go) section.

<span style="color:red">**CAUTION** All actions described below **MUST** be applied to the **!!!FORKED!!!** repository!!!</span>

Next, perform steps below:

- Create **dev** branch. You can do it either via Pycharm' menu (see the Pycharm how to for details) or via terminal like this:
```buildoutcfg
git checkout master
git pull
git checkout -b dev
```
- Add an implementation to methods in the **\_\_init__.py** module that covers the demands
- markup_text
- highlight_text
- Add tests to the implemented methods in the **tests/test_highlighter.py** module. You can find examples of tests on [Flask testing howto](http://flask.pocoo.org/docs/1.0/testing/) page.
- Run tests
- Run code check
- Commit and push your local changes to the remote **git** repository. You can do it either via Pycharm view (**Ctrl + K**) or via terminal
```buildoutcfg
git commit -a -m 'type your commit message here'
git push origin dev
```
- Create **MR** (merge request). See how to do it [here](https://docs.gitlab.com/ee/gitlab-basics/add-merge-request.html)
- Add @onidzelskyi as a collaborator with write access rights.
- Send the link to the **MR** to your reviewer

Binary file added Introduction/python_highlighter/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions Introduction/python_highlighter/highlighter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Flask module
file: __init__.py
date: 12.12.2012
author [email protected]
license: MIT"""

from flask import Flask, render_template, request, Markup


def create_app():

app = Flask(__name__)

template_file_name = 'index.html'

@app.route('/', methods=['GET'])
def index():
return render_template(template_file_name)

@app.route('/', methods=['POST'])
def process():
search_text = request.form['search']
text = request.form['text']
highlighted_text = highlight_text(text, search_text)
result = {'text': text,
'highlighted_text': Markup(highlighted_text),
}
return render_template(template_file_name, **result)

def markup_text(text):
"""Markup given text.
This is supplementary method that helps you to wrap marked text in tags.
@:param text - string text to be marked
@:return marked text, e.g., <mark>highlighted text</mark>."""
result = text

# TODO: add an implementation
result = "<mark>{}</mark>".format(text)
return result

def highlight_text(text, expr):
"""Markup searched string in given text.
@:param text - string text to be processed (e.g., 'The sun in the sky')
@:param expr - string pattern to be searched in the text (e.g., 'th')
@:return marked text, e.g., "<mark>Th</mark>e sun in <mark>th</mark>e sky"."""
result = text

# TODO: add an implementation
mc = set(re.findall(expr, text, flags=re.IGNORECASE))
for i in mc:

result = re.sub(i, markup_text(i), result)

return result

return app
Binary file not shown.
25 changes: 25 additions & 0 deletions Introduction/python_highlighter/highlighter/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<html>
<body>
<form action="http://localhost:5000/" method="POST">
<table cellspacing=24>
<tr>
<td>
<p>Search string <input type="text" name="search" onchange="this.form.submit()"/></p>
</td>
<td>
</td>
</tr>
<tr>
<td>
<p><textarea rows="40" cols="50" name="text" style="width: 400px; height: 400px;">{{ text }}</textarea></p>
</td>
<td style="vertical-align: top; text-align: justify">
<div style="width: 400px; height: 400px;">
<p>{{ highlighted_text }}</p>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
2 changes: 2 additions & 0 deletions Introduction/python_highlighter/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask>=1.0
pytest
12 changes: 12 additions & 0 deletions Introduction/python_highlighter/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import find_packages, setup

setup(
name='highlighter',
version='1.0.0',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=[
'flask',
],
)
Binary file not shown.
36 changes: 36 additions & 0 deletions Introduction/python_highlighter/tests/test_highlighter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Test module
file: test_highlighter.py
date: 12.12.2012
author [email protected]
license: MIT"""

import unittest
from highlighter import create_app


class HighlightTest(unittest.TestCase):
"""Test class for flask app."""

def setUp(self):
"""This method is called each time the test routine run"""
self.app = create_app().test_client()
# TODO: add the missing test data in this routine
self.highlighted_text = b'Sample <mark>text</mark> to be highlighted'
self.search_text = b'Text'
self.text = b'Sample text to be highlighted'

def tearDown(self):
"""This method is called after the test routine is finished
to clear out the data created in setUp method."""
# TODO: add an implementation
del self.app
del self.highlighted_text
del self.text
del self.search_text


def test_markup_text(self):
"""Test markup process"""
response = self.app.post('/', data={'search': self.search_text,
'text': self.text})
self.assertIn(self.highlighted_text, response.data)