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..2ca9b1e --- /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.7 +- 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.7 + 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.7 + 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.7 + 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.7 + 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..e74798c --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# 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*. +``` +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` + 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