Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Jun 13, 2024
1 parent 73e64e4 commit e4759a7
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 83 deletions.
12 changes: 2 additions & 10 deletions irs_reader/filing.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import io
import json
import os
import sys
from collections import OrderedDict
from xml.parsers.expat import ExpatError

import xmltodict

from .file_utils import get_local_path, get_s3_URL, stream_download, validate_object_id
from .settings import IRS_READER_ROOT, KNOWN_SCHEDULES
from .type_utils import (
dictType,
listType,
noneType,
orderedDictType,
strType,
unicodeType,
)
from .settings import KNOWN_SCHEDULES
from .type_utils import dictType, listType, orderedDictType


class InvalidXMLException(Exception):
Expand Down
4 changes: 2 additions & 2 deletions irs_reader/irsx_cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import argparse

from .filing import Filing
from .settings import IRS_READER_ROOT, KNOWN_SCHEDULES
from .text_format_utils import *
from .settings import KNOWN_SCHEDULES
from .text_format_utils import to_csv, to_json, to_txt
from .xmlrunner import XMLRunner


Expand Down
1 change: 0 additions & 1 deletion irs_reader/irsx_index_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import sys
from datetime import date

from .file_utils import get_index_file_URL, get_local_index_path, stream_download
Expand Down
3 changes: 1 addition & 2 deletions irs_reader/irsx_retrieve_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse
import os
import sys
from zipfile import ZipFile

from .file_utils import stream_download
Expand Down Expand Up @@ -79,7 +78,7 @@ def run_cli_retrieve_main(args_read):
print(
"""
Please visit https://www.irs.gov/charities-non-profits/form-990-series-downloads
To see if any additional files are available.
To see if any additional files are available.
"""
)
for year in args_read.year:
Expand Down
2 changes: 1 addition & 1 deletion irs_reader/keyerror_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ignorable_keyerrors = ["/ReturnHeader/BuildTS"]

## Todo: put in 2013 / 2015 series canonicals.
# Todo: put in 2013 / 2015 series canonicals.
# 2013 vars that no longer exist
discontinued_2013_vars = [
"/IRS990ScheduleA/CertificationInd",
Expand Down
5 changes: 2 additions & 3 deletions irs_reader/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys

from .dir_utils import mkdir_p

Expand Down Expand Up @@ -117,7 +116,7 @@
]

# 2020 is experimental
# see https://www.irs.gov/charities-non-profits/ty2020-xml-schemas-and-business-rules-for-exempt-organizations-modernized-e-file
# see https://www.irs.gov/charities-non-profits/ty2020-xml-schemas-and-business-rules-for-exempt-organizations-modernized-e-file # noqa

# We can capture the group structure for these so it doesn't break
# but these versions ARE NOT supported and aren't mapped to IRSx variables
Expand Down Expand Up @@ -145,6 +144,6 @@
mkdir_p([WORKING_DIRECTORY, INDEX_DIRECTORY])

