Skip to content

Commit

Permalink
Update build systems
Browse files Browse the repository at this point in the history
- Add Makefile with targets for common development commands.
- Use/enforce isort. Repair sort order in various code files.
- Update .travis.yml to use latest linux dist
- Just use requirements.txt for development requirements. setup.py captures
  installation requirements.
  • Loading branch information
jpgrayson committed Mar 25, 2020
1 parent 66a0e40 commit a0b2b44
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 79 deletions.
51 changes: 28 additions & 23 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
dist: xenial
language: python
os: linux
dist: bionic
cache: pip

matrix:
python:
- '3.8'
- '3.7'
- '3.6'
- '2.7'
- 'pypy3'
- 'nightly'

env:
- MAKE_TARGET=test

jobs:
include:
- python: '2.7'
env:
- COVERAGE=--cov
- FLAKE8=--flake8
- python: 'pypy2.7-6.0'
- python: '3.4'
- python: '3.5'
- python: '3.6'
- python: '3.7'
env:
- COVERAGE=--cov
- FLAKE8=--flake8
- python: 'pypy3.5-6.0'
- python: '3.8-dev'
- python: 'nightly'
- python: '3.8'
env: MAKE_TARGET=lint
- python: '3.8'
env: MAKE_TARGET=coverage
allow_failures:
- python: '3.8-dev'
- python: 'nightly'

install:
- pip install -r requirements-dev.txt
- if [ -n "$COVERAGE" ]; then pip install coveralls; fi
- pip install -e .
- |
if [ "$MAKE_TARGET" = "coverage" ]; then
pip install coveralls
fi
- pip install --upgrade -r requirements.txt -e .

script:
- py.test $FLAKE8 $COVERAGE
- make "$MAKE_TARGET"

after_success:
- if [ -n "$COVERAGE" ]; then coveralls; fi
- |
if [ "$MAKE_TARGET" = "coverage" ]; then
coveralls
fi
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
PYTHON ?= python

.PHONY: lint
lint: lint-isort lint-flake8

.PHONY: lint-isort
lint-isort:
isort --check-only --quiet --diff --recursive .

.PHONY: lint-flake8
lint-flake8:
flake8 .

.PHONY: format
format: format-isort

.PHONY: format-isort
format-isort:
isort --recursive .

.PHONY: test
test:
pytest

.PHONY: coverage
coverage:
pytest --cov

.PHONY: docs
docs:
$(MAKE) -C docs html

.PHONY: build
build:
$(PYTHON) setup.py build

.PHONY: dist
dist:
$(PYTHON) setup.py sdist bdist_wheel
2 changes: 1 addition & 1 deletion desmod/probe.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import simpy
import six

from desmod.queue import Queue
from desmod.pool import Pool
from desmod.queue import Queue


def attach(scope, target, callbacks, **hints):
Expand Down
7 changes: 4 additions & 3 deletions desmod/progress.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import print_function, division
from __future__ import division, print_function

from collections import OrderedDict
from contextlib import contextmanager
from datetime import datetime, timedelta
import sys
import timeit

from desmod.timescale import parse_time, scale_time

try:
import progressbar
except ImportError:
Expand All @@ -14,8 +17,6 @@
except ImportError:
colorama = None

from desmod.timescale import parse_time, scale_time


@contextmanager
def standalone_progress_manager(env):
Expand Down
14 changes: 8 additions & 6 deletions desmod/simulation.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
"""Simulation model with batteries included."""

from __future__ import division

from contextlib import closing
from multiprocessing import cpu_count, Process, Queue
from multiprocessing import Process, Queue, cpu_count
from pprint import pprint
from six.moves import filter
from threading import Thread

import json
import os
import random
import shutil
import timeit

from six.moves import filter
import simpy
import six
import yaml

from desmod.config import factorial_config
from desmod.progress import (standalone_progress_manager,
get_multi_progress_manager,
consume_multi_progress)
from desmod.progress import (
consume_multi_progress,
get_multi_progress_manager,
standalone_progress_manager,
)
from desmod.timescale import parse_time, scale_time
from desmod.tracer import TraceManager

Expand Down
1 change: 1 addition & 0 deletions desmod/timescale.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import division

import re

_unit_map = {'s': 1e0,
Expand Down
9 changes: 5 additions & 4 deletions desmod/tracer.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
from __future__ import print_function

import os
import re
import sqlite3
import sys
import traceback

import simpy
from vcd import VCDWriter
import simpy

from . import probe
from .util import partial_format
from .timescale import parse_time, scale_time
from .queue import Queue
from .pool import Pool
from .queue import Queue
from .timescale import parse_time, scale_time
from .util import partial_format


class Tracer(object):
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/gas_station/gas_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

from itertools import count, cycle

from simpy import Resource

from desmod.component import Component
from desmod.dot import generate_dot
from desmod.pool import Pool
from desmod.queue import Queue
from desmod.simulation import simulate
from simpy import Resource


class Top(Component):
Expand Down
9 changes: 5 additions & 4 deletions docs/examples/grocery/grocery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
"""
from __future__ import division

from argparse import ArgumentParser
from datetime import timedelta
from functools import partial
from itertools import count

from desmod.config import apply_user_overrides, parse_user_factors
from simpy import Container, Resource
from vcd.gtkw import GTKWSave

from desmod.component import Component
from desmod.config import apply_user_overrides, parse_user_factors
from desmod.dot import generate_dot
from desmod.queue import Queue
from desmod.simulation import simulate, simulate_factors

from simpy import Container, Resource
from vcd.gtkw import GTKWSave


class Top(Component):
"""The top-level component of the model."""
Expand Down
11 changes: 0 additions & 11 deletions requirements-dev.txt

This file was deleted.

14 changes: 10 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
pyvcd >= 0.1.1
PyYAML >= 3.11
simpy >= 3.0.8
six >= 1.10.0
colorama
flake8
isort
progressbar2
pytest
pytest-cov
setuptools_scm
Sphinx
sphinx-rtd-theme
tox
12 changes: 9 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
[bdist_wheel]
universal = 1

[tool:pytest]

[wheel]
universal = 1
[flake8]
ignore = D, E121, E123, E126, E226, E24, E704, W503, W504
exclude = build/, .*/

[isort]
force_grid_wrap = 0
from_first = True
include_trailing_comma = True
line_length = 79
multi_line_output = 3
use_parentheses = True
use_parentheses = True
skip_glob = .*
known_third_party = pyvcd, simpy
21 changes: 12 additions & 9 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import sys

import pytest

from desmod.config import (ConfigError,
NamedManager,
apply_user_config,
apply_user_overrides,
fuzzy_lookup,
factorial_config,
parse_user_factor,
parse_user_factors,
_safe_eval)
from desmod.config import (
ConfigError,
NamedManager,
_safe_eval,
apply_user_config,
apply_user_overrides,
factorial_config,
fuzzy_lookup,
parse_user_factor,
parse_user_factors,
)


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os

import pytest

from desmod.dot import component_to_dot, generate_dot
from desmod.component import Component
from desmod.dot import component_to_dot, generate_dot
from desmod.simulation import SimEnvironment


pytestmark = pytest.mark.usefixtures('cleandir')


Expand Down
2 changes: 1 addition & 1 deletion tests/test_probe.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
import simpy

from desmod.pool import Pool, PriorityPool
from desmod.probe import attach
from desmod.queue import Queue
import simpy


@pytest.fixture
Expand Down
12 changes: 8 additions & 4 deletions tests/test_simulation.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import json
import os
import pytest

import pytest
import yaml

from desmod.component import Component
from desmod.simulation import (simulate, simulate_factors, simulate_many,
SimEnvironment, SimStopEvent)
from desmod.simulation import (
SimEnvironment,
SimStopEvent,
simulate,
simulate_factors,
simulate_many,
)
import desmod.progress


pytestmark = pytest.mark.usefixtures('cleandir')


Expand Down
5 changes: 3 additions & 2 deletions tests/test_tracer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import sqlite3

import pytest
import simpy

from desmod.component import Component
from desmod.pool import Pool
from desmod.queue import Queue
from desmod.simulation import simulate
import pytest
import simpy

pytestmark = pytest.mark.usefixtures('cleandir')

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ envlist = py27,py33,py34,py35,py36,pypy,pypy3
skip_missing_interpreters = True

[testenv]
deps = -rrequirements-dev.txt
deps = -rrequirements.txt
commands = py.test --flake8

0 comments on commit a0b2b44

Please sign in to comment.