Skip to content

Commit

Permalink
Setting up poetry (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
leikoilja authored Mar 25, 2021
1 parent 409dc16 commit fc2bac0
Show file tree
Hide file tree
Showing 19 changed files with 1,353 additions and 228 deletions.
41 changes: 24 additions & 17 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,38 @@ name: Build package

on:
push:
branches: [ master ]
branches:
- master
pull_request:
branches: [ master ]
branches:
- master

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-latest, ubuntu-latest,windows-latest]
python-version: [3.6, 3.7, 3.8]
python-version: [3.8]
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U pip setuptools
pip install wheel
- name: Test package
run: |
python setup.py install
pip show glocaltokens
- name: Check out the repository
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.1.5

- name: Install dependencies
run: poetry install

- name: Test package building
run: |
poetry build
35 changes: 35 additions & 0 deletions .github/workflows/linting-and-testing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Linting & Testing

on:
push:
branches:
- master
pull_request:

jobs:
pre-commit:
name: Pre-commit
strategy:
matrix:
python-version: [3.8]
runs-on: ubuntu-latest
steps:
- name: Check out the repository
uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: abatilo/[email protected]
with:
poetry-version: 1.1.5

- name: Install dependencies
run: poetry install

- name: Run pre-commit on all files
run: |
poetry run pre-commit run --all-files --show-diff-on-failure --color=always
14 changes: 0 additions & 14 deletions .github/workflows/pre-commit.yaml

This file was deleted.

25 changes: 0 additions & 25 deletions .github/workflows/tests.yaml

This file was deleted.

50 changes: 35 additions & 15 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/PyCQA/isort
rev: 5.7.0
- id: check-added-large-files
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: local
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
args:
- --safe
- --quiet
- id: black
name: black
entry: poetry run black
language: system
types: [python]
require_serial: true
- id: isort
name: isort
entry: poetry run isort
language: system
types: [python]
require_serial: true
# - id: flake8
# name: flake8
# entry: poetry run flake8
# language: system
# types: [python]
# - id: pylint
# name: pylint
# entry: poetry run pylint
# language: system
# types: [python]
- id: pytest
name: pytest
language: system
entry: poetry run pytest
pass_filenames: false
always_run: true
89 changes: 89 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Contribution guidelines

Contributing to this project should be as easy and transparent as possible, whether it's:

- Reporting a bug
- Discussing the current state of the code
- Submitting a fix
- Proposing new features

## Github is used for everything

Github is used to host code, to track issues and feature requests, as well as accept pull requests.

Pull requests are the best way to propose changes to the codebase.

1. Fork the repo and create your branch from `master`.
2. If you've changed something, update the documentation.
3. Make sure your code lints (using pre-commit).
4. Test you contribution.
5. Issue that pull request!

## Any contributions you make will be under the MIT Software License

