Skip to content

Commit

Permalink
reuerments updated for compas 2 compatibily
Browse files Browse the repository at this point in the history
  • Loading branch information
fleischp committed Mar 15, 2024
1 parent 162dcef commit 4e2be4b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 235 deletions.
6 changes: 4 additions & 2 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
autopep8
black
bump2version>=1.0
check-manifest>=0.36
compas_invocations
doc8
flake8
invoke>=0.14
isort
pylint
pytest
sphinx_compas_theme>=0.9
sphinx>=1.6
sphinx_compas2_theme
twine
-e .
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compas_fab >= 1, < 2
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def read(*names, **kwargs):
about = {}
exec(read('src', 'compas_rrc', '__version__.py'), about)


requirements = read("requirements.txt").split("\n")


setup(
name=about['__title__'],
version=about['__version__'],
Expand Down
6 changes: 3 additions & 3 deletions src/compas_rrc/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import math
import threading

from compas.robots import Configuration
from compas.robots import Joint
from compas_robots import Configuration
from compas_robots.model import Joint

__all__ = ['CLIENT_PROTOCOL_VERSION',
'FeedbackLevel',
Expand Down Expand Up @@ -196,7 +196,7 @@ def __iter__(self):

# Conversion methods
def to_configuration_primitive(self, joint_types, joint_names=None):
"""Convert the ExternalAxes to a :class:`compas.robots.Configuration`, including the unit conversion
"""Convert the ExternalAxes to a :class:`compas_robots.Configuration`, including the unit conversion
from mm and degrees to meters and radians.
Parameters
Expand Down
261 changes: 31 additions & 230 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -1,234 +1,35 @@
# -*- coding: utf-8 -*-
from __future__ import print_function

import contextlib
import glob
import os
import sys
from shutil import copytree
from shutil import rmtree

from invoke import Exit
from invoke import task

BASE_FOLDER = os.path.dirname(__file__)


class Log(object):
def __init__(self, out=sys.stdout, err=sys.stderr):
self.out = out
self.err = err

def flush(self):
self.out.flush()
self.err.flush()

def write(self, message):
self.flush()
self.out.write(message + '\n')
self.out.flush()

def info(self, message):
self.write('[INFO] %s' % message)

def warn(self, message):
self.write('[WARN] %s' % message)


log = Log()


def confirm(question):
while True:
response = input(question).lower().strip()

if not response or response in ('n', 'no'):
return False

if response in ('y', 'yes'):
return True

print('Focus, kid! It is either (y)es or (n)o', file=sys.stderr)


@task(default=True)
def help(ctx):
"""Lists available tasks and usage."""
ctx.run('invoke --list')
log.write('Use "invoke -h <taskname>" to get detailed help for a task.')


@task(help={
'docs': 'True to generate documentation, otherwise False',
'bytecode': 'True to clean up compiled python files, otherwise False.',
'builds': 'True to clean up build/packaging artifacts, otherwise False.'})
def clean(ctx, docs=True, bytecode=True, builds=True):
"""Cleans the local copy from compiled artifacts."""
if builds:
ctx.run('python setup.py clean')

if bytecode:
for root, dirs, files in os.walk(BASE_FOLDER):
for f in files:
if f.endswith('.pyc'):
os.remove(os.path.join(root, f))
if '.git' in dirs:
dirs.remove('.git')

folders = []

if docs:
folders.append('docs/_build/')
folders.append('docs/reference/generated')
folders.append('dist/')

if bytecode:
folders.append('src/compas_rrc/__pycache__')
folders.append('.pytest_cache')

if builds:
folders.append('build/')
folders.append('src/compas_rrc.egg-info/')

for folder in folders:
rmtree(os.path.join(BASE_FOLDER, folder), ignore_errors=True)


@task(help={
'rebuild': 'True to clean all previously built docs before starting, otherwise False.',
'doctest': 'True to run doctests, otherwise False.',
'check_links': 'True to check all web links in docs for validity, otherwise False.'})
def docs(ctx, doctest=False, rebuild=False, check_links=False):
"""Builds package's HTML documentation."""

if rebuild:
clean(ctx)

with chdir(BASE_FOLDER):
if doctest:
testdocs(ctx, rebuild=rebuild)

ctx.run('sphinx-build -b html docs dist/docs')

if check_links:
linkcheck(ctx, rebuild=rebuild)


@task()
def lint(ctx):
"""Check the consistency of coding style."""
log.write('Running flake8 python linter...')

with chdir(BASE_FOLDER):
ctx.run('flake8 src')


@task()
def testdocs(ctx, rebuild=False):
"""Test the examples in the docstrings."""
log.write('Running doctest...')
opts = '-E' if rebuild else ''
ctx.run('sphinx-build {} -b doctest docs dist/docs'.format(opts))


@task()
def linkcheck(ctx, rebuild=False):
"""Check links in documentation."""
log.write('Running link check...')
opts = '-E' if rebuild else ''
ctx.run('sphinx-build {} -b linkcheck docs dist/docs'.format(opts))


@task()
def check(ctx):
"""Check the consistency of documentation, coding style and a few other things."""

with chdir(BASE_FOLDER):
lint(ctx)

log.write('Checking ReStructuredText formatting...')
ctx.run('python setup.py check --strict --metadata --restructuredtext')

log.write('Checking python imports...')
ctx.run('isort --check-only --diff src tests setup.py')

log.write('Checking MANIFEST.in...')
ctx.run('check-manifest')


@task(help={
'checks': 'True to run all checks before testing, otherwise False.',
'doctests': 'True to run doctests, otherwise False.'})
def test(ctx, checks=False, doctests=False):
"""Run all tests."""
if checks:
check(ctx)

with chdir(BASE_FOLDER):
if doctests:
ctx.run('pytest --doctest-modules')
else:
ctx.run('pytest')


@task
def prepare_changelog(ctx):
"""Prepare changelog for next release."""
UNRELEASED_CHANGELOG_TEMPLATE = '\nUnreleased\n----------\n\n**Added**\n\n**Changed**\n\n**Fixed**\n\n**Deprecated**\n\n**Removed**\n'

with chdir(BASE_FOLDER):
# Preparing changelog for next release
with open('CHANGELOG.rst', 'r+') as changelog:
content = changelog.read()
start_index = content.index('----------')
start_index = content.rindex('\n', 0, start_index - 1)
last_version = content[start_index:start_index + 11].strip()

if last_version == 'Unreleased':
log.write('Already up-to-date')
return

changelog.seek(0)
changelog.write(content[0:start_index] + UNRELEASED_CHANGELOG_TEMPLATE + content[start_index:])

ctx.run('git add CHANGELOG.rst && git commit -m "Prepare changelog for next release"')


@task(help={
'release_type': 'Type of release follows semver rules. Must be one of: major, minor, patch.'})
def release(ctx, release_type):
"""Releases the project in one swift command!"""
if release_type not in ('patch', 'minor', 'major'):
raise Exit('The release type parameter is invalid.\nMust be one of: major, minor, patch')

# Run checks
ctx.run('invoke check test')

# Bump version and git tag it
ctx.run('bump2version %s --verbose' % release_type)

# Build project
ctx.run('python setup.py clean --all sdist bdist_wheel')

# Prepare changelog for next release
prepare_changelog(ctx)

# Clean up local artifacts
clean(ctx)

# Upload to pypi
if confirm('Everything is ready. You are about to push to git which will trigger a release to pypi.org. Are you sure? [y/N]'):
ctx.run('git push --tags && git push')
else:
raise Exit('You need to manually revert the tag/commits created.')


@contextlib.contextmanager
def chdir(dirname=None):
current_dir = os.getcwd()
try:
if dirname is not None:
os.chdir(dirname)
yield
finally:
os.chdir(current_dir)
from compas_invocations import build
from compas_invocations import docs
from compas_invocations import style
from compas_invocations import tests
from invoke import Collection

ns = Collection(
docs.help,
style.check,
style.lint,
style.format,
docs.docs,
docs.linkcheck,
tests.test,
tests.testdocs,
tests.testcodeblocks,
build.prepare_changelog,
build.clean,
build.release,
build.build_ghuser_components,
)
ns.configure(
{
"base_folder": os.path.dirname(__file__),
"ghuser": {
"source_dir": "src/compas_rrc/ghpython/components",
"target_dir": "src/compas_rrc/ghpython/components/ghuser",
"prefix": "COMPAS RRC: ",
},
}
)

0 comments on commit 4e2be4b

Please sign in to comment.