Skip to content
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

Makefile to tox #24

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# .coveragerc to control coverage.py
[run]
branch = True
source = hubspot-api
# omit = bad_file.py

[paths]
source =
hs_api/
*/site-packages/

[report]
# Regexes for lines to exclude from consideration
exclude_lines =
# Have to re-enable the standard pragma
pragma: no cover

# Don't complain about missing debug-only code:
def __repr__
if self\.debug

# Don't complain if tests don't hit defensive assertion code:
raise AssertionError
raise NotImplementedError

# Don't complain if non-runnable code isn't run:
if 0:
if __name__ == .__main__.:
137 changes: 102 additions & 35 deletions .github/workflows/pr_check.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,116 @@
# This is a basic workflow to help you get started with Actions
# GitHub Actions configuration

name: Pull Request Check
name: tests

# Controls when the workflow will run
on:
pull_request:
branches: [ "main" ]
push:
# Avoid using all the resources/limits available by checking only
# relevant branches and tags. Other branches can be checked via PRs.
branches: [main]
tags: ['v[0-9]*', '[0-9]+.[0-9]+*'] # Match tags that resemble a version
pull_request: # Run in every PR
workflow_dispatch: # Allow manually triggering the workflow
schedule:
# Run roughly every 15 days at 00:00 UTC
# (useful to check if updates on dependencies break the package)
- cron: '0 0 1,16 * *'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
concurrency:
group: >-
${{ github.workflow }}-${{ github.ref_type }}-
${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
prepare:
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
outputs:
wheel-distribution: ${{ steps.wheel-distribution.outputs.path }}
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with: {fetch-depth: 0} # deep clone for setuptools-scm
- uses: actions/setup-python@v4
with: {python-version: "3.11"}
- name: Run static analysis and format checkers
run: pipx run pre-commit run --all-files --show-diff-on-failure
- name: Build package distribution files
run: pipx run tox -e clean,build
- name: Record the path of wheel distribution
id: wheel-distribution
run: echo "path=$(ls dist/*.whl)" >> $GITHUB_OUTPUT
- name: Store the distribution files for use in other stages
# `tests` and `publish` will use the same pre-built distributions,
# so we make sure to release the exact same package that was tested
uses: actions/upload-artifact@v3
with:
name: python-distribution-files
path: dist/
retention-days: 1

# setup env
- name: setup env
run: |
pip install --upgrade pip
pip install -r requirements.txt

# Run linting
- name: run linting
run: flake8 --config=setup.cfg

# Run black
- name: run black
run: black ./ --verbose

# Run isort
- name: run isort
run: isort

# Runs a set of commands using the runners shell
- name: Run pytests
test:
needs: prepare
strategy:
matrix:
python:
- "3.7" # oldest Python supported by PSF
- "3.11" # newest Python that is stable
platform:
- ubuntu-latest
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Retrieve pre-built distribution files
uses: actions/download-artifact@v3
with: {name: python-distribution-files, path: dist/}
- name: Run tests
env:
HUBSPOT_TEST_ACCESS_TOKEN: ${{ secrets.HUBSPOT_TEST_ACCESS_TOKEN }}
HUBSPOT_TEST_PIPELINE_ID: ${{ secrets.HUBSPOT_TEST_PIPELINE_ID }}
HUBSPOT_TEST_TICKET_PIPELINE_ID: ${{ secrets.HUBSPOT_TEST_TICKET_PIPELINE_ID }}
run: python -m pytest
run: >-
pipx run tox
--installpkg '${{ needs.prepare.outputs.wheel-distribution }}'
-- -rFEx --durations 10 --color yes
- name: Generate coverage report
run: pipx run coverage lcov -o coverage.lcov
- name: Upload partial coverage report
uses: coverallsapp/github-action@master
with:
path-to-lcov: coverage.lcov
github-token: ${{ secrets.github_token }}
flag-name: ${{ matrix.platform }} - py${{ matrix.python }}
parallel: true

finalize:
needs: test
runs-on: ubuntu-latest
steps:
- name: Finalize coverage report
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

publish:
needs: finalize
if: ${{ github.event_name == 'push' && contains(github.ref, 'refs/tags/') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with: {python-version: "3.11"}
- name: Retrieve pre-built distribution files
uses: actions/download-artifact@v3
with: {name: python-distribution-files, path: dist/}
- name: Publish Package
env:
# Set your PYPI_TOKEN as a secret using GitHub UI
# - https://pypi.org/help/#apitoken
# - https://docs.github.com/en/actions/security-guides/encrypted-secrets
TWINE_REPOSITORY: pypi
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: pipx run tox -e publish
62 changes: 62 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
exclude: '^docs/conf.py'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
exclude: (districts1822.csv|races_full_tables_2018-2022.zip)
- id: check-ast
- id: check-json
- id: check-merge-conflict
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: end-of-file-fixer
- id: requirements-txt-fixer
- id: mixed-line-ending
args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows

# If you want to avoid flake8 errors due to unused vars or imports:
- repo: https://github.com/myint/autoflake
rev: v2.0.1
hooks:
- id: autoflake
args: [
--in-place,
--remove-all-unused-imports,
--remove-unused-variables,
]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
language_version: python3

# If like to embrace black styles even in the docs:
- repo: https://github.com/asottile/blacken-docs
rev: 1.13.0
hooks:
- id: blacken-docs
additional_dependencies: [black]

- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.1
hooks:
- id: mypy
additional_dependencies:
- types-requests
- types-python-dateutil
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ id of the pipeline that you want to interact with as the default.
```python
from hs_api.api.hubspot_api import HubSpotClient

access_token = 'my_access_token'
pipeline_id = 'my_pipeline_id'
access_token = "my_access_token"
pipeline_id = "my_pipeline_id"

client = HubSpotClient(
access_token=access_token,
PIPELINE_ID=pipeline_id,
pipeline_id=pipeline_id,
)
```

You can also set the environment variables `HUBSPOT_ACCESS_TOKEN` and
`HUBS_PIPELINE_ID` which will be used as defaults if no access_token or
pipeline_id are passed to the `HubSpotClient`.
pipeline_id are passed to the `HubSpotClient`. This can be done by copying
the .env.template file from `hs_api\.env.template` into the root of the
project and renaming it to .env.


More details on how to use the client can be found in the test cases that
Expand Down Expand Up @@ -77,7 +79,7 @@ normal, which will kick off the github actions to run the linting and tests.

Be aware that a couple of the tests can be flakey due to the delay in the
asynchronous way hubspot returns results and actually applies them to the
underlying data. There are dealys in place to account for this but there can
underlying data. There are delays in place to account for this but there can
be cases where a test fails because a record appears to have not been created.
This probably needs reworking, but feel free to re-run the tests.

Expand Down
5 changes: 0 additions & 5 deletions hs_api/.env.template

This file was deleted.

8 changes: 0 additions & 8 deletions requirements.txt

This file was deleted.

Loading