diff --git a/Makefile b/Makefile index a43e06584..a85fd1880 100644 --- a/Makefile +++ b/Makefile @@ -198,7 +198,7 @@ pep8: .depends-ci .PHONY: pep257 pep257: .depends-ci - $(PEP257) $(PACKAGE) --ignore=E501,D102 + $(PEP257) $(PACKAGE) --ignore=D102 .PHONY: pylint pylint: .depends-dev diff --git a/doorstop/core/document.py b/doorstop/core/document.py index 17913e8b6..51d03d558 100644 --- a/doorstop/core/document.py +++ b/doorstop/core/document.py @@ -22,6 +22,7 @@ class Document(BaseValidatable, BaseFileObject): # pylint: disable=R0902 CONFIG = '.doorstop.yml' SKIP = '.doorstop.skip' # indicates this document should be skipped + ASSETS = 'assets' INDEX = 'index.yml' DEFAULT_PREFIX = Prefix('REQ') @@ -209,6 +210,13 @@ def config(self): """Get the path to the document's file.""" return os.path.join(self.path, Document.CONFIG) + @property + def assets(self): + """Get the path to the document's assets if they exist else `None`.""" + path = os.path.join(self.path, Document.ASSETS) + if os.path.isdir(path): + return path + @property @auto_load def prefix(self): @@ -306,7 +314,7 @@ def skip(self): def index(self): """Get the path to the document's index if it exists else `None`.""" path = os.path.join(self.path, Document.INDEX) - if os.path.exists(path): + if os.path.isfile(path): return path @index.setter diff --git a/doorstop/core/publisher.py b/doorstop/core/publisher.py index cf9956df8..b92cb8cef 100644 --- a/doorstop/core/publisher.py +++ b/doorstop/core/publisher.py @@ -53,6 +53,8 @@ def publish(obj, path, ext=None, linkify=None, index=None, **kwargs): log.info("publishing to {}...".format(path2)) lines = publish_lines(obj2, ext, linkify=linkify, **kwargs) common.write_lines(lines, path2) + if obj2.assets: + common.copy(obj2.assets, os.path.join(path2, obj2.ASSETS)) # Create index if index and count: diff --git a/doorstop/core/test/__init__.py b/doorstop/core/test/__init__.py index 27fd979d3..b3d59173a 100644 --- a/doorstop/core/test/__init__.py +++ b/doorstop/core/test/__init__.py @@ -110,6 +110,7 @@ class MockDataMixIn: # pylint: disable=W0232,R0903 mock_document = MagicMock() mock_document.prefix = 'MOCK' mock_document.items = [] + mock_document.assets = None mock_tree = MagicMock() mock_tree.documents = [mock_document] @@ -151,6 +152,7 @@ class MockDataMixIn: # pylint: disable=W0232,R0903 _file="links: [sys1]\ntext: 'Heading 2'\nlevel: 2.1.0\n" "normative: false"), ] + document.assets = None item3 = MockItem('path/to/req4.yml', _file=( "links: [sys4]" + '\n' diff --git a/doorstop/core/test/test_document.py b/doorstop/core/test/test_document.py index c9c1b176f..abe535c49 100644 --- a/doorstop/core/test/test_document.py +++ b/doorstop/core/test/test_document.py @@ -224,7 +224,7 @@ def test_next_number_server(self): def test_index_get(self): """Verify a document's index can be retrieved.""" self.assertIs(None, self.document.index) - with patch('os.path.exists', Mock(return_value=True)): + with patch('os.path.isfile', Mock(return_value=True)): path = os.path.join(self.document.path, self.document.INDEX) self.assertEqual(path, self.document.index)