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

style: apply style black, flake8, isort (#108) #109

Closed
wants to merge 2 commits into from
Closed
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
91 changes: 91 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI

on:
push:
branches: [ main ]

workflow_dispatch:

jobs:
cancel-previous:
runs-on: ubuntu-latest
if: github.ref != 'refs/heads/main'
steps:
- uses: khan/[email protected]
with:
workflows: "ci.yml"
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

linting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: "3.8"

- name: Install dependencies
run: |
# Install / update package management tools
pip install -U pip setuptools
# Test dependencies
pip install -U pytest pytest-cov pytest-vcr black==23.3.0 flake8>=6.0,<7.0 isort>=5.0,<6.0
# Dump installed packages and versions
pip freeze

- name: Run linting tools
run: |
black -l 120 --check --diff .
isort --profile=black --check --diff .
flake8 src tests docs setup.py

- name: Comment PR
if: github.event_name == 'pull_request' && failure()
uses: marocchino/[email protected]
with:
message: |
- Please format your Python code with [black](https://black.readthedocs.io): `make black`
- Please organize your imports [isorts](https://isort.readthedocs.io): `make isort`
- Please ensure that your code passes [flake8](https://flake8.pycqa.org/en/latest/): `make flake8`

You can trigger all lints locally by running `black -l 120 --check . && isort --profile=black --check . && flake8 src tests docs setup.py`
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

testing:
needs: linting
runs-on: ubuntu-latest
strategy:
matrix:
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"

steps:
- name: Checkout repository
uses: actions/checkout@v2

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

- name: Install dependencies
run: |
sudo apt install libhts-dev libhts3 libhtscodecs-dev libhtscodecs2 tabix
# Install / update package management tools.
pip install -U pip setuptools
# Test dependencies
pip install -U pytest pytest-cov pytest-vcr black==23.3.0 flake8>=6.0,<7.0 isort>=5.0,<6.0
# Install the local package itself in editable mode.
pip install -e .
# Dump installed packages and versions
pip freeze

- name: Run tests
run: |
pytest
19 changes: 19 additions & 0 deletions .github/workflows/conventional-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: PR

on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

jobs:
title-format:
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
validateSingleCommit: true
39 changes: 0 additions & 39 deletions .github/workflows/cqa.yml

This file was deleted.

41 changes: 41 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: release-please

on:
push:
branches:
- main

jobs:
release-please:
runs-on: ubuntu-latest
steps:

- uses: GoogleCloudPlatform/release-please-action@v2
id: release
with:
release-type: python
package-name: biocommons.seqrepo

- uses: actions/checkout@v2
if: ${{ steps.release.outputs.release_created }}
with:
fetch-depth: 0

- name: Set up Python
if: ${{ steps.release.outputs.release_created }}
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Build package
if: ${{ steps.release.outputs.release_created }}
run: |
python -m pip install --upgrade pip
python setup.py sdist

- name: Publish to PyPI
if: ${{ steps.release.outputs.release_created }}
uses: pypa/gh-action-pypi-publish@master
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Editors
.*.sw?
*~

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Changelog
16 changes: 7 additions & 9 deletions docs/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import math
from base64 import urlsafe_b64decode, urlsafe_b64encode
from binascii import hexlify, unhexlify
import datetime
import math
import sys


def _format_time(timespan, precision=3):
"""Formats the timespan in a human readable form

>>> _format_time(0.35)
'350 ms'

Expand All @@ -26,21 +24,21 @@ def _format_time(timespan, precision=3):
if timespan >= 60.0:
# we have more than a minute, format that in a human readable form
# Idea from http://snipplr.com/view/5713/
parts = [("d", 60*60*24),("h", 60*60),("min", 60), ("s", 1)]
parts = [("d", 60 * 60 * 24), ("h", 60 * 60), ("min", 60), ("s", 1)]
time = []
leftover = timespan
for suffix, length in parts:
value = int(leftover / length)
if value > 0:
leftover = leftover % length
time.append(u'%s%s' % (str(value), suffix))
time.append(u"%s%s" % (str(value), suffix))
if leftover < 1:
break
return " ".join(time)

units = [u"s", u"ms", u"us", u"ns"] # the save value
units = [u"s", u"ms", u"us", u"ns"] # the save value
scaling = [1, 1e3, 1e6, 1e9]

if timespan > 0.0:
order = min(-int(math.floor(math.log10(timespan)) // 3), 3)
else:
Expand All @@ -51,6 +49,6 @@ def _format_time(timespan, precision=3):
def hex_to_base64url(s):
return urlsafe_b64encode(unhexlify(s)).decode("ascii")


def base64url_to_hex(s):
return hexlify(urlsafe_b64decode(s)).decode("ascii")

3 changes: 1 addition & 2 deletions fixes/fixer
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ This script isn't for general users

import argparse
import logging
import sqlite3
import os
import sqlite3
import sys

import coloredlogs
import yaml


_logger = logging.getLogger()

fixes_dir = os.path.dirname(sys.argv[0])
Expand Down
1 change: 0 additions & 1 deletion misc/rsync-log-summary
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import sys
import coloredlogs
from dateutil.parser import parse


_logger = logging.getLogger(__name__)

# e.g., 2016/08/31 01:24:34 [32383] rsync on seqrepo/ from ec2-....compute.amazonaws.com (52.34.43.195)
Expand Down
10 changes: 5 additions & 5 deletions misc/threading-verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@


import os
from multiprocessing import Process, Queue
import sqlite3
import sys
from multiprocessing import Process, Queue

from biocommons.seqrepo import SeqRepo

Expand All @@ -37,7 +37,7 @@ def fetch_in_thread(sr, nsa):
def fetch_seq(q, nsa):
pid, ppid = os.getpid(), os.getppid()
q.put((pid, ppid, sr[nsa]))

q = Queue()
p = Process(target=fetch_seq, args=(q, nsa))
p.start()
Expand All @@ -46,9 +46,9 @@ def fetch_seq(q, nsa):

assert pid != ppid, "sequence was not fetched from thread"
return pid, ppid, seq


def make_seqrepo(writeable):

def make_seqrepo(writeable):
sr = SeqRepo("/tmp/sr", writeable=True)
sr.store("SMELLASSWEET", [{"namespace": "en", "alias": "rose"}, {"namespace": "fr", "alias": "rose"}])

Expand All @@ -70,6 +70,6 @@ def _test(sr):
print("sys.platform: " + sys.platform)
print("sys.version: " + sys.version.replace("\n", " "))
print("sqlite3.sqlite_version: " + sqlite3.sqlite_version)

_test(make_seqrepo(writeable=False))
_test(make_seqrepo(writeable=True))
2 changes: 1 addition & 1 deletion sbin/get-sequence-urls
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import logging
import re
import sys
from urllib.request import urljoin, urlopen
from requests_html import HTMLSession, HTML

import coloredlogs
from requests_html import HTML, HTMLSession

_logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,5 @@ all_files = 1
max-line-length = 120
exclude = tests/*
max-complexity = 10
ignore = E129,E221,E241,E251,E303,W291

ignore = E203, E266, E501, W503

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from setuptools import setup

setup(use_scm_version=True)
1 change: 1 addition & 0 deletions src/biocommons/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pragma: nocover
import pkg_resources

pkg_resources.declare_namespace(__name__)
10 changes: 5 additions & 5 deletions src/biocommons/seqrepo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@
from __future__ import absolute_import, division, print_function, unicode_literals

import logging
import pkg_resources
import warnings

import pkg_resources

_logger = logging.getLogger(__name__)

from ._versionwarning import *
from ._versionwarning import * # noqa; F403

try:
__version__ = pkg_resources.get_distribution(__name__).version
except pkg_resources.DistributionNotFound as e: # pragma: no cover
except pkg_resources.DistributionNotFound: # pragma: no cover
warnings.warn("can't get __version__ because %s package isn't installed" % __package__, Warning)
__version__ = None

_logger.info(__name__ + " " + __version__)


from .seqrepo import SeqRepo

from .seqrepo import SeqRepo # noqa: F401, E402

# <LICENSE>
# Copyright 2016 biocommons.fastadir Contributors (https://github.com/biocommons/biocommons.fastadir/)
Expand Down
2 changes: 0 additions & 2 deletions src/biocommons/seqrepo/_internal/logging_support.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import logging

class DuplicateFilter:
"""
Filters away duplicate log messages.
Expand Down
Loading