diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..0106142e3 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,57 @@ +name: test + +on: [pull_request] + +jobs: + test: + name: Test Python ${{ matrix.python-version }} + runs-on: ubuntu-latest + + strategy: + matrix: + python-version: [3.7, 3.8, 3.9] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip + restore-keys: | + ${{ runner.os }}-pip + - name: Test + run: | + pip install --upgrade nox + nox -s test-${{ matrix.python-version }} + + lint: + name: Check Linting + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + - name: Pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip + restore-keys: | + ${{ runner.os }}-pip + - name: Lint + run: | + pip install --upgrade nox + nox -s lint + + + + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e066820c8..000000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: python -python: - - "3.7" - - "3.8" - - "3.9" -cache: - directories: - - $HOME/.cache/pip -before_install: - - pip install setuptools pip pytest --upgrade -install: - - pip install -e .[dev] -script: - - make check html-docs diff --git a/Makefile b/Makefile index 71ec81be1..07a8c53b2 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,5 @@ GH_PAGES_SOURCES = planet docs Makefile -check: - py.test --doctest-modules planet tests - flake8 planet tests - -coverage: - py.test --doctest-modules --cov planet --cov-report=html:htmlcov tests planet/api - pex: # disable-cache seemed required or the older version would be used pex . -o dist/planet -e planet.scripts:main --disable-cache diff --git a/noxfile.py b/noxfile.py new file mode 100644 index 000000000..8ce7a4f4b --- /dev/null +++ b/noxfile.py @@ -0,0 +1,41 @@ +import nox + +nox.options.stop_on_first_error = True +nox.options.reuse_existing_virtualenvs = True +# nox.options.keywords = "test + check" + +source_files = ("planet", "tests", "setup.py", "noxfile.py") +# docs_requirements = ("mkdocs", "mkdocs-material", "mkautodoc>=0.1.0") + + +@nox.session(python=["3.7", "3.8", "3.9"]) +def test(session): + session.install("-e", ".[test]") + + options = session.posargs + if "-k" or "-x" in options: + options.append("--no-cov") + + session.run("pytest", "-v", *options) + + +@nox.session +def lint(session): + session.install("-e", ".[dev]") + + session.run("flake8", *source_files) + +# @nox.session +# def docs(session): +# session.install("--upgrade", *docs_requirements) +# session.install("-e", ".") +# +# session.run("mkdocs", "build") +# +# +# @nox.session(reuse_venv=True) +# def watch(session): +# session.install("--upgrade", *docs_requirements) +# session.install("-e", ".") +# +# session.run("mkdocs", "serve") diff --git a/planet/api/_fatomic.py b/planet/api/_fatomic.py deleted file mode 100644 index 5d2949c78..000000000 --- a/planet/api/_fatomic.py +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright 2015 Planet Labs, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -''' Provide atomic file support - a subset of `fatomic` included here -(https://github.com/abarnert/fatomic) as upstream is not in pypi -''' -import contextlib -import errno -import os -import shutil -import tempfile -import types - - -@contextlib.contextmanager -def atomic_open(filename, mode, *args, **kwargs): - if mode[0] not in 'wxa' or len(mode) > 1 and mode[1] == '+': - raise ValueError("invalid mode: '{}'".format(mode)) - f = tempfile.NamedTemporaryFile(mode=mode, - prefix=os.path.basename(filename), - dir=os.path.dirname(filename), - suffix='.tmp', - delete=False) - # track: explicitly discarded, normal/abnormal completion - _discard = [None] - try: - if mode[0] == 'a': - try: - with open(filename, 'r'+mode[1:], *args, **kwargs) as fin: - shutil.copyfileobj(fin, f) - except (OSError, IOError) as e: - if e.errno == errno.ENOENT: - pass - - def discard(self, _discard=_discard): - # explicit discard - _discard[0] = True - f.discard = types.MethodType(discard, f) - yield f - # normal completion - if not _discard[0]: - _discard[0] = False - # block and force discarding - finally: - f.close() - # if we didn't complete or were aborted, delete - if _discard[0] is None or _discard[0]: - os.unlink(f.name) - else: - os.replace(f.name, filename) diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index c7129f646..000000000 --- a/requirements-dev.txt +++ /dev/null @@ -1,4 +0,0 @@ -pytest-asyncio==0.14.0 -respx==0.16.3 -sphinx-autobuild==2020.9.1 -tox==3.20.1 diff --git a/setup.cfg b/setup.cfg index 5a8e9329c..fc457e155 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,3 +3,20 @@ universal: 1 [metadata] license_file: LICENSE + +[tool:pytest] +addopts = + --cov=planet + --cov=tests + --cov-report=term-missing + --cov-report=xml + --cov-fail-under 95.69 + -rxXs + +[coverage:run] +source = planet,tests +branch = True + +[coverage:report] +skip_covered = True +show_missing = True diff --git a/setup.py b/setup.py index 775652d10..3a1736bc8 100644 --- a/setup.py +++ b/setup.py @@ -11,21 +11,10 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from pathlib import Path -from codecs import open as codecs_open from setuptools import setup, find_packages - -# Get the long description from the relevant file -# TODO: consider moving to markdown from rst at this point -try: - with codecs_open('README.rst', encoding='utf-8') as f: - long_description = f.read() -except: - # @todo for now, fall back to this - pex fails to resolve the README - long_description = '' - - with open('planet/api/__version__.py') as f: for line in f: if line.find("__version__") >= 0: @@ -35,25 +24,28 @@ continue +install_requires = [ + 'httpx>=0.16', + 'tqdm>=4.56', + 'pywin32 >= 1.0;platform_system=="Windows"' +] + test_requires = [ 'pytest', 'pytest-asyncio', - 'respx' + 'pytest-cov', + 'respx==0.16.3' ] -dev_requires = [ +lint_requires = [ 'flake8', - 'setuptools', - 'pex', - 'pytest-cov', - 'sphinx', - 'wheel', ] + setup(name='planet', version=version, description=u"Planet API Client", - long_description=long_description, + long_description=Path("README.md").read_text("utf-8"), classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'Environment :: Console', @@ -82,7 +74,7 @@ ], extras_require={ 'test': test_requires, - 'dev': test_requires + dev_requires, + 'dev': test_requires + lint_requires, }, entry_points=""" [console_scripts] diff --git a/tests/unit/test_atomic.py b/tests/unit/test_atomic.py deleted file mode 100644 index 63b1234c7..000000000 --- a/tests/unit/test_atomic.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright 2015 Planet Labs, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import os -from planet.api._fatomic import atomic_open - - -def test_atomic_open(tmpdir): - outfile = str(tmpdir.join('foo')) - - def lsdir(): - return os.listdir(str(tmpdir)) - - def assert_content_is(expected): - with open(outfile, 'r') as fp: - assert fp.read() == expected - - # success case - with atomic_open(outfile, 'w') as fp: - fp.write('bar') - assert_content_is('bar') - # no tmp files remain - assert ['foo'] == lsdir() - - # exception during write, assert file remains untouched - try: - with atomic_open(outfile, 'w') as fp: - fp.write('bazzy') - raise Exception('drat') - except Exception: - assert_content_is('bar') - else: - assert False - # no tmp files remain - assert ['foo'] == lsdir() - - # manual discarding - with atomic_open(outfile, 'w') as fp: - fp.write('bazzy') - fp.discard() - assert_content_is('bar') - # no tmp files remain - assert ['foo'] == lsdir() diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 66963ede2..000000000 --- a/tox.ini +++ /dev/null @@ -1,13 +0,0 @@ -# Tox (https://tox.readthedocs.io/) is a tool for running tests -# in multiple virtualenvs. This configuration file will run the -# test suite on all supported python versions. To use it, "pip install tox" -# and then run "tox" from this directory. - -[tox] -envlist = py37, py38, py39 - -[testenv] -deps = pytest -commands = - pip install -e .[dev] - pytest {posargs}