File: move-data-to-usr-share.diff

package info (click to toggle)
python-docutils 0.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 11,448 kB
  • sloc: python: 53,302; lisp: 14,475; xml: 1,807; javascript: 1,032; makefile: 102; sh: 96
file content (247 lines) | stat: -rw-r--r-- 10,288 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
From: Jakub Wilk <jwilk@debian.org>
Date: Thu, 8 Oct 2015 11:57:09 -0700
Subject: Allow all data files to be moved to /usr/share/docutils/.

Forwarded: not-needed
Last-Update: 2023-05-20
---
 docutils/__init__.py                               | 24 ++++++++++++++++++++++
 docutils/parsers/rst/directives/misc.py            |  3 ++-
 docutils/writers/html4css1/__init__.py             | 11 +++++-----
 docutils/writers/html5_polyglot/__init__.py        |  6 ++++--
 docutils/writers/latex2e/__init__.py               |  9 ++++++--
 docutils/writers/odf_odt/__init__.py               |  4 ++--
 docutils/writers/pep_html/__init__.py              |  5 +++--
 docutils/writers/s5_html/__init__.py               |  2 +-
 .../test_rst/test_directives/test_include.py       |  3 ++-
 9 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/docutils/__init__.py b/docutils/__init__.py
index cdd29e7..30f78f8 100644
--- a/docutils/__init__.py
+++ b/docutils/__init__.py
@@ -339,3 +339,27 @@ class Component(SettingsSpec, TransformSpec):
         a certain input context or output format.
         """
         return format in self.supported
+
+import os
+
+_debian_package = 0
+
+if _debian_package:
+    def _datadir(path, buildloc=None):
+        dirname = os.path.dirname(path)
+        prefix = os.path.join(os.path.dirname(__file__), '') # _datadir
+        assert path.startswith(prefix), "%r doesn't start with %r" % (path, prefix)
+        suffix = dirname[len(prefix):]
+        datadir = os.path.join('/usr/share/docutils/', suffix)
+
+        # If we are in the process of building the Debian python-docutils
+        # package, we must look for latex files in the debian/tmp directory
+        # rather than in /usr, as they don't yet exist there.
+        if _debian_package == 'build' and buildloc == 'local':
+            datadir = 'debian/tmp' + datadir
+
+        return datadir
+
+else:
+    def _datadir(path, buildloc=None):
+        return os.path.dirname(path)
diff --git a/docutils/parsers/rst/directives/misc.py b/docutils/parsers/rst/directives/misc.py
index 1394f01..2c19d11 100644
--- a/docutils/parsers/rst/directives/misc.py
+++ b/docutils/parsers/rst/directives/misc.py
@@ -14,6 +14,7 @@ from pathlib import Path
 from urllib.request import urlopen
 from urllib.error import URLError
 
+import docutils
 from docutils import frontend, io, nodes, statemachine, utils
 from docutils.parsers.rst import Directive, convert_directive_function
 from docutils.parsers.rst import directives, roles, states
@@ -70,7 +71,7 @@ class Include(Directive):
                    'class': directives.class_option,
                    'name': directives.unchanged}
 
-    standard_include_path = Path(states.__file__).parent / 'include'
+    standard_include_path = Path(docutils._datadir(states.__file__)) / 'include'
 
     def run(self) -> list:
         """Include a file as part of the content of this reST file.
diff --git a/docutils/writers/html4css1/__init__.py b/docutils/writers/html4css1/__init__.py
index 88c781b..89f6246 100644
--- a/docutils/writers/html4css1/__init__.py
+++ b/docutils/writers/html4css1/__init__.py
@@ -19,6 +19,7 @@ __docformat__ = 'reStructuredText'
 import os.path
 import re
 
+import docutils
 from docutils import frontend, nodes, writers
 from docutils.writers import _html_base
 from docutils.writers._html_base import PIL
