Skip to content

Adds pylint check #2

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

Merged
merged 4 commits into from
Mar 15, 2022
Merged
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: 16 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
language: python
python:
- "3.9"
before_install:
- export PYTHONPATH=$PYTHONPATH:$(pwd)/src

install:
- pip install pipenv
- pipenv install
- pipenv install --dev

stages:
- style
- test

script:
# Your test script goes here
- pytest -v --color=yes src # Runs in pipenv
jobs:
include:
- stage: style
name: "Style check"
script: pylint **/*.py
- stage: test
name: "Unit tests"
script: pytest -v --color=yes src # Runs in pipenv
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
activate:
pipenv shell

test:
pytest

lint:
pylint src
pylint **/*.py

lintfix:
autopep8 src --recursive --in-place --aggressive
autopep8 **/*.py --recursive --in-place --aggressive

lintfixhard:
autopep8 src --recursive --in-place --aggressive --aggressive
autopep8 **/*.py --recursive --in-place --aggressive --aggressive

install:
pipenv install
pipenv install --dev

lock:
pipenv lock
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ make install
```
This calls `pipenv`, which will create a virtual environment for this project.

To enter a shell on this environment run
To activate this environment run
```bash
make shell
make activate
```

## Tests
Expand All @@ -44,11 +44,11 @@ make lint

We use `autopep8` to automatically fix errors.

User
Use
```bash
make lintfix
```
of
or
```bash
make lintfixhard
```
Expand Down
43 changes: 25 additions & 18 deletions cli/cnn_fashion_mnist_classifier.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@

"""CLI to use the cnn.FashionMNISTClassifier"""
import argparse
from computer_vision.cnn import FashionMNISTClassifier


def build_arg_parser():
"""Parses the user's arguments"""
parser = argparse.ArgumentParser(
description="Use a CNN classifier to classify the "+
description="Use a CNN classifier to classify the " +
"Fashion MNIST training dataset",
epilog="Built with <3 by Emmanuel Byrd at 8th Light Ltd."
)
parser.add_argument(
"--model_path", metavar="./model.h5", type=str, default="./model.h5",
help="The read/write path of the trained model " +
help="The read/write path of the trained model " +
"(default: ./model.h5)"
)
parser.add_argument(
"--history_path", metavar="./train_hist", type=str,
"--history_path", metavar="./train_hist", type=str,
default="./train_hist",
help="The read/write path of the training history "+
help="The read/write path of the training history " +
"(default: ./hist)"
)
parser.add_argument(
Expand Down Expand Up @@ -49,49 +51,54 @@ def build_arg_parser():
help="Path to store the generated plot. Leave blank to ignore."
)
parser.add_argument(
"--save_model", action=argparse.BooleanOptionalAction,type=bool,
"--save_model", action=argparse.BooleanOptionalAction, type=bool,
help="Save the model"
)
return parser


def execute_cnn(args):
cnn_trainer = FashionMNISTClassifier(args.model_path, args.history_path)
"""Execute the FashionMNISTClassifier functions as requested"""
cnn_trainer = FashionMNISTClassifier()

if args.use_stored:
cnn_trainer.load_model()
cnn_trainer.load_train_history()
cnn_trainer.load_model(args.model_path)
cnn_trainer.load_train_history(args.history_path)
cnn_trainer.show_summary()
elif args.train:
cnn_trainer.load_dataset()
cnn_trainer.build_model()
cnn_trainer.show_summary()
cnn_trainer.compile()
cnn_trainer.train(
args.mini_batch_size,
args.epochs,
args.mini_batch_size,
args.epochs,
args.validation_split
)
else:
print (
"Do you want to load a model or train a new one? "+
print(
"Do you want to load a model or train a new one? " +
"(--use_stored, --train)"
)
return

if args.plot or args.save_plot:
cnn_trainer.plot_hist(args.plot, args.save_plot)

if args.save_model:
cnn_trainer.save_model()
cnn_trainer.save_train_history()
cnn_trainer.save_model(args.model_path)
cnn_trainer.save_train_history(args.history_path)


def main():
"""Main function"""
arg_parser = build_arg_parser()
args = arg_parser.parse_args()

execute_cnn(args)

print("Finished.")



if __name__ == "__main__":
main()
main()
26 changes: 18 additions & 8 deletions path_adder.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
"""Adds this repository's modules to the Python's PATH"""
import os
import sys

import pathlib


def main():
for elem in sys.path:
this_file_path = pathlib.Path(__file__).parent.resolve()
src_path = os.path.join(this_file_path, "src")
"""
Creates a `.pth` file under the corresponding `site-packages` dir.

This function works in both a virtual and a native environment.
"""
this_file_path = pathlib.Path(__file__).parent.resolve()
src_path = os.path.join(this_file_path, "src")

for elem in sys.path:
if elem.endswith("site-packages"):
site_packages_dir = elem
elif elem == src_path:
print(src_path + " path is already added. Aborting...")
return

file_name = 'extra_python_folders.pth'
with open(os.path.join(site_packages_dir, file_name), 'w') as f:
f.write(src_path)

file_path = os.path.join(site_packages_dir,
'extra_python_folders.pth')

with open(file_path, 'w', encoding="utf-8") as file:
file.write(src_path)
print("Added to path: " + src_path)


if __name__ == "__main__":
main()
main()
1 change: 1 addition & 0 deletions src/computer_vision/cnn/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
"""Convolutional Neural Network (CNN) implementations"""
from .fashion_mnist_classifier import FashionMNISTClassifier
Loading