From 67149cd49ec5d360db3b707ad0cdde2340231112 Mon Sep 17 00:00:00 2001 From: adimyth Date: Wed, 9 Sep 2020 23:02:11 +0530 Subject: [PATCH 1/2] 1. Adds CONTRIBUTING guidelines 2. Adds `.pre-commit-config.yaml` that checks before commits 3. Runs black 4. Updates requirements --- .gitignore | 3 ++ .pre-commit-config.yaml | 80 +++++++++++++++++++++++++++++++++++++++++ CONTRIBUTING.md | 22 ++++++++++++ README.md | 25 ++++++++++--- colabcode/code.py | 2 ++ requirements.txt | 5 ++- 6 files changed, 131 insertions(+), 6 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100644 CONTRIBUTING.md diff --git a/.gitignore b/.gitignore index 86809b7..95db7fb 100644 --- a/.gitignore +++ b/.gitignore @@ -130,3 +130,6 @@ dmypy.json # vscode .vscode/ + +# asdf +.tool-versions diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..75edefb --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,80 @@ +default_language_version: + python: python3 + +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: master + hooks: + - id: check-merge-conflict + - id: check-added-large-files + args: ['--maxkb=30000'] + - id: check-executables-have-shebangs + - id: trailing-whitespace +- repo: https://github.com/psf/black + rev: stable + hooks: + - id: black + language_version: python3.6 +- repo: local + hooks: + - id: flake8 + name: flake8 + description: Python style guide enforcement. + entry: flake8 + args: [ + "--config=setup.cfg", + "--ignore=E501,PD011,F403,F405,W503,E231,VNE001" + ] + additional_dependencies: [ + flake8, + flake8-2020, # flake8 plugin which checks for misuse of `sys.version` or `sys.version_info` + flake8-blind-except, # A flake8 extension that checks for blind except: statements + flake8-builtins, # Check for python builtins being used as variables or parameters. + flake8-comprehensions, # It helps you write better list/set/dict comprehensions. + dlint, # Dlint is a tool for encouraging best coding practices and helping ensure we're writing secure Python code. + flake8-pytest, # pytest assert checker plugin for flake8 + flake8-tabs, # Tab (or Spaces) indentation style checker for flake8 + ] + language: python + language_version: python3.6 + types: [python] + require_serial: true + - id: autoflake + name: autoflake + description: remove unused imports + entry: autoflake + args: [ + "--in-place", + "--remove-unused-variables" + ] + language: python + language_version: python3.6 + types: [python] + require_serial: true + additional_dependencies: [autoflake] + - id: isort + name: isort + description: Automatically sort imports. + entry: isort + args: [ + "--recursive", + ] + language: python + language_version: python3.6 + types: [python] + require_serial: true + additional_dependencies: [isort] + - id: pytest + name: Run Pytest + description: Run Python unit-tests + entry: pytest + language: python + types: [python] + language_version: python3.6 + require_serial: true + stages: [push] + additional_dependencies: [ + pytest, + pytest-cov, + pytest-mock + ] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..3d8c982 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,22 @@ +# Contributing +We follow the "fork-and-pull" Git workflow. + +1. Fork the *ColabCode* repo from `master` branch +2. Clone the fork locally +3. Create a branch for local development +4. When done making changes, make sure that your changes pass [flake8](https://pypi.org/project/flake8/). Also ensure, that your code is formatted using [black](https://github.com/psf/black). +5. Commit changes to your own branch and push them to your fork +6. Submit a Pull request for review + +## Coding Style +The codebase uses +* [black](https://github.com/psf/black) for code formatting. +* [flake8](https://pypi.org/project/flake8/) for code checking + +Install dependencies from *requirements.txt*. Run black - +```python +black . +``` + +All your changes will be tested. Check `.pre-commit-config.yaml` + diff --git a/README.md b/README.md index 305c7a5..fe3054b 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,24 @@ Run code server on Google Colab or Kaggle Notebooks -- install colabcode: `pip install colabcode` -- import colabcode: `from colabcode import ColabCode` -- run: `ColabCode(port=10000, password="abhishek")` -- you can also run it with any password or port :) +## Getting Started +Install colabcode +```bash +pip install colabcode +``` +Import colabcode +```python +from colabcode import ColabCode +``` +Run colabcode +``` +ColabCode(port=10000, password="myawesome password") +``` +You can also run it with any password or port :) -See an example in [this video tutorial](https://www.youtube.com/watch?v=7kTbM3D02jU). +## Relevant Sources +* Checkout Abhishek's YouTube video [here](https://www.youtube.com/watch?v=7kTbM3D02jU) +* [VSCode on Google Colab](https://amitness.com/vscode-on-colab/) article by Amit Chaudhary + +## Contributing +Kindly refer to [CONTRIBUTING.md](CONTRIBUTING.md) diff --git a/colabcode/code.py b/colabcode/code.py index 8ad9f68..0b0fdc1 100644 --- a/colabcode/code.py +++ b/colabcode/code.py @@ -1,8 +1,10 @@ import os import subprocess from pyngrok import ngrok + try: from google.colab import drive + colab_env = True except ImportError: colab_env = False diff --git a/requirements.txt b/requirements.txt index abdb8d2..da9d0d3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,4 @@ -pyngrok=4.1.11 +pyngrok==4.1.11 +pre-commit +flake8 +black From 2b3c1fa6a6de961de56176d7a18090562fbcac33 Mon Sep 17 00:00:00 2001 From: adimyth Date: Wed, 9 Sep 2020 23:15:08 +0530 Subject: [PATCH 2/2] updates instruction in CONTRIBUTING to use pre-commit --- .pre-commit-config.yaml | 10 +++++----- CONTRIBUTING.md | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 75edefb..2ca9b1e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: rev: stable hooks: - id: black - language_version: python3.6 + language_version: python3.7 - repo: local hooks: - id: flake8 @@ -36,7 +36,7 @@ repos: flake8-tabs, # Tab (or Spaces) indentation style checker for flake8 ] language: python - language_version: python3.6 + language_version: python3.7 types: [python] require_serial: true - id: autoflake @@ -48,7 +48,7 @@ repos: "--remove-unused-variables" ] language: python - language_version: python3.6 + language_version: python3.7 types: [python] require_serial: true additional_dependencies: [autoflake] @@ -60,7 +60,7 @@ repos: "--recursive", ] language: python - language_version: python3.6 + language_version: python3.7 types: [python] require_serial: true additional_dependencies: [isort] @@ -70,7 +70,7 @@ repos: entry: pytest language: python types: [python] - language_version: python3.6 + language_version: python3.7 require_serial: true stages: [push] additional_dependencies: [ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3d8c982..e74798c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,21 +2,31 @@ We follow the "fork-and-pull" Git workflow. 1. Fork the *ColabCode* repo from `master` branch -2. Clone the fork locally -3. Create a branch for local development -4. When done making changes, make sure that your changes pass [flake8](https://pypi.org/project/flake8/). Also ensure, that your code is formatted using [black](https://github.com/psf/black). +2. Clone the fork locally +3. Create a branch for local development +4. When done making changes, make sure that your changes pass [flake8](https://pypi.org/project/flake8/). Also ensure, that your code is formatted using [black](https://github.com/psf/black). 5. Commit changes to your own branch and push them to your fork 6. Submit a Pull request for review ## Coding Style -The codebase uses +The codebase uses * [black](https://github.com/psf/black) for code formatting. * [flake8](https://pypi.org/project/flake8/) for code checking -Install dependencies from *requirements.txt*. Run black - +Install dependencies from *requirements.txt*. +``` +pip install -r requirements.txt +``` + +Run black - ```python black . ``` +Before commiting - +```bash +pre-commit install +``` + All your changes will be tested. Check `.pre-commit-config.yaml`