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

Add linting action #1694

Open
wants to merge 5 commits into
base: master
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
30 changes: 30 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[flake8]
exclude = */migrations
extend-ignore =
# "Celery tasks should have explicit names." isn't very well implemented at this time (4/19/2020)
PIE783
# False positive in flake8-pie 0.7 (2021-04-15)
PIE795
PIE798
PIE803
# Print found
T201

# Logging statement uses string.format()
G001
# Logging statement uses '%'
G002
# Logging statement uses '+'
G003
# Logging statement uses f-string (Same as PIE803)
G004

# This is used by flake8-import-order
import-order-style = pycharm
application-import-names = accounts, apiv2, bookmarks, clustering, comments, donations, favorites, follow, forum, freesound, general, geotags, messages, monitor, ratings, search, similarity, sounds, support, tags, tickets, utils, wiki
# This is used by flake8-requirements
known-modules =
max-line-length = 170

# This is used by flake8-annotations so that we don't have to explicitly type None in functions that don't use it
suppress-none-returning = true
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# .git-blame-ignore-revs
# Format code with yapf
d5ebbd0725f79ea4c994312bd508059fa5b8ce51

22 changes: 22 additions & 0 deletions .github/workflows/python-flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Flake8
# https://gitlab.com/pycqa/flake8

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Lint with flake8
run: |
pip -q install -r requirements.linters.txt
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# These are just the style issues
flake8 . --count --statistics
12 changes: 12 additions & 0 deletions .github/workflows/python-yapf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: YAPF Formatting Check
on: [push]
jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: run YAPF to test if python code is correctly formatted
uses: AlexanderMelde/yapf-action@master
with:
args: --verbose
3 changes: 3 additions & 0 deletions _docs/api/add_examples_to_api_docs_source_files.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import sys
import urllib.request, urllib.parse, urllib.error

sys.path.append("../../apiv2")
from examples import examples

base_url = 'https://freesound.org/'


def get_formatted_examples_for_view(view_name):
try:
data = examples[view_name]
Expand Down
87 changes: 42 additions & 45 deletions _docs/api/generate_analysis_documentation/generate_analysis_rst.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Generate skeleton for documentation,
# Generate skeleton for documentation,
# add essentia documentation links by hand


import urllib.request, urllib.error, urllib.parse,json

import urllib.request, urllib.error, urllib.parse, json

header = """
.. _analysis-docs:
Expand Down Expand Up @@ -50,57 +48,56 @@
image_str = " .. image:: _static/descriptors/"
height_str = " :height: 300px"
algorithm_doc_str = "http://essentia.upf.edu/documentation/reference/streaming_"
sorted_namespaces = ["metadata","lowlevel","rhythm","tonal","sfx"]
desc_exceptions = ["metadata.audio_properties","metadata.version","rhythm.onset_rate"]
sorted_namespaces = ["metadata", "lowlevel", "rhythm", "tonal", "sfx"]
desc_exceptions = ["metadata.audio_properties", "metadata.version", "rhythm.onset_rate"]

example_url = "https://freesound.org/api/sounds/1234/analysis/?api_key=53b80e4d8a674ccaa80b780372103680&all=True"

req = urllib.request.Request(example_url)
resp = urllib.request.urlopen(req)
top = json.loads(resp.read())


mapping = dict()
for line in open("algorithm_mapping.csv"):
desc,alg = line[:-1].split(",")
mapping[desc] = alg
desc, alg = line[:-1].split(",")
mapping[desc] = alg

print(header)

for k in sorted_namespaces:
ns = k[0].upper()+k[1:]
print(ns+ " Descriptors")
print(">>>>>>>>>>>>>>>>>>>>\n\n")
for d in top[k].keys():
descriptor = k+"."+d
print(descriptor)
print("-------------------------")
print("\n::\n")
print(curl_str+k+"/"+d)
if mapping[descriptor] !="None":
print("\n**Essentia Algorithm**\n")
print(algorithm_doc_str+mapping[descriptor]+".html")
stats = top[k][d]
if descriptor in desc_exceptions:
print("\n")
continue
if isinstance(stats, dict):
print("\n\n**Stats**::\n\n")
for s in stats.keys():
print("/"+s)

print("\n\n**Distribution in Freesound**\n")

if "mean" in stats.keys():
if isinstance(stats['mean'], list):
for i in range(len(stats['mean'])):
img = image_str+descriptor+".mean.%03d"%i
print(img+".png")
print(height_str)
else:
print(image_str+descriptor+".mean.png")
print(height_str)
elif isinstance(stats, float) or isinstance(stats, int):
print(image_str+descriptor+".png")
print(height_str)
print("\n\n")
ns = k[0].upper() + k[1:]
print(ns + " Descriptors")
print(">>>>>>>>>>>>>>>>>>>>\n\n")
for d in top[k].keys():
descriptor = k + "." + d
print(descriptor)
print("-------------------------")
print("\n::\n")
print(curl_str + k + "/" + d)
if mapping[descriptor] != "None":
print("\n**Essentia Algorithm**\n")
print(algorithm_doc_str + mapping[descriptor] + ".html")
stats = top[k][d]
if descriptor in desc_exceptions:
print("\n")
continue
if isinstance(stats, dict):
print("\n\n**Stats**::\n\n")
for s in stats.keys():
print("/" + s)

print("\n\n**Distribution in Freesound**\n")

if "mean" in stats.keys():
if isinstance(stats['mean'], list):
for i in range(len(stats['mean'])):
img = image_str + descriptor + ".mean.%03d" % i
print(img + ".png")
print(height_str)
else:
print(image_str + descriptor + ".mean.png")
print(height_str)
elif isinstance(stats, float) or isinstance(stats, int):
print(image_str + descriptor + ".png")
print(height_str)
print("\n\n")
36 changes: 19 additions & 17 deletions _docs/api/generate_analysis_documentation/generate_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,59 @@
import gaia2
import pylab as pl

OUT_FOLDER = 'out_plots' # Must be created
GAIA_INDEX_FILE = 'fs_index.db' # File with gaia index
BINS = 100 # Bins per histogram plot
OUT_FOLDER = 'out_plots' # Must be created
GAIA_INDEX_FILE = 'fs_index.db' # File with gaia index
BINS = 100 # Bins per histogram plot


def plot_histogram(pool, label, x_label_ticks = False):
def plot_histogram(pool, label, x_label_ticks=False):
fig = pl.figure()
ax = fig.add_subplot(111)

if not x_label_ticks:
range_min = min(pool) #percentile(pool, 10)
range_max = max(pool) #percentile(pool, 90)
range_min = min(pool) #percentile(pool, 10)
range_max = max(pool) #percentile(pool, 90)
else:
range_min = min(pool)
range_max = max(pool) + 1

n_bins = BINS
if x_label_ticks:
n_bins = len(x_label_ticks)
n, bins, patches = ax.hist(pool, bins=n_bins, range=(float(range_min), float(range_max)), log=False, histtype='stepfilled')
n, bins, patches = ax.hist(
pool, bins=n_bins, range=(float(range_min), float(range_max)), log=False, histtype='stepfilled'
)
pl.title('Distribution: %s' % label)
if not x_label_ticks:
ax.ticklabel_format(axis='x', style='sci', scilimits=(-3,3))
ax.ticklabel_format(axis='x', style='sci', scilimits=(-3, 3))
else:
pl.xticks(list(range(0, len(x_label_ticks))),[' %s'%tick for tick in x_label_ticks])
ax.ticklabel_format(axis='y', style='sci', scilimits=(-2,2))
pl.xticks(list(range(0, len(x_label_ticks))), [' %s' % tick for tick in x_label_ticks])
ax.ticklabel_format(axis='y', style='sci', scilimits=(-2, 2))
ax.set_xlabel('Value')
ax.set_ylabel('Frequency of occurrence')
ax.grid(True)
pl.savefig('%s/%s.png' % (OUT_FOLDER, label[1:]))
pl.close()


ds = gaia2.DataSet()
dataset_path = GAIA_INDEX_FILE
ds.load(dataset_path)
transformation_history = ds.history().toPython()
normalization_coeffs = None
for i in range(0,len(transformation_history)):
if transformation_history[-(i+1)]['Analyzer name'] == 'normalize':
normalization_coeffs = transformation_history[-(i+1)]['Applier parameters']['coeffs']
for i in range(0, len(transformation_history)):
if transformation_history[-(i + 1)]['Analyzer name'] == 'normalize':
normalization_coeffs = transformation_history[-(i + 1)]['Applier parameters']['coeffs']
print([x for x in normalization_coeffs.keys() if (".tonal" in x and "chords" in x)])
descriptor_names = ds.layout().descriptorNames()
point_names = ds.pointNames()
example_point = ds.point(point_names[0])
reject_stats = ['dmean', 'dmean2', 'dvar', 'dvar2', 'max', 'min', 'var']

reject_stats = ['dmean', 'dmean2', 'dvar', 'dvar2', 'max', 'min', 'var']

for descriptor_name in descriptor_names:
region = ds.layout().descriptorLocation(descriptor_name)
if region.lengthType() == gaia2.VariableLength or descriptor_name.split('.')[-1] in reject_stats:
continue
continue

try:
example_value = example_point.value(descriptor_name)
Expand Down Expand Up @@ -112,4 +114,4 @@ def plot_histogram(pool, label, x_label_ticks = False):
key_ids[key] = j
pool = [key_ids[value] for value in pool]

plot_histogram(pool, descriptor_name, x_label_ticks = keys)
plot_histogram(pool, descriptor_name, x_label_ticks=keys)
23 changes: 10 additions & 13 deletions _docs/api/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []


# -- Options for HTML output ---------------------------------------------------

# The theme to use for HTML and HTML Help pages. Major themes that come with
Expand Down Expand Up @@ -159,7 +158,6 @@
# Output file base name for HTML help builder.
htmlhelp_basename = 'FreesoundAPIdoc'


# -- Options for LaTeX output --------------------------------------------------

# The paper size ('letter' or 'a4').
Expand All @@ -171,23 +169,22 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'FreesoundAPI.tex', 'Freesound API Documentation',
'Frederic Font', 'manual'),
('index', 'FreesoundAPI.tex', 'Freesound API Documentation', 'Frederic Font', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None

# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False

# Additional stuff for the LaTeX preamble.
#latex_preamble = ''
# Additional stuff for the LaTeX preamble.
#latex_preamble = ''

# Documents to append as an appendix to all manuals.
#latex_appendices = []
# Documents to append as an appendix to all manuals.
#latex_appendices = []

# If false, no module index is generated.
#latex_use_modindex = True
# If false, no module index is generated.
#latex_use_modindex = True
Loading
Loading