Skip to content

iKostanOrg/codewars

Repository files navigation

Python3 solutions for codewars problems

Document PNG

Main Build Pipeline GitHub commit activity Documentation Status Netlify Status CircleCI codecov CodeFactor Codacy Badge Maintainability Test Coverage Maintenance GitHub repo size GitHub last commit Micro badge

About Codewars

Codewars is a collective effort by its users. They are creators - authoring kata to teach various techniques, solving kata with solutions that enlighten others, and commenting with constructive feedback. The leaders among them moderate the content and community.

Difficulty

My profile on Codewars

My Codewars Profile

8 - 7 kyu │ Beginner
6 - 5 kyu │ Novice
4 - 3 kyu │ Competent
2 - 1 kyu │ Proficient
1 - 5 dan │ Expert
5 - 8 dan │ Master

Note: For each completed kata, there is a corresponding unittest file.

Dev Environment

  1. Python 3.12.3
  2. PyTest
  3. Allure Framework
  4. Win 10 (64 bit)
  5. PyCharm 2024.1.1 (Community Edition)
  6. GitHub Desktop
  7. GIT 2.39.1.windows.1

Python Packages

No. Package Description Link
1

Full list of dependencies see here.

Online Documentation

Python3 solutions for codewars problems’s documentation is built with Sphinx using a theme provided by Read the Docs.

Sphinx is a tool that makes it easy to create intelligent and beautiful documentation, written by Georg Brandl and licensed under the BSD license.

Online version of the latest tech documentation

Allure Report

Allure is based on standard xUnit results output but adds some supplementary data. Any report is generated in two steps. During test execution (first step), a small library called adapter attached to the testing framework saves information about executed tests to XML files.

During report generation (second step), the XML files are transformed to a HTML report. This can be done with a command line tool, a plugin for CI or a build tool.

Online version of the latest Allure report

Tech Issues and Problem Solving

Changing the project interpreter in the PyCharm project settings
  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Project | Project Interpreter.

  2. Expand the list of the available interpreters and click the Show All link.

  3. Select the target interpreter. When PyCharm stops supporting any of the outdated Python versions, the corresponding project interpreter is marked as unsupported.

  4. The Python interpreter name specified in the Name field, becomes visible in the list of available interpreters. Click OK to apply the changes.

For more info please check here

PyCharm - Choosing Your Testing Framework
  1. Open the Settings/Preferences dialog, and under the node Tools, click the page Python Integrated Tools.

  2. On this page, click the Default Test Runner field.

  3. Choose the desired test runner:

choosing_test_runner

For more info please see Enable Pytest for you project

Setting up Python3 virtual environment on Windows machine
  1. open CMD
  2. navigate to project directory, for example: bash cd C:\Users\superadmin\Desktop\Python\CodinGame
  3. run following command: bash pip install virtualenv
  4. run following command: bash virtualenv venv --python=python
Setting up Python3 virtual environment on Linx (Ubuntu) machine

How to install virtualenv

  1. Install pip first: bash sudo apt-get install python3-pip
  2. Then install virtualenv using pip3: bash sudo pip3 install virtualenv
  3. Now create a virtual environment (>you can use any name instead of venv): bash virtualenv venv
  4. You can also use a Python interpreter of your choice: bash virtualenv -p /usr/bin/python2.7 venv
  5. Active your virtual environment: bash source venv/bin/activate
  6. Using fish shell: bash source venv/bin/activate.fish
  7. To deactivate: bash deactivate
  8. Create virtualenv using Python3: bash virtualenv -p python3 myenv
  9. Instead of using virtualenv you can use this command in Python3: bash python3 -m venv myenv

Source

Activate Virtual Environment

In a newly created virtualenv there will be a bin/activate shell script. For Windows systems, activation scripts are provided for CMD.exe and Powershell.

  1. Open Terminal
  2. Run: \path\to\env\Scripts\activate

Source

Auto generate requirements.txt

Any application typically has a set of dependencies that are required for that application to work. The requirements file is a way to specify and install specific set of package dependencies at once.

Use pip’s freeze command to generate a requirements.txt file for your project:

pip freeze > requirements.txt

If you save this in requirements.txt, you can follow this guide: PyCharm - Manage dependencies using requirements.txt, or you can:

pip install -r requirements.txt

Source

error: RPC failed; curl 56 Recv failure: Connection was reset
  1. Open Git Bash
  2. Run: "git config --global http.postBuffer 157286400"

Source

How to fix in case .gitignore is ignored by Git

Even if you haven't tracked the files so far, Git seems to be able to "know" about them even after you add them to .gitignore

NOTE:

  • First commit your current changes, or you will lose them.
  • Then run the following commands from the top folder of your Git repository:
git rm -r --cached .
git add .
git commit -m "fixed untracked files"
Scoop: a command-line installer for Windows

