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
use PEP 420: implicit namespace package #990
Conversation
module = importlib.import_module(name) | ||
except Exception as ex: | ||
print(ex) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this because I think we want to raise an error if a module doesn't import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, better to fail loudly.
It turns out that this has some implications for our package data (currently just the placeholder directories for translation catalogs). See discussion: pypa/setuptools#3323
I'll deal with this separately in #644. |
@@ -77,7 +69,7 @@ | |||
# | |||
# This is also used if you do content translation via gettext catalogs. | |||
# Usually you set "language" from the command line for these cases. | |||
language = None | |||
language = 'en' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing an error in the ReadTheDocs build, probably due to a sphinx update.
@phargogh this is finally ready! The RTD build issues fixed themselves in time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very exciting! I just had a few very small comments and suggestions, but overall this is looking good!
doc/api-docs/conf.py
Outdated
INVEST_ROOT_DIR = os.path.join(DOCS_SOURCE_DIR, '..', '..') | ||
INVEST_BUILD_DIR = os.path.join(INVEST_ROOT_DIR, 'build') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these used anywhere else now that we're properly defining INVEST_LIB_DIR
? Might they be able to be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, they can be removed
module = importlib.import_module(name) | ||
except Exception as ex: | ||
print(ex) | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, better to fail loudly.
doc/api-docs/conf.py
Outdated
'_core', # anything ending in '_core' | ||
'recmodel_server', | ||
'recmodel_workspace_fetcher' | ||
'recmodel_workspace_fetcher', | ||
'natcap.invest.ui' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the RTD-rendered docs (https://invest--990.org.readthedocs.build/en/990/api.html for this PR) it looks like maybe this exclusion isn't working. Maybe it never worked? In any case, it would probably be nice to exclude packages, or else just have everything in there since it is in the source code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is working as expected - it's excluding those from the model entrypoints file models.rst
. But they're still in the API docs.
The list of excluded modules was unnecessary, though. I refactored so that any module with an ARGS_SPEC
is included in models.rst
.
doc/api-docs/conf.py
Outdated
# all modules with an execute function should have an ARGS_SPEC | ||
model_title = module.ARGS_SPEC['model_name'] | ||
all_modules[model_title] = name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so much better than our prior reliance on module-level docstrings!
namespace_packages=['natcap'], | ||
packages=[ | ||
'natcap', | ||
'natcap.invest', | ||
'natcap.invest.coastal_blue_carbon', | ||
'natcap.invest.delineateit', | ||
'natcap.invest.ui', | ||
'natcap.invest.ndr', | ||
'natcap.invest.sdr', | ||
'natcap.invest.recreation', | ||
'natcap.invest.scenic_quality', | ||
'natcap.invest.seasonal_water_yield', | ||
], | ||
packages=find_namespace_packages('src'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! It was not immediately clear to me from this function name that normal packages within natcap.invest
would also be captured, but that does seem to be the behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's confusing! pypa/setuptools#3427
doc/api-docs/conf.py
Outdated
from datetime import datetime | ||
import importlib | ||
import itertools | ||
import os | ||
import pkgutil | ||
import subprocess | ||
import sys | ||
|
||
from datetime import datetime | ||
from sphinx.ext import apidoc | ||
from unittest.mock import MagicMock | ||
|
||
import natcap.invest | ||
from sphinx.ext import apidoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just check these imports and make sure that we aren't importing anything we no longer need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, a couple of them aren't needed any more
Co-authored-by: James Douglass <jamesdouglassusa@gmail.com>
@phargogh I'd like to squash these commits before merging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks@emlys !
Description
Fixes #967
src/natcap/__init__.py
to makenatcap
an implicit namespace packagenamespace_packages
parameter tosetup
. Since we already list out all packages, I don't think we need to change anything else: https://setuptools.pypa.io/en/latest/userguide/package_discovery.htmldoc/api-docs/conf.py
to work with the implicit namespace package, and some minor refactoring:natcap.invest
, not the build/lib* locationChecklist
Updated HISTORY.rst (if these changes are user-facing)Updated the user's guide (if needed)Tested the affected models' UIs (if relevant)