8000 Package project by slarse · Pull Request #714 · TheAlgorithms/Python · GitHub
[go: up one dir, main page]

Skip to content

Package project #714

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

Closed
wants to merge 9 commits into from
Closed
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
20 changes: 6 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
language: python
cache: pip
python:
- 2.7
- 3.6
#- nightly
#- pypy
#- pypy3
matrix:
allow_failures:
- python: nightly
- python: pypy
- python: pypy3
install:
#- pip install -r requirements.txt
- pip install flake8 # pytest # add another testing frameworks later
- pip install flake8
- pip install -e .[TEST]
before_script:
# stop the build if there are Python syntax errors or undefined names
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
# Prints an unmanageable amount of output (some 6000 lines)
#- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
script:
- true # pytest --capture=sys # add other tests here
- ./run_tests.sh
notifications:
on_success: change
on_failure: change # `always` will be the setting once code changes slow down
on_failure: change
31 changes: 31 additions & 0 deletions .travis/covstring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""This utility script gathers the top level packages for wich coverage should
be measured.
"""
import os

PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))


def gather_packages(cwd=PROJECT_ROOT):
"""Return a list of all directories in cwd containing an ``__init__.py`` file."""
dirpaths = (path for path in os.listdir(PROJECT_ROOT) if os.path.isdir(path))
package_names = [
os.path.basename(path) for path in dirpaths if "__init__.py" in os.listdir(path)
]
return package_names

def generate_coverage_py_string(cwd=PROJECT_ROOT):
"""Generate a string on the form ``--cov PACKAGE_1 --cov PACKAGE_2 ...`` such
that all packages found in cwd are traced using pytest-cov.
"""
packages = gather_packages(cwd)
assert packages

return "--cov " + " --cov ".join(packages)

def main():
cov_string = generate_coverage_py_string()
print(cov_string)

if __name__ == "__main__":
main()
Empty file added Graphs/__init__.py
Empty file.
Empty file added Maths/__init__.py
Empty file.
Empty file.
Empty file added arithmetic_analysis/__init__.py
Empty file.
Empty file added binary_tree/__init__.py
Empty file.
Empty file added boolean_algebra/__init__.py
Empty file.
Empty file added ciphers/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added dynamic_programming/__init__.py
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def cycle_nodes(self):
indirect_parents = []
ss = s
anticipating_nodes = set()
on_the_way_back = False

while True:
# check if there is any non isolated nodes
Expand Down Expand Up @@ -200,6 +201,7 @@ def has_cycle(self):
indirect_parents = []
ss = s
anticipating_nodes = set()
on_the_way_back = False

while True:
# check if there is any non isolated nodes
Expand Down Expand Up @@ -368,6 +370,7 @@ def cycle_nodes(self):
indirect_parents = []
ss = s
anticipating_nodes = set()
on_the_way_back = False

while True:
# check if there is any non isolated nodes
Expand Down Expand Up @@ -415,6 +418,7 @@ def has_cycle(self):
indirect_parents = []
ss = s
anticipating_nodes = set()
on_the_way_back = False

while True:
# check if there is any non isolated nodes
Expand Down
Empty file added graphs/__init__.py
Empty file.
Empty file added hashes/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file added machine_learning/__init__.py
Empty file.
Empty file added maths/__init__.py
Empty file.
Empty file added matrix/__init__.py
Empty file.
Empty file added networking_flow/__init__.py
Empty file.
Empty file added neural_network/__init__.py
Empty file.
Empty file added other/__init__.py
Empty file.
Empty file added other/game_of_life/__init__.py
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /bin/bash
#
# Script for running the test suite with branch coverage.

# Coverage.py caches interfere with subsequent runs for some reason
rm -f .coverage*

python -m pytest tests/ $(python .travis/covstring.py) --cov-branch
Empty file added searches/__init__.py
Empty file.
40 changes: 40 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""This is a setup module for installing this project. To install the project,
set the current working directory to the project root, and run:

``pip install .``

Depending on your environment, you may need some modifiers. To install for the
current user only, run:

``pip install . --user``

``pip`` is sometimes aliased to the Python 3 version of pip, and sometimes to
the Python 2 version. If you want to be sure to use the one for Python 3, run:

``python3 -m pip install . --user``

If you also want to be able to develop and run the test suite, you need to install
with test dependencies (preferably in a virtual environment):

``pip install --editable .[TEST]``
"""
from setuptools import setup, find_packages

with open("README.md", mode="r") as file:
README = file.read()

TEST_REQUIREMENTS = ["pytest>=4.0.0", "pytest-cov", "pytest-timeout"]
REQUIRED = ["numpy", "matplotlib", "sympy", "scikit-learn", "tensorflow"]

setup(
name="TheAlgorithms",
description="All algorithms implemented in Python (for education)",
long_description=README,
long_description_content_type="text/markdown",
license="MIT",
packages=find_packages(exclude=("tests", "docs")),
tests_require=TEST_REQUIREMENTS,
install_requires=REQUIRED,
extras_require=dict(TEST=TEST_REQUIREMENTS),
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*",
)
Empty file added simple_client/__init__.py
Empty file.
Empty file added sorts/__init__.py
Empty file.
Empty file added strings/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions tests/test_imports.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import os
import re
import importlib
import pytest

def _split_path_rec(path):
rest, tail = os.path.split(path)
if rest == "":
return [tail]
return _split_path_rec(rest) + [tail]


def _gather_modules():
"""Gather all modules that should be imported, but exclude __init__
modules and anything in the tests directory.

Note that all top-level directories, except those listed in
``exclude_dirs``, will be searched. This means that, for example,
virtual environments in the project directory will be "teste".
"""
testdir = os.path.abspath(os.path.dirname(__file__))
root = os.path.dirname(testdir)
modules = []
exclude_dirs = [os.path.abspath(p) for p in (testdir, root)]

for dirpath, dirnames, filenames in os.walk(root):
dirnames[:] = [d for d in dirnames if os.path.abspath(d) not in exclude_dirs]
if dirpath == root: # skip root to avoid scripts
continue
for filename in filenames:
if not filename.endswith(".py") or filename.endswith("__init__.py"):
continue
reldirpath = os.path.relpath(dirpath, root)
path_nodes = _split_path_rec(os.path.join(reldirpath, filename))
module = ".".join(path_nodes)[:-3]
modules.append(module)
return modules


@pytest.mark.parametrize("module", _gather_modules())
@pytest.mark.timeout(2)
def test_import_module(module):
"""Test that all modules from project root can be imported"""
mod = importlib.import_module(module)
assert mod

if __name__ == "__main__":
print(_gather_modules())
Empty file added traversals/__init__.py
Empty file.
0