@@ -31,13 +32,13 @@ class Writer(writers._html_base.Writer):
 
     default_stylesheets = ['html4css1.css']
     default_stylesheet_dirs = ['.',
-                               os.path.abspath(os.path.dirname(__file__)),
-                               os.path.abspath(os.path.join(
-                                   os.path.dirname(os.path.dirname(__file__)),
-                                   'html5_polyglot'))  # for math.css
+                               docutils._datadir(os.path.abspath(__file__)),
+                               os.path.join(
+                                   docutils._datadir(os.path.dirname(os.path.abspath(__file__))),
+                                   'html5_polyglot')  # for math.css
                                ]
     default_template = os.path.join(
-        os.path.dirname(os.path.abspath(__file__)), 'template.txt')
+        docutils._datadir(os.path.abspath(__file__)), 'template.txt')
 
     # use a copy of the parent spec with some modifications
     settings_spec = frontend.filter_settings_spec(
diff --git a/docutils/writers/html5_polyglot/__init__.py b/docutils/writers/html5_polyglot/__init__.py
index 83b9661..6ec06bd 100644
--- a/docutils/writers/html5_polyglot/__init__.py
+++ b/docutils/writers/html5_polyglot/__init__.py
@@ -29,8 +29,10 @@ from __future__ import annotations
 
 __docformat__ = 'reStructuredText'
 
+import os.path
 from pathlib import Path
 
+import docutils
 from docutils import frontend, nodes
 from docutils.writers import _html_base
 
@@ -41,8 +43,8 @@ class Writer(_html_base.Writer):
     """Formats this writer supports."""
 
     default_stylesheets = ['minimal.css', 'plain.css']
-    default_stylesheet_dirs = ['.', str(Path(__file__).parent)]
-    default_template = Path(__file__).parent / 'template.txt'
+    default_stylesheet_dirs = ['.', docutils._datadir(os.path.abspath(__file__))]
+    default_template = Path(docutils._datadir(os.path.abspath(__file__))) / 'template.txt'
 
     # use a copy of the parent spec with some modifications
     settings_spec = frontend.filter_settings_spec(
diff --git a/docutils/writers/latex2e/__init__.py b/docutils/writers/latex2e/__init__.py
index 9a80a5d..fb7afa9 100644
--- a/docutils/writers/latex2e/__init__.py
+++ b/docutils/writers/latex2e/__init__.py
@@ -14,17 +14,19 @@ __docformat__ = 'reStructuredText'
 #
 # convention deactivate code by two # i.e. ##.
 
+import os.path
 import re
 import string
 import warnings
 from pathlib import Path
 
+import docutils
 from docutils import frontend, nodes, languages, writers, utils
 from docutils.transforms import references, writer_aux
 from docutils.utils._roman_numerals import RomanNumeral
 from docutils.utils.math import pick_math_environment, unichar2tex
 
-LATEX_WRITER_DIR = Path(__file__).parent
+LATEX_WRITER_DIR = Path(docutils._datadir(os.path.abspath(__file__)))
 
 
 class Writer(writers.Writer):
@@ -614,7 +616,10 @@ def _read_block(fp):
     return ''.join(block).rstrip()
 
 
-with open(LATEX_WRITER_DIR/'docutils.sty', encoding='utf-8') as fp:
+_docutils_sty = os.path.join(docutils._datadir(os.path.abspath(__file__),
+                                               "local"),
+                             'docutils.sty')
+with open(_docutils_sty, encoding='utf-8') as fp:
     for line in fp:
         line = line.strip('% \n')
         if not line.endswith('::'):
diff --git a/docutils/writers/odf_odt/__init__.py b/docutils/writers/odf_odt/__init__.py
index 4262688..33322ac 100644
--- a/docutils/writers/odf_odt/__init__.py
+++ b/docutils/writers/odf_odt/__init__.py
@@ -371,13 +371,13 @@ class Writer(writers.Writer):
 
     default_stylesheet_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_stylesheet))
+        os.path.join(docutils._datadir(__file__), default_stylesheet))
 
     default_template = 'template.txt'
 
     default_template_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_template))
+        os.path.join(docutils._datadir(__file__), default_template))
 
     settings_spec = (
         'ODF-Specific Options.',
diff --git a/docutils/writers/pep_html/__init__.py b/docutils/writers/pep_html/__init__.py
index ea07117..9aea403 100644
--- a/docutils/writers/pep_html/__init__.py
+++ b/docutils/writers/pep_html/__init__.py
@@ -13,6 +13,7 @@ __docformat__ = 'reStructuredText'
 import os
 import os.path
 
+import docutils
 from docutils import frontend, nodes, utils
 from docutils.writers import html4css1
 
@@ -23,13 +24,13 @@ class Writer(html4css1.Writer):
 
     default_stylesheet_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_stylesheet))
+        os.path.join(docutils._datadir(__file__), default_stylesheet))
 
     default_template = 'template.txt'
 
     default_template_path = utils.relative_path(
         os.path.join(os.getcwd(), 'dummy'),
-        os.path.join(os.path.dirname(__file__), default_template))
+        os.path.join(docutils._datadir(__file__), default_template))
 
     settings_spec = html4css1.Writer.settings_spec + (
         'PEP/HTML Writer Options',
diff --git a/docutils/writers/s5_html/__init__.py b/docutils/writers/s5_html/__init__.py
index 2eeff17..49baed9 100644
--- a/docutils/writers/s5_html/__init__.py
+++ b/docutils/writers/s5_html/__init__.py
@@ -21,7 +21,7 @@ from docutils.writers import html4css1
 
 themes_dir_path = utils.relative_path(
     os.path.join(os.getcwd(), 'dummy'),
-    os.path.join(os.path.dirname(__file__), 'themes'))
+    os.path.join(docutils._datadir(__file__), 'themes'))
 
 
 def find_theme(name):
diff --git a/test/test_parsers/test_rst/test_directives/test_include.py b/test/test_parsers/test_rst/test_directives/test_include.py
index bea6973..dfb1a42 100755
--- a/test/test_parsers/test_rst/test_directives/test_include.py
+++ b/test/test_parsers/test_rst/test_directives/test_include.py
@@ -17,6 +17,7 @@ if __name__ == '__main__':
     # so we import the local `docutils` package.
     sys.path.insert(0, str(Path(__file__).resolve().parents[4]))
 
+import docutils
 from docutils import core, parsers, utils
 from docutils.frontend import get_default_settings
 from docutils.parsers.rst import Parser
@@ -111,7 +112,7 @@ latin2 = TEST_ROOT/'data/latin2.rst'
 utf_16_file = TEST_ROOT/'data/utf-16-le-sig.rst'
 utf_16_error_str = ("UnicodeDecodeError: 'ascii' codec can't decode byte 0xff "
                     "in position 0: ordinal not in range(128)")
-rst_states_dir = os.path.dirname(parsers.rst.states.__file__)
+rst_states_dir = docutils._datadir(parsers.rst.states.__file__)
 # TODO fix case normalisation bug on Windows in utils.relative_path()
 # nonexistent = os.path.relpath(
 #     os.path.join(rst_states_dir, 'include', 'nonexistent'),