Skip to content

Expand --remote-data to allow different modes#5506

Merged
eteq merged 15 commits intoastropy:masterfrom
astrofrog:remote-astropy
Dec 2, 2016
Merged

Expand --remote-data to allow different modes#5506
eteq merged 15 commits intoastropy:masterfrom
astrofrog:remote-astropy

Conversation

@astrofrog
Copy link
Member

@astrofrog astrofrog commented Nov 25, 2016

(This came out of a discussion in #5496)

This was a bit of work to get right, but with this pull request, it is now possible to optionally decorate remote tests using:

@remote_data(source='astropy')

Such tests are run by default but will fail if the test tries to access non-astropy data (i.e. data not on data.astropy.org). The --remote-data option can now take three values:

python setup.py test --remote-data=none
python setup.py test --remote-data=astropy
python setup.py test --remote-data=any

The first skips all tests with @remote_data, the second (which is the default) skips remote tests that don't specify source='astropy' (or specify source='any' explicitly), and the third runs all remote tests.

Note that this also preserves backward-compatibility with the plain option:

python setup.py test --remote-data

which is translated to --remote-data=any.

So this is backward-compatible and now allows tests such as those for WCSAxes to run on Travis without enabling ALL the remote tests. Since the data.astropy.org server is pretty stable (unlike e.g. VO services), I don't think this should cause any issues.

Note that this can be expanded in future to allow more modes now that it is a string option!

cc @mhvk @eteq @bsipocz @pllim @MSeifert04 @keflavich @Cadair

@MSeifert04
Copy link
Contributor

MSeifert04 commented Nov 25, 2016

I think remote-data=none should be assumed by default. I don't want tests to fail just because I currently have no connection or have a connection but only with limited traffic.

Otherwise: no objections. But I haven't looked to closely on the code.

@astrofrog
Copy link
Member Author

astrofrog commented Nov 25, 2016

I think remote-data=none should be assumed by default. I don't want tests to fail just because I currently have no connection.

Ok, that would be fine by me, as long as we can set --remote-data=astropy as the default on the CI services?

@astrofrog
Copy link
Member Author

So the failure seems to happen because data.astropy.org gets translated into an IP address at some point, so we need to also find a way to whitelist the current IP address of data.astropy.org.

if allow_astropy_data:
data_astropy_org_ip = socket.gethostbyname('data.astropy.org')
valid_hosts += ('data.astropy.org', 'astropy.stsci.edu', data_astropy_org_ip)
for valid_host in ('data.astropy.org', 'astropy.stsci.edu'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. I am not aware that we have astropy.stsci.edu. Is this a planned addition for 1.3?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data.astropy.org is astropy.stsci.edu :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Could you please email me the details? Thanks!

before distutils/setuptools try to parse the command-line options.
"""
def __init__(cls, name, bases, dct):
for i in range(len(sys.argv)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range(len(...)) is something of a do-not in my opinion, I think a more elegant way would be:

try:
    idx = sys.argv.index('--remote-data')
except ValueError:
    pass
else:
    sys.argv[idx] = '--remote-data=any'

but it just does exactly the same, so keep whichever you like more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

run these tests.
remote_data : {'none', 'astropy', 'any'}, optional
Controls whether to run tests marked with @remote_data. This can be
set to run no tests with remote data (``no``), only ones that use
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no should be none

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

parser.addoption("--remote-data", action="store_true",

# The following means that if --remote-data is not specified, the default
# is 'astropy', but if it is specified without arguments, it defaults to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the default is none.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah but if you do --remote-data on its own, it does the old behavior and defaults to any

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the first sentence: The following means that if --remote-data is not specified, the default is 'astropy'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, fixed

raise ValueError("source should be 'astropy' or 'any'")

if remote_data_config == 'none':
if source in ('astropy', 'any'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always true because you already raised an exception if source not in ('astropy', 'any').

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

assert True
if pytestconfig.getoption('remote_data') == 'none':
pytest.fail('@remote_data was not skipped with remote_data=none')
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This else clause is superfluous, no? The same package data gets downloaded on line 42.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@mhvk
Copy link
Contributor

mhvk commented Nov 29, 2016

Had a look only now, but this looks very good. One nitpicky comment only.

@mhvk
Copy link
Contributor

mhvk commented Nov 29, 2016

One more comment: I think this would warrant a changelog entry.

@astrofrog
Copy link
Member Author

@mhvk - I've added a changelog entry

@mhvk
Copy link
Contributor

mhvk commented Nov 29, 2016

OK, great. I'm happy for this to be merged once the tests have passed.

@eteq
Copy link
Member

eteq commented Dec 1, 2016

This is in principal 👍 from me, and I didn't see any issues in a quick review. But one thing I'm concerned about: how does this affect affiliated packages that may be using the remote_data machinery? Specifically, if they have set it in the setup.cfg, does this still work?

@eteq
Copy link
Member

eteq commented Dec 1, 2016

Answered my own question: if I add the following to an affiliated package's setup.cfg:

[test]
remote_data = 1

with the current master, this correctly causes the default python setup.py test to behave like --remote-data is set. With this PR, it leads to:

E               urllib.error.URLError: <urlopen error An attempt was made to connect to the internet by a test that was not marked `remote_data`. The requested host was: github.com>

But with this PR, I can get it all working again by doing

[test]
remote_data = any

So the fix is pretty easy. Moreover, I think this PR is an improvement on this behavior, because before there was no way to override the setup.cfg state, whereas now at the command line --remote-data=none turns off a default of it being on.

The question is: do we accept this subtle backwards incompatibility? I know I've talked to some people about using setup.cfg in the manner I've outlined above in their affiliated packages, but I can't find any instances actually in the wild. So maybe we just accept the possibility? Or should there be a note about this in the changelog or something?

@astrofrog
Copy link
Member Author

@eteq - I think it should now be fixed to be backward-compatible, with a deprecation warning.

@eteq
Copy link
Member

eteq commented Dec 2, 2016

Looks great. The one remaining test is delayed (for an unclear amount of time) due to a travis OS X problem. Hard to see how that could be an issue here, so will merge to let #5496 get its test updated APAP.

@eteq eteq merged commit 732fb94 into astropy:master Dec 2, 2016
@MSeifert04
Copy link
Contributor

I stopped the OSX build to free some workers for the other PRs.

@bsipocz
Copy link
Member

bsipocz commented Feb 14, 2017

@astrofrog - I'm fairly certain that this PR broke the coverage reporting (see #5701). The PR merged just before this still gets the report on coveralls, while this one looks perfectly normal on travis, doesn't trigger a report on coveralls. Any ideas?

@astrofrog
Copy link
Member Author

@bsipocz - good catch! The issue is that the following comparison now fails:

if [[ $SETUP_CMD == 'test --coverage' ]]; then

We should just check for the presence of --coverage in SETUP_CMD.

Sorry for breaking things! :-/

@astrofrog astrofrog deleted the remote-astropy branch November 14, 2018 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants