Skip to content

Commit

Permalink
Merge branch 'release/3.1.0' into new-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hudgston committed Oct 2, 2019
2 parents 43733e1 + b743c10 commit f39e227
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 64 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:warning: cirrus has been ported to Python 3 and newer versions (>=3.0.0) are not backwards compatible. The last Python 2 release was 2.0.2. :warning:

cirrus
======

Expand All @@ -18,7 +20,7 @@ Our solution was to check out the most recently working version, `0.1.7` and cre
Installation Prerequisites
==========================

* Cirrus requires python 2.7 (support for python 3 is in the pipeline) as well as pip and virtualenv installed.
* Cirrus requires python 3.5.
* Git tools are heavily used, git is a requirement as cirrus is accessed via git command aliases.

Installation as a user:
Expand All @@ -31,7 +33,7 @@ bash installer.sh

The installer script will set up an install of cirrus for you in your home directory
and prompt for some info so that it can set up some parameters in your .gitconfig
The installer will create a virtualenv and install cirrus from pip via the cirrus-cli package, installing the latest available version.
The installer will create a virtualenv and install cirrus from pip via the cirrus-cli package, installing the latest available version. If a specific version is required, it may be set via environment variable. For example, if you require version 3.0.0 you can use `export CIRRUS_INSTALL_VERSION='==3.0.0'`



Expand All @@ -42,7 +44,7 @@ _Note_: This package uses GitFlow, any development work should be done off the d
pull requests made against develop, not master.

```bash
git clone https://github.com/evansde77/cirrus.git
git clone https://github.com/cloudant/cirrus.git
cd cirrus
git cirrus build
```
Expand Down Expand Up @@ -197,9 +199,8 @@ Commands related to creation of a new git-flow style release branch, building th
There are three subcommands:

1. new - creates a new release branch, increments the package version, builds the release notes if configured.
2. build - Runs sdist to create a new build artifact from the release branch
2. build\_and\_upload - builds a release artifact and uploads it to artifactory. A `--dev` option is provided to create test releases which can be used for testing (via sapitest002 for example).
3. merge - Runs git-flow style branch merges back to master and develop, optionally waiting on CI or setting flags for GH build contexts if needed
4. upload - Pushes the build artifact to the pypi server configured in the cirrus conf, using a plugin system to allow for customisation.

Usage:
```bash
Expand Down
2 changes: 1 addition & 1 deletion cirrus.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = cirrus-cli
version = 3.0.0
version = 3.1.0
description = cirrus development and build git extensions
organization = cloudant
version_file = src/cirrus/__init__.py
Expand Down
2 changes: 1 addition & 1 deletion installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ echo "Installing cirrus to LOCATION=${LOCATION}" > ${LOCATION}/install.log
cd ${LOCATION}

# bootstrap virtualenv
virtualenv venv
python -m venv venv
. venv/bin/activate

# This depends on a properly configured pip.conf file.
Expand Down
2 changes: 1 addition & 1 deletion src/cirrus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
See the License for the specific language governing permissions and
limitations under the License.
"""
__version__="3.0.0"
__version__="3.1.0"

81 changes: 79 additions & 2 deletions src/cirrus/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def build_parser(argslist):
default=False,
action='store_true'
)
parser.add_argument(
'--freeze',
action='store_true',
help='ignores sub-dependency pins, and then updates them'
)
opts = parser.parse_args(argslist)
return opts

Expand All @@ -99,6 +104,14 @@ def execute_build(opts):

# we have custom build controls in the cirrus.conf
reqs_name = build_params.get('requirements_file', 'requirements.txt')
activate_cmd = '. ./{}/bin/activate'.format(config.venv_name())
if opts.freeze:
requirements = Requirements(
reqs_name,
'requirements-sub.txt',
activate_cmd
)
requirements.parse_out_sub_dependencies()
extra_reqs = build_params.get('extra_requirements', '')
extra_reqs = [x.strip() for x in extra_reqs.split(',') if x.strip()]
if opts.extras:
Expand Down Expand Up @@ -214,11 +227,15 @@ def execute_build(opts):
else:
LOGGER.info('running python setup.py develop...')
run(
'. ./{0}/bin/activate && python setup.py develop'.format(
config.venv_name()
'{} && python setup.py develop'.format(
activate_cmd
)
)

if opts.freeze:
requirements.update_sub_dependencies()
requirements.restore_sub_dependencies()


def main():
"""
Expand All @@ -233,5 +250,65 @@ def main():
build_docs(make_opts=opts.docs)


class Requirements:
"""
Modify requirments files
"""
def __init__(self, dep_filename, sub_dep_filename, activate_cmd):
"""
:param str dep_filename: name of the requirements file containing
direct dependencies
:param str sub_dep_filename: name of the requirements file containing
sub-dependencies
:param str activate_cmd: shell command used to activate a virtualenv
"""
self.direct_filename = dep_filename
self.sub_filename = sub_dep_filename
self.direct_dependencies = None
self.sub_dependencies = None
self.activate_cmd = activate_cmd

def parse_out_sub_dependencies(self):
"""
Modifies the direct requirements file to exclude sub-dependencies,
noop if no sub-dependencies specified
"""
with open(self.direct_filename, 'r') as requirements_file:
direct = requirements_file.read().strip().split('\n')
del direct[0]
with open(self.direct_filename, 'w+') as new_req_file:
direct = sorted(direct)
new_req_file.write('\n'.join(direct))

self.direct_dependencies = set(direct)

def update_sub_dependencies(self):
"""
Re-pins sub-dependencies after getting the latest acceptable versions
"""
run('{} && pip freeze > {}'.format(
self.activate_cmd, self.sub_filename
))
with open(self.sub_filename, 'r') as sub_req_file:
sub = sub_req_file.read().strip().split('\n')
sub = [item for item in sub if not item.startswith('-e')]
self.sub_dependencies = set(sub)
new_sub_req = self.sub_dependencies - self.direct_dependencies
with open(self.sub_filename, 'w+') as sub_req_file:
new_sub_req = sorted(list(new_sub_req))
sub_req_file.write('\n'.join(new_sub_req))

def restore_sub_dependencies(self):
"""
Modifies requirments file to include sub-dependencies
"""
with open(self.direct_filename, 'r+') as requirements_file:
contents = requirements_file.read()
requirements_file.seek(0)
requirements_file.write(
'-r {}\n'.format(self.sub_filename) + contents
)


if __name__ == '__main__':
main()
60 changes: 8 additions & 52 deletions src/cirrus/selfupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import argparse
import arrow
import os
import requests
import inspect
import contextlib

Expand All @@ -26,7 +25,6 @@


LOGGER = get_logger()
PYPI_JSON_URL = "https://pypi.python.org/pypi/cirrus-cli/json"


@contextlib.contextmanager
Expand Down Expand Up @@ -58,7 +56,7 @@ def build_parser(argslist):
'--version',
help='specify a tag to install',
required=False,
default=None,
default='',

)
parser.add_argument(
Expand All @@ -80,40 +78,6 @@ def build_parser(argslist):
return opts


def sort_by_date(d1, d2):
"""
cmp function to sort by datetime string
that is second element of tuples in list
"""
date1 = arrow.get(d1[1])
date2 = arrow.get(d2[1])
return date1 > date2


def latest_release(config):
"""
_latest_release_
pull list of releases from GH repo, pick the newest by
publication date.
"""
releases = get_releases(config.organisation_name(), config.package_name())
tags = [(release['tag_name'], release['published_at']) for release in releases]
sorted(tags, cmp=sort_by_date)
most_recent_tag = tags[0][0]
return most_recent_tag


def latest_pypi_release():
"""grab latest release from pypi"""
resp = requests.get(PYPI_JSON_URL)
resp.raise_for_status()
content = resp.json()
latest = content['info']['version']
return latest


def find_cirrus_install():
"""
_find_cirrus_install_
Expand Down Expand Up @@ -153,7 +117,9 @@ def setup_develop(config):

def pip_install(version):
"""pip install the version of cirrus requested"""
pip_req = 'cirrus-cli=={0}'.format(version)
if version:
version = '=={}'.format(version)
pip_req = 'cirrus-cli{}'.format(version)
venv_name = os.path.basename(virtualenv_home())
LOGGER.info("running pip upgrade...")
run(
Expand Down Expand Up @@ -191,24 +157,14 @@ def pip_update(opts):
"""update pip installed cirrus"""
install = cirrus_home()
with chdir(install):
if opts.version is not None:
tag = opts.version
LOGGER.info("tag specified: {0}".format(tag))
else:
# should probably be a pip call now...
tag = latest_pypi_release()
LOGGER.info("Retrieved latest tag: {0}".format(tag))
pip_install(tag)
pip_install(opts.version)


def main():
"""
_main_
parse command line opts and deduce wether to check out
a branch or tag, default behaviour is to look up latest
release on github and install that
Parses command line opts and deduce wether to check out
a branch or tag, default behaviour is to install latest release found by
pip
"""
opts = build_parser(sys.argv)
if opts.legacy_repo:
Expand Down
Loading

0 comments on commit f39e227

Please sign in to comment.