try:
from .local_settings import *
from .local_settings import * # noqa
except ImportError:
pass
4 changes: 2 additions & 2 deletions irs_reader/sked_dict_reader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .flatten_utils import flatten
from .keyerror_utils import ignorable_keyerror
from .settings import LOG_KEY
from .type_utils import (
dictType,
listType,
Expand Down Expand Up @@ -228,7 +227,8 @@ def _parse_json(self, json_node, parent_path=""):
pass

elif this_node_type == strType:
msg = "String '%s'" % json_node
pass
# msg = "String '%s'" % json_node
# self.logging.debug(msg)
else:
raise Exception("Unhandled type: %s" % (type(json_node)))
Expand Down
15 changes: 2 additions & 13 deletions irs_reader/standardizer.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
import collections
import csv
import os
import sys

# import logging
from datetime import datetime

from .settings import KEYERROR_LOG, METADATA_DIRECTORY
from .sked_dict_reader import SkedDictReader
from .type_utils import listType

if sys.version_info >= (3, 0):
import csv
else:
import unicodecsv as csv
from .settings import METADATA_DIRECTORY


class Standardizer(object):
Expand Down
6 changes: 3 additions & 3 deletions irs_reader/text_format_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import unicodecsv

from .standardizer import Documentizer, Standardizer, VersionDocumentizer
from .standardizer import VersionDocumentizer

BRACKET_RE = re.compile(r"\[.*?\]")

Expand Down Expand Up @@ -114,7 +114,7 @@ def to_txt(
for result in results:
for this_result in result["csv_line_array"]:

#### Collect the variables we need
# Collect the variables we need
vardata = None
textoutput = "\n" # This is what we'll eventually write out
this_result["form"] = this_result["xpath"].split("/")[1]
Expand All @@ -137,7 +137,7 @@ def to_txt(
)
this_result["description"] = debracket(raw_description)

#### Write the output, now that we've got the vars
# Write the output, now that we've got the vars

if this_sked_name != this_result["form"]:
textoutput += (
Expand Down
32 changes: 2 additions & 30 deletions irs_reader/xmlrunner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from .filing import Filing
from .settings import (
ALLOWED_VERSIONSTRINGS,
CSV_ALLOWED_VERSIONSTRINGS,
WORKING_DIRECTORY,
)
from .settings import ALLOWED_VERSIONSTRINGS, CSV_ALLOWED_VERSIONSTRINGS
from .sked_dict_reader import SkedDictReader
from .standardizer import Documentizer, Standardizer, VersionDocumentizer
from .standardizer import Documentizer, Standardizer

# from .log_utils import configure_logging
from .type_utils import listType
Expand Down Expand Up @@ -149,30 +145,6 @@ def run_filing(self, object_id, verbose=False):
print("Filing version %s isn't supported for this operation" % this_version)
return this_filing

"""
def run_from_filing_obj(self, this_filing, verbose=False):
#Run from a pre-created filing object.
self.whole_filing_data = []
self.filing_keyerr_data = []
this_filing.process(verbose=verbose)
object_id = this_filing.get_object_id()
this_version = this_filing.get_version()
if this_version in ALLOWED_VERSIONSTRINGS:
this_version = this_filing.get_version()
schedules = this_filing.list_schedules()
ein = this_filing.get_ein()
for sked in schedules:
sked_dict = this_filing.get_schedule(sked)
self._run_schedule(sked, object_id, sked_dict, ein)
this_filing.set_result(self.whole_filing_data)
this_filing.set_keyerrors(self.filing_keyerr_data)
return this_filing
else:
return this_filing
"""

def run_sked(self, object_id, sked, verbose=False):
"""
sked is the proper name of the schedule:
Expand Down
7 changes: 1 addition & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
install_requires=["requests", "xmltodict", "unicodecsv"],
extras_require={
"tests": [
"nose",
"requests",
"xmltodict",
"unicodecsv",
"tox",
"tox-pyenv",
"pytest",
]
},
packages=["irsx"],
Expand Down
19 changes: 9 additions & 10 deletions tests/tests.py → tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

import pytest

from irs_reader.file_utils import validate_object_id
from irs_reader.filing import Filing
from irs_reader.irsx_cli import get_parser as get_cli_parser
from irs_reader.irsx_cli import run_main as run_cli_main
from irs_reader.irsx_index_cli import get_cli_index_parser, run_cli_index_main
from irs_reader.object_ids import (object_ids_2015, object_ids_2016,
object_ids_2017)
from irs_reader.settings import WORKING_DIRECTORY
from irs_reader.standardizer import Standardizer
from irs_reader.xmlrunner import XMLRunner
from irsx.file_utils import validate_object_id
from irsx.filing import Filing
from irsx.irsx_cli import get_parser as get_cli_parser
from irsx.irsx_cli import run_main as run_cli_main
from irsx.irsx_index_cli import get_cli_index_parser, run_cli_index_main
from irsx.object_ids import object_ids_2015, object_ids_2016, object_ids_2017
from irsx.settings import WORKING_DIRECTORY
from irsx.standardizer import Standardizer
from irsx.xmlrunner import XMLRunner

FILING_2015V21 = "201642229349300909"
FILING_2015V21_skeds = [
Expand Down

0 comments on commit e4759a7

Please sign in to comment.