In short, when you submit code changes, your submissions are understood to be under the same [MIT License](http://choosealicense.com/licenses/mit/) that covers the project. Feel free to contact the maintainers if that's a concern.

## Report bugs using Github's [issues](../../issues)

GitHub issues are used to track public bugs.
Report a bug by [opening a new issue](../../issues/new/choose); it's that easy!

## Write bug reports with detail, background, and sample code

**Great Bug Reports** tend to have:

- A quick summary and/or background
- Steps to reproduce
- Be specific!
- Give sample code if you can.
- What you expected would happen
- What actually happens
- Notes (possibly including why you think this might be happening, or stuff you tried that didn't work)

People _love_ thorough bug reports. I'm not even kidding.

## Use a Consistent Coding Style

Install [Poetry](https://python-poetry.org/docs/#installation) to setup developer environment.
It uses [black](https://github.com/ambv/black) and [prettier](https://prettier.io/)
to make sure the code follows the style.

`pre-commit` can be used to run all check with one command (see dedicated section below).

## Test your code modification

You can use the `pre-commit` settings implemented in this repository to have
linting tool checking your contributions (see dedicated section below).

When writting unittests please follow the good practises like:

- Use `faker` to fake the data. See [examples](https://faker.readthedocs.io/en/master/)
- Use `mock` to patch objects/methods. See [examples](https://realpython.com/python-mock-library/)

## Pre-commit

With Poetry installed, run `poetry install` in the repo root.
It will create virualenv with all required packages.

If GRPC fails to compile on MacOS, run `export CFLAGS="-DHAVE_UNISTD_H"` first. It should be resolved in GRPC 1.36.

After that you can run [pre-commit](https://pre-commit.com/) with settings included in the
repostory to have code style and linting checks.

Activate `pre-commit` git hook:

```console
$ poetry run pre-commit install
```

Now the pre-commit tests will be done every time you commit.

You can also run the tests on all repository files manually with the command:

```console
$ poetry run pre-commit run --all-files
```

## License

By contributing, you agree that your contributions will be licensed under its MIT License.
1 change: 0 additions & 1 deletion HISTORY.md

This file was deleted.

22 changes: 6 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[![GitHub Workflow Status][workflow-shield]][workflow]
[![Contributors][contributors-shield]][contributors]
[![PyPI][pypi-shield]][pypi]
[![Pre-commit][pre-commit-shield]][pre-commit]

[![Open Issues][issues-shield]][issues]
[![Open Pull-Requests][pr-shield]][pr]
[![Contributors][contributors-shield]][contributors]

[![GitHub Release][releases-shield]][releases]
[![GitHub Activity][commits-shield]][commits]
Expand Down Expand Up @@ -104,23 +105,9 @@ print("[*] Master token", master_token)

## Contributing

See [Contributing guidelines](CONTRIBUTING.md)
This is an open-source project and all countribution is highly welcomed. To contribute please:

- Fork this repo
- Create a new branch
- Create a new virtual environment and install dependencies:
`pip install -r requirements`
- Implement your changes
- If possible add tests for your changes
- Push your changes to your branch
- Open Pull Request

When writting unittests please follow the good practises like:

- Use `faker` to fake the data. See [examples](https://faker.readthedocs.io/en/master/)
- Use `mock` to patch objects/methods. See [examples](https://realpython.com/python-mock-library/)
- You can run `python -m discover -p 'test*.py'` or `tox` inside of your virtual environment to test locally.

# Credits

Much credits go to @rithvikvibhu(https://github.com/rithvikvibhu) for doing most of the heavy work like finding a way to
Expand Down Expand Up @@ -151,5 +138,8 @@ Also, thank you very much to the guys at `pychromecast` which provided the code
[license]: https://github.com/leikoilja/glocaltokens/blob/main/LICENSE
[license-shield]: https://img.shields.io/github/license/leikoilja/glocaltokens.svg?style=for-the-badge

[pre-commit-shield]: https://img.shields.io/badge/pre--commit-enabled-brightgreen?style=for-the-badge
[pre-commit]: https://github.com/pre-commit/pre-commit

[releases-shield]: https://img.shields.io/github/release/leikoilja/glocaltokens.svg?style=for-the-badge
[releases]: https://github.com/leikoilja/glocaltokens/releases
7 changes: 3 additions & 4 deletions glocaltokens/client.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from datetime import datetime
import json
import logging
from datetime import datetime
from typing import Any, Dict, List, Optional
from uuid import uuid4

import grpc
from gpsoauth import perform_master_login, perform_oauth
import grpc

from .const import (
ACCESS_TOKEN_APP_NAME,
Expand All @@ -24,8 +24,7 @@
)
from .google.internal.home.foyer import v1_pb2, v1_pb2_grpc
from .scanner import GoogleDevice, discover_devices
from .utils import network as net_utils
from .utils import token as token_utils
from .utils import network as net_utils, token as token_utils
from .utils.logs import censor

logging.basicConfig(level=logging.ERROR)
Expand Down
10 changes: 6 additions & 4 deletions glocaltokens/google/internal/home/foyer/v1_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fc2bac0

Please sign in to comment.