-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Enable pre-release builds from dev branch
* Add function to get a pre-release version number, only for Travis jobs on the dev branch * Add separate deploy target for dev branch only * Add separate 'build' setuptools extra for build-specific packages * Remove `twine` from dependencies since Travis uses this already * Add `semantic-version` package, only used for Travis pre-release builds * Note: Also added this to dev dependencies, but only because there are unit tests for the Travis CI pre-release version numbers * Move `mypy.ini` config into `setup.cfg` * Add badges for package format and supported python version * Update pypi version badge to match the format/resolution of the others
- Loading branch information
Showing
9 changed files
with
108 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,38 @@ | ||
import logging | ||
from logging import getLogger | ||
from os import getenv | ||
|
||
__author__ = "Nicolas Noé" | ||
__email__ = "nicolas@niconoe.eu" | ||
__version__ = "0.9.1" | ||
__version__ = "0.10.0" | ||
|
||
# These are imported here so they can be set with pyinaturalist.<variable> | ||
from pyinaturalist.constants import DRY_RUN_ENABLED, DRY_RUN_WRITE_ONLY | ||
|
||
DEFAULT_USER_AGENT = "Pyinaturalist/{version}".format(version=__version__) | ||
user_agent = DEFAULT_USER_AGENT | ||
|
||
# These are imported here so they can be set with pyinaturalist.<variable> | ||
from pyinaturalist.constants import DRY_RUN_ENABLED, DRY_RUN_WRITE_ONLY | ||
|
||
# Enable logging for urllib and other external loggers | ||
logging.basicConfig(level="DEBUG") | ||
def get_prerelease_version(version: str) -> str: | ||
""" If we're running in a Travis CI job on the dev branch, get a prerelease version using the | ||
current build number. For example: ``1.0.0 -> 1.0.0-dev+123`` | ||
This could also be done in ``.travis.yml``, but it's a bit cleaner to do in python, and | ||
``semantic_version`` provides some extra sanity checks. | ||
""" | ||
if not (getenv("TRAVIS") == "true" and getenv("TRAVIS_BRANCH") == "dev"): | ||
return version | ||
# If we happen to be in a dev build, this will prevent the initial 'pip install' from failing | ||
try: | ||
from semantic_version import Version | ||
except ImportError: | ||
return version | ||
|
||
new_version = Version(version) | ||
new_version.prerelease = ["dev"] | ||
new_version.build = [getenv("TRAVIS_BUILD_NUMBER", "0")] | ||
getLogger(__name__).info("Using pre-release version: {}".format(new_version)) | ||
return str(new_version) | ||
|
||
|
||
# This won't modify the version outside of Travis | ||
__version__ = get_prerelease_version(__version__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# A couple tests to make sure that versioning works as expected within Travis | ||
# So, for example, the build would fail before accidentally publishing a bad version | ||
from sys import version_info | ||
from unittest.mock import patch | ||
import pytest | ||
|
||
|
||
# Mocking out getenv() instead of actually setting envars so this doesn't affect other tests | ||
@patch("pyinaturalist.getenv", side_effect=["true", "master", "123"]) | ||
def test_version__stable_release(mock_getenv): | ||
import pyinaturalist | ||
|
||
assert "dev" not in pyinaturalist.__version__ | ||
|
||
|
||
@pytest.mark.skipif(version_info < (3, 6), reason="semantic-version requires python >= 3.6") | ||
@patch("pyinaturalist.getenv", side_effect=["true", "dev", "123"]) | ||
def test_version__pre_release(mock_getenv): | ||
import pyinaturalist | ||
|
||
assert pyinaturalist.get_prerelease_version("1.0.0") == "1.0.0-dev+123" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters