Skip to content

Commit

Permalink
feat: replace yapf with black as code formatter
Browse files Browse the repository at this point in the history
we already use fourmat/black to check/format our code, so no need to include yapf as another dependency. Yapf also looks like not be actively developed.
  • Loading branch information
newgene committed Mar 24, 2023
1 parent 9b6731c commit fce0864
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 12 additions & 10 deletions biothings/hub/dataplugin/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
import urllib.parse
from string import Template

# we switched to use black for code formatting
# from yapf.yapflib import yapf_api
import black
import requests
import yaml
from yapf.yapflib import yapf_api

from biothings import config as btconfig
from biothings.hub.dataload.dumper import LastModifiedFTPDumper, LastModifiedHTTPDumper
Expand All @@ -32,7 +34,6 @@ class LoaderException(Exception):


class BasePluginLoader(object):

loader_type = None # set in subclass

def __init__(self, plugin_name):
Expand Down Expand Up @@ -74,7 +75,6 @@ def load_plugin(self):


class ManifestBasedPluginLoader(BasePluginLoader):

loader_type = "manifest"

# should match a _dict_for_***
Expand Down Expand Up @@ -505,7 +505,6 @@ def interpret_manifest(self, manifest, data_plugin_folder):


class AdvancedPluginLoader(BasePluginLoader):

loader_type = "advanced"

def can_load_plugin(self):
Expand Down Expand Up @@ -547,7 +546,6 @@ def load_plugin(self):


class BaseAssistant(object):

plugin_type = None # to be defined in subblass
data_plugin_manager = None # set by assistant manager
dumper_manager = None # set by assistant manager
Expand Down Expand Up @@ -644,7 +642,6 @@ class AssistedUploader(object):


class GithubAssistant(BaseAssistant):

plugin_type = "github"

@property
Expand Down Expand Up @@ -685,7 +682,6 @@ def handle(self):


class LocalAssistant(BaseAssistant):

plugin_type = "local"

@property
Expand Down Expand Up @@ -925,7 +921,9 @@ def export_dumper(self, plugin_name, folder):
# clear init, we'll append code
# we use yapf (from Google) as autopep8 (for instance) doesn't give
# good results in term in indentation (input_type list for keylookup for instance)
beauty, _ = yapf_api.FormatCode(dclass.python_code)
# switched to use black from yapf
# beauty, _ = yapf_api.FormatCode(dclass.python_code)
beauty = black.format_str(dclass.python_code, mode=black.Mode())
with open(dfile, "w") as fout:
fout.write(beauty)
with open(dinit, "a") as fout:
Expand Down Expand Up @@ -959,7 +957,9 @@ def export_uploader(self, plugin_name, folder):
dinit = os.path.join(folder, "__init__.py")
mod_name = f"{uclass.__name__.split('_')[1]}_upload"
ufile = os.path.join(folder, mod_name + ".py")
beauty, _ = yapf_api.FormatCode(uclass.python_code)
# switched to use black from yapf
# beauty, _ = yapf_api.FormatCode(uclass.python_code)
beauty = black.format_str(uclass.python_code, mode=black.Mode())
with open(ufile, "w") as fout:
fout.write(beauty)
with open(dinit, "a") as fout:
Expand Down Expand Up @@ -1010,7 +1010,9 @@ def export_mapping(self, plugin_name, folder):
return res
else:
ufile = os.path.join(folder, "upload.py")
strmap, _ = yapf_api.FormatCode(pprint.pformat(mapping))
# switched to use black from yapf
# strmap, _ = yapf_api.FormatCode(pprint.pformat(mapping))
strmap = black.format_str(pprint.pformat(mapping), mode=black.Mode())
with open(ufile, "a") as fout:
fout.write(
"""
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ def read(fname):
"pip", # auto-install requirements from plugins
# 'pandas==1.0.1', # json with inf/nan and more to come (replaced by orjson below now)
# 'orjson>=3.5.2', # this is a faster json lib support inf/nan and datetime
"yapf", # code reformatter, better results than autopep8
# "yapf", # code reformatter, better results than autopep8
"black", # code formatter
"requests-aws4auth", # aws s3 auth requests for autohub
"networkx>=2.1,<2.6", # datatransform
"biothings_client>=0.2.6", # datatransform (api client),
"cryptography==38.0.3", # for generate ssh keys, ssl cert.
"cryptography>=38.0.3", # for generate ssh keys, ssl cert, also required by asyncssh
]

# extra requirements to develop biothings
Expand Down

0 comments on commit fce0864

Please sign in to comment.