Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[run]
branch = True

[report]
fail_under = 100
show_missing = True

[report]
omit =
*/_generated/*.py
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pip-log.txt
# Unit test / coverage reports
.coverage
.tox
nosetests.xml
.cache

# Translations
*.mo
Expand Down
8 changes: 2 additions & 6 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Running Tests
--------------

- To run all tests for ``gcloud-python`` on a single Python version, run
``nosetests`` from your development virtualenv (See
``py.test`` from your development virtualenv (See
*Using a Development Checkout* above).

- To run the full set of ``gcloud-python`` tests on all platforms, install
Expand Down Expand Up @@ -272,11 +272,7 @@ Test Coverage
-------------

- The codebase *must* have 100% test statement coverage after each commit.
You can test coverage via ``tox -e coverage``, or alternately by installing
``nose`` and ``coverage`` into your virtualenv, and running
``setup.py nosetests --with-coverage``. If you have ``tox`` installed::

$ tox -e cover
You can test coverage via ``tox -e cover``.

Documentation Coverage and Building HTML Documentation
------------------------------------------------------
Expand Down
8 changes: 7 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,38 @@ environment:
- PYTHON: "C:\\Python27"
PYTHON_VERSION: "2.7.11"
PYTHON_ARCH: "32"
TOX_ENV: "py27"

- PYTHON: "C:\\Python27-x64"
PYTHON_VERSION: "2.7.11"
PYTHON_ARCH: "64"
TOX_ENV: "py27"

# Python 3.4.4 is the latest Python 3.4 with a Windows installer
# Python 3.4.4 is the overall latest
# https://www.python.org/ftp/python/3.4.4/
- PYTHON: "C:\\Python34"
PYTHON_VERSION: "3.4.4"
PYTHON_ARCH: "32"
TOX_ENV: "py34"

- PYTHON: "C:\\Python34-x64"
PYTHON_VERSION: "3.4.4"
PYTHON_ARCH: "64"
TOX_ENV: "py34"

# Python 3.5.1 is the latest Python 3.5 with a Windows installer
# Python 3.5.1 is the overall latest
# https://www.python.org/ftp/python/3.5.1/
- PYTHON: "C:\\Python35"
PYTHON_VERSION: "3.5.1"
PYTHON_ARCH: "32"
TOX_ENV: "py35"

- PYTHON: "C:\\Python35-x64"
PYTHON_VERSION: "3.5.1"
PYTHON_ARCH: "64"
TOX_ENV: "py35"

install:
- ECHO "Filesystem root:"
Expand Down Expand Up @@ -83,7 +89,7 @@ build_script:
test_script:
- "%CMD_IN_ENV% pip list"
# Run the project tests
- "%CMD_IN_ENV% python setup.py nosetests"
- "%CMD_IN_ENV% tox -e %TOX_ENV%"

after_test:
# If tests are successful, create binary packages for the project.
Expand Down
4 changes: 2 additions & 2 deletions appveyor/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# pip will build them from source using the MSVC compiler matching the
# target Python version and architecture
wheel
nose
nose-exclude
pytest
tox
cryptography
grpcio >= 1.0rc1
grpc-google-pubsub-v1
Expand Down
61 changes: 47 additions & 14 deletions gcloud/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@
(?P<nanos>\d{1,9}) # nanoseconds, maybe truncated
Z # Zulu
""", re.VERBOSE)
DEFAULT_CONFIGURATION_PATH = '~/.config/gcloud/configurations/config_default'
# NOTE: Catching this ImportError is a workaround for GAE not supporting the
# "pwd" module which is imported lazily when "expanduser" is called.
try:
_USER_ROOT = os.path.expanduser('~')
except ImportError: # pragma: NO COVER
_USER_ROOT = None
_GCLOUD_CONFIG_FILE = os.path.join(
'gcloud', 'configurations', 'config_default')
_GCLOUD_CONFIG_SECTION = 'core'
_GCLOUD_CONFIG_KEY = 'project'


class _LocalStack(Local):
Expand Down Expand Up @@ -171,10 +180,10 @@ def _app_engine_id():


def _file_project_id():
"""Gets the project id from the credentials file if one is available.
"""Gets the project ID from the credentials file if one is available.

:rtype: str or ``NoneType``
:returns: Project-ID from JSON credentials file if value exists,
:returns: Project ID from JSON credentials file if value exists,
else ``None``.
"""
credentials_file_path = os.getenv(CREDENTIALS)
Expand All @@ -185,9 +194,37 @@ def _file_project_id():
return credentials.get('project_id')


def _get_nix_config_path():
"""Get the ``gcloud`` CLI config path on *nix systems.

:rtype: str
:returns: The filename on a *nix system containing the CLI
config file.
"""
return os.path.join(_USER_ROOT, '.config', _GCLOUD_CONFIG_FILE)


def _get_windows_config_path():
"""Get the ``gcloud`` CLI config path on Windows systems.

:rtype: str
:returns: The filename on a Windows system containing the CLI
config file.
"""
appdata_dir = os.getenv('APPDATA', '')
return os.path.join(appdata_dir, _GCLOUD_CONFIG_FILE)


def _default_service_project_id():
"""Retrieves the project ID from the gcloud command line tool.

This assumes the ``.config`` directory is stored
- in ~/.config on *nix systems
- in the %APPDATA% directory on Windows systems

Additionally, the ${HOME} / "~" directory may not be present on Google
App Engine, so this may be conditionally ignored.

Files that cannot be opened with configparser are silently ignored; this is
designed so that you can specify a list of potential configuration file
locations.
Expand All @@ -196,21 +233,17 @@ def _default_service_project_id():
:returns: Project-ID from default configuration file else ``None``
"""
search_paths = []
# Workaround for GAE not supporting pwd which is used by expanduser.
try:
search_paths.append(os.path.expanduser(DEFAULT_CONFIGURATION_PATH))
except ImportError:
pass
if _USER_ROOT is not None:
search_paths.append(_get_nix_config_path())

if os.name == 'nt':
search_paths.append(_get_windows_config_path())

windows_config_path = os.path.join(os.getenv('APPDATA', ''),
'gcloud', 'configurations',
'config_default')
search_paths.append(windows_config_path)
config = configparser.RawConfigParser()
config.read(search_paths)

if config.has_section('core'):
return config.get('core', 'project')
if config.has_section(_GCLOUD_CONFIG_SECTION):
return config.get(_GCLOUD_CONFIG_SECTION, _GCLOUD_CONFIG_KEY)


def _compute_engine_id():
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

23 changes: 10 additions & 13 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ envlist =

[testing]
deps =
nose
nose-exclude
pytest
covercmd =
nosetests \
--exclude-dir=system_tests \
--with-coverage \
--cover-package=gcloud \
--cover-package=unit_tests \
--cover-erase \
--cover-tests \
--cover-branches \
--nocapture
py.test \
--cov=gcloud \
--cov=unit_tests \
--cov-config {toxinidir}/.coveragerc \
unit_tests

[grpc]
deps =
Expand All @@ -28,7 +23,7 @@ deps =

[testenv]
commands =
nosetests
py.test {posargs} unit_tests
deps =
{[testing]deps}
{[grpc]deps}
Expand All @@ -44,16 +39,18 @@ deps =
basepython =
python2.7
commands =
{[testing]covercmd} --cover-min-percentage=100
{[testing]covercmd}
deps =
{[testenv]deps}
coverage
pytest-cov

[testenv:coveralls]
basepython = {[testenv:cover]basepython}
commands =
{[testing]covercmd}
coveralls
ignore_errors = True
deps =
{[testenv:cover]deps}
coveralls
Expand Down
Loading