Installation instructions:

Open a PowerShell terminal (version 5.1 or later) and from the PS C:> prompt:

  1. Set the execution policy:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

[Source](https://scoop.sh/#/)
</details>

<details>
    <summary>Install Allure Report for Windows</summary>

Install from [Scoop](https://scoop.sh/#/):

1. Make sure Scoop is installed. See [the installation instructions on GitHub](https://github.com/ScoopInstaller/Install#readme).
2. Make sure `Java version 8 or higher` installed, and its directory is specified
   in the `JAVA_HOME` environment variable.
3. In a terminal, run this command: `scoop install allure`
4. Run this command to see if it reports the latest version: `allure --version`

[Source](https://allurereport.org/docs/install-for-windows/)
</details>

<details>
  <summary>How to generate Allure report with history trends (Windows OS)</summary>

Step by step:

1. Run tests from pytest using following arguments:
   `-v --alluredir=allure-results`
2. Copy '.\allure-report\history\' folder into '.\allure-results\history\'
3. Run:
   `allure generate .\allure-results\ -o .\allure-report\ --clean`
4. Following output should appear:
   `Report successfully generated to .\allure-report`
5. Run: 
   `allure open .\allure-report\`

[Source](https://github.com/allure-framework/allure2/issues/813)
</details>

<details>
  <summary>Sphinx Documentation Set Up</summary>

Step by step:

1. Create docs directory.
2. Open cmd > Go to docs directory.
3. cmd > Run: `sphinx-quickstart`. **Note:** run with default answers.
4. Go to `docs/conf.py`.
5. Uncomment following lines: 
```python
import os
import sys
sys.path.insert(0, os.path.abspath('.'))
  1. Update extensions list as following:
extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc']
  1. Update template as following:
html_theme = 'sphinx_rtd_theme'
  1. Update sys.path.insert as following:
sys.path.insert(0, os.path.abspath('..'))
  1. Go to docs/index.rst > add modules, see example below:
.. toctree::
  :maxdepth: 2
  :caption: Contents:
    
  modules
  1. Open cmd > run:
sphinx-apidoc -F -o . ..
  1. cmd > Run:
make html
  1. Install html template:
pip install sphinx_rtd_theme

More info:

Auto-Generated Python Documentation with Sphinx

Step by step:

  1. Open CMD
  2. Go to docs directory
  3. Run: make clean
  4. Run: sphinx-apidoc -F -P -o . ..
  5. Add doc files name into relevant doc rst file
  6. Run: make html

Source

Read-the-docs build fails with “cannot import name 'PackageFinder' from 'pip._internal.index'

The issue and the fix are described in read-the-docs issue #6554:

The fix is to wipe out the build environment as follows (this is taken from here):

  • Log in to read-the-docs
  • Go to Versions
  • Click on the Edit button of the version you want to wipe on the right side of the page
  • Go to the bottom of the page and click the wipe link, next to the “Save” button
  • Now you can re-build the version with a fresh build environment!

This fix worked for me (but as of 26-Jan-2020 you have to wipe out the environment for every build, see comment from Grimmy below).

Source

How to use requirements.txt to install all dependencies in a python project
  1. Run pip install -r requirements.txt
  2. Run pip freeze > requirements.txt

Source

ERROR: The term 'make' is not recognized as the name of a cmdlet

The error "'make' is not recognized as an internal or external command, operable program or batch file" occurs when we run the make command on Windows without having make installed. To solve the error, install make using Chocolatey.

make clean
make : The term 'make' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path 
was included, verify that the path is correct and try again.
At line:1 char:1
+ make clean
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (make:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Suggestion [3,General]: The command make was not found, but does exist in the current location. Windows PowerShell does not load commands from the current location by default. If you trust this command, instead type: ".\make". See "get-help about_Command_Precedence" for more details.

To install Chocolatey:

  1. Open PowerShell as an administrator.
  2. Run the following command:
    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
  3. Wait for the command to complete.
  4. Type choco to make sure Chocolatey is installed:
    PS C:\WINDOWS\system32> choco
    Chocolatey v2.4.1
    Please run 'choco -?' or 'choco <command> -?' for help menu.
  5. Now that you have Chocolatey installed, run the following command to install make:
    PS C:\WINDOWS\system32> choco install make -y
    Chocolatey v2.4.1
    Installing the following packages:
    make
    By installing, you accept licenses for the packages.
    Downloading package from source 'https://community.chocolatey.org/api/v2/'
    Progress: Downloading make 4.4.1... 100%
    
    make v4.4.1 [Approved]
    make package files install completed. Performing other installation steps.
     ShimGen has successfully created a shim for make.exe
     The install of make was successful.
      Deployed to 'C:\ProgramData\chocolatey\lib\make'
    
    Chocolatey installed 1/1 packages.
     See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Source