Skip to content

Commit

Permalink
use environmental variables instead of local_settings.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fgregg committed Jun 13, 2024
1 parent 277f3c9 commit d0be7fd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
18 changes: 4 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,21 +289,11 @@ For example:

### Legacy configuration ###

You also can configure IRSx's cache location by setting the local_settings.py file. To figure out where that settings file is, log in to a terminal and type:

>>> from irsx.settings import IRSX_SETTINGS_LOCATION
>>> IRSX_SETTINGS_LOCATION
'/long/path/to/lib/python3.6/site-packages/irsx/settings.py'

[ If you get an error, try upgrading irsx with `pip install irsx --upgrade` -- this feature was added in 0.1.1. ]


Go to that directory. You can either modify the settings.py file or the local_settings.py file. To do the latter, first `cd` into the directory where the settings files live and run:

$ cp local_settings.py-example local_settings.py

Then edit local_settings.py to set WORKING\_DIRECTORY to where the raw xml files are found.
You also can configure IRSx's cache location by setting an environmntal variable.

```console
> export IRSX_CACHE_DIRECTORY=/where/you/like
```

## IRSx from python

Expand Down
16 changes: 0 additions & 16 deletions irs_reader/local_settings-example.py

This file was deleted.

26 changes: 18 additions & 8 deletions irs_reader/settings.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import os

import environ

from .dir_utils import mkdir_p

IRS_READER_ROOT = os.path.abspath(os.path.dirname(__file__))
env = environ.Env()


# This is the URL to amazon's bucket, could use another synced to it
IRS_XML_HTTP_BASE = "https://gt990datalake-rawdata.s3.amazonaws.com/EfileData/XmlFiles"
IRS_READER_ROOT = env(
"IRS_READER_ROOT", default=os.path.abspath(os.path.dirname(__file__))
)

# This is the URL to Giving Tuesday's bucket, could use another synced to it
IRS_XML_HTTP_BASE = env(
"IRS_XML_HTTP_BASE",
default="https://gt990datalake-rawdata.s3.amazonaws.com/EfileData/XmlFiles",
)

# It can be hard to locate this.
IRSX_SETTINGS_LOCATION = os.path.join(IRS_READER_ROOT, "settings.py")

# Defaults to the same directory as this settings file, but you can override
# with the `IRSX_CACHE_DIRECTORY` environment variable
IRSX_CACHE_DIRECTORY = os.environ.get("IRSX_CACHE_DIRECTORY", IRS_READER_ROOT)
IRSX_CACHE_DIRECTORY = env("IRSX_CACHE_DIRECTORY", default=IRS_READER_ROOT)

# The directory we put files in while we're processing them
WORKING_DIRECTORY = os.environ.get(
"IRSX_WORKING_DIRECTORY", os.path.join(IRSX_CACHE_DIRECTORY, "XML")
WORKING_DIRECTORY = env(
"IRSX_WORKING_DIRECTORY", default=os.path.join(IRSX_CACHE_DIRECTORY, "XML")
)
# Helpful to keep these around for lookup purposes
INDEX_DIRECTORY = os.environ.get(
"IRSX_INDEX_DIRECTORY", os.path.join(IRSX_CACHE_DIRECTORY, "CSV")
INDEX_DIRECTORY = env(
"IRSX_INDEX_DIRECTORY", default=os.path.join(IRSX_CACHE_DIRECTORY, "CSV")
)

IRS_INDEX_BASE = "https://apps.irs.gov/pub/epostcard/990/xml/%s/index_%s.csv"
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
setup_requires=[
"setuptools",
],
install_requires=["requests", "xmltodict", "unicodecsv"],
install_requires=["requests", "xmltodict", "django-environ"],
extras_require={
"tests": [
"pytest",
Expand Down

0 comments on commit d0be7fd

Please sign in to comment.