Skip to content

Commit

Permalink
packaging scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
JarronL committed Mar 13, 2018
1 parent 8c4c67c commit 33fe76e
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 36 deletions.
26 changes: 3 additions & 23 deletions .travis.yml.bak → .travis_TBI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,14 @@ env:

matrix:
include:
# do the actual tests against dev version of POPPY
# - python: 2.7
# - python: 3.5

# Do a coverage test in Python 3.
- python: 3.6
env: SETUP_CMD='test --coverage'
env: SETUP_CMD='test'

# Try Astropy development version
- python: 3.6
env: SETUP_CMD='test' ASTROPY_VERSION=development

# Try older numpy versions
- python: 2.7
env: SETUP_CMD='test' NUMPY_VERSION=1.12
- python: 2.7
env: SETUP_CMD='test' NUMPY_VERSION=1.11

# Try released POPPY
- python: 3.6
env: SETUP_CMD='test' PIP_DEPENDENCIES='webbpsf jwxml'

allow_failures:
# Released WebbPSF may be missing new functionality used by dev pynrc
- env: SETUP_CMD='test' PIP_DEPENDENCIES='webbpsf jwxml'


# Command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
Expand All @@ -61,10 +43,9 @@ install:
# environment. In some cases, ci-helpers may not offer enough flexibility
# in how to install a package, in which case you can have additional
# commands in the install: section below.

- git clone git://github.com/astropy/ci-helpers.git
- source ci-helpers/travis/setup_conda.sh

#- source ci-helpers/travis/setup_conda_$TRAVIS_OS_NAME.sh
# As described above, using ci-helpers, you should be able to set up an
# environment with dependencies installed using conda and pip, but in some
# cases this may not provide enough flexibility in how to install a
Expand All @@ -74,8 +55,7 @@ install:
# section if they are needed before setting up conda) to install any
# other dependencies.

# Command to run tests, e.g. python setup.py test
script: tox
script: $MAIN_CMD $SETUP_CMD

# Assuming you have installed the travis-ci CLI tool, after you
# create the Github repo and add it to Travis, run the
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ lint: ## check style with flake8
flake8 pynrc tests

test: ## run tests quickly with the default Python
py.test
python setup.py test

test-all: ## run tests on every Python version with tox
tox
Expand Down
6 changes: 1 addition & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ A JWST NIRCam ETC and Simulator

**!!Under Development!!**

.. warning::

Under Development!!

pyNRC is a set of Python-based tools for planning observations with JWST NIRCam,
such as an ETC, a simple image slope simulator, and an enhanced data simulator.

Expand All @@ -41,7 +37,7 @@ realistic JWST images and spectra.

Documentation can be found at https://pynrc.readthedocs.io.

**Note**: pyNRC enables more modes than are officially allowed by the Observatory,
**Note:** pyNRC enables more modes than are officially allowed by the Observatory,
(ie., filter + coronagraphic combinations, subarray sizes, etc.).
Just because you can do something with pyNRC does not mean it will be supported.
Check out https://jwst-docs.stsci.edu/display/JTI/NIRCam+Observing+Modes for more information.
Expand Down
14 changes: 11 additions & 3 deletions pynrc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import astropy
from astropy import config as _config

import tempfile

class Conf(_config.ConfigNamespace):

# Path to data files for pynrc.
Expand All @@ -28,17 +30,23 @@ class Conf(_config.ConfigNamespace):
on_rtd = os.environ.get('READTHEDOCS') == 'True'

if on_rtd:
path = '/'
path = tempfile.gettempdir()
else:
path = os.getenv('PYNRC_PATH')
if path is None:
print("WARNING: Environment variable $PYNRC_PATH is not set!")
print(" Setting PYNRC_PATH to temporary directory.")
path = tempfile.gettempdir()
print(" {}".format(path))
#raise EnvironmentError("Environment variable $PYNRC_PATH is not set!")
if not os.path.isdir(path):
#print ("WARNING: PYNRC_PATH ({}) is not a valid directory path!".format(path))
raise IOError("PYNRC_PATH ({}) is not a valid directory path!".format(path))

if '/' not in path[-1]:
# Make sure there is a '/' at the end of the path name
if '/' not in path[-1]:
path += '/'
path = path + '/'

PYNRC_PATH = _config.ConfigItem(path, 'Directory path to data files \
required for pynrc calculations.')

Expand Down
6 changes: 3 additions & 3 deletions pynrc/nrc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2846,13 +2846,13 @@ def bp_2mass(filter):
dir = conf.PYNRC_PATH + 'throughputs/2MASS/'
if 'j' in filter.lower():
file = '2mass_j.txt'
name = 'J'
name = 'J-Band'
elif 'h' in filter.lower():
file = '2mass_h.txt'
name = 'H'
name = 'H-Band'
elif 'k' in filter.lower():
file = '2mass_ks.txt'
name = 'Ks'
name = 'Ks-Band'
else:
raise ValueError('{} not a valid 2MASS filter'.format(filter))

Expand Down
36 changes: 35 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
Expand All @@ -17,6 +20,37 @@
from pynrc.version import __version__
version = __version__

import os, sys

if sys.argv[-1] == 'publish':
os.system("python setup.py sdist upload")
os.system("python setup.py bdist_wheel upload")
print("You probably want to also tag the version now:")
print(" python setup.py tag")
sys.exit()

if sys.argv[-1] == 'tag':
os.system("git tag -a %s -m 'version %s'" % (version, version))
os.system("git push --tags")
sys.exit()


if sys.argv[-1] == 'test':
test_requirements = [
'pytest',
'coverage'
]
try:
modules = map(__import__, test_requirements)
except ImportError as e:
err_msg = e.message.replace("No module named ", "")
msg = "%s is not installed. Install your test requirments." % err_msg
raise ImportError(msg)

print('pyNRC testing not yet implemented!!')
os.system('py.test')
sys.exit()

# Get the long description from the README and HISTORY files
with open('README.rst') as readme_file:
readme = readme_file.read()
Expand All @@ -28,7 +62,7 @@
'numpy>=1.10.0',
'matplotlib>=1.5.0',
'scipy>=0.16.0',
'astropy>=1.2.0',
'astropy>=2.0.3',
'pysynphot>=0.9',
'poppy>=0.6.1',
'webbpsf>=0.6.0',
Expand Down
18 changes: 18 additions & 0 deletions tests/cli.py.old.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-

"""Console script for pynrc."""
import sys
import click


@click.command()
def main(args=None):
"""Console script for pynrc."""
click.echo("Replace this message by putting your code into "
"pynrc.cli.main")
click.echo("See click documentation at http://click.pocoo.org/")
return 0


if __name__ == "__main__":
sys.exit(main()) # pragma: no cover
16 changes: 16 additions & 0 deletions tests/test_pynrc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Tests for `pynrc` package."""

import pytest
#import pynrc


def test_the_obvious():
print('pyNRC testing not yet implemented!!')
assert True == True


if __name__ == '__main__':
pytest.main()
38 changes: 38 additions & 0 deletions tests/test_pynrc.py.old
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Tests for `pynrc` package."""

import pytest

from click.testing import CliRunner

import pynrc
from pynrc import cli


@pytest.fixture
def response():
"""Sample pytest fixture.
See more at: http://doc.pytest.org/en/latest/fixture.html
"""
# import requests
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')


def test_content(response):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string


def test_command_line_interface():
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert 'pynrc.cli.main' in result.output
help_result = runner.invoke(cli.main, ['--help'])
assert help_result.exit_code == 0
assert '--help Show this message and exit.' in help_result.output

0 comments on commit 33fe76e

Please sign in to comment.