Remove dead code

Change I5689985fd8ab2a061c04776c5320188343b2f077 removed the only user
of these methods.

Change-Id: Iba0f75ca0e3efaf6a89baa73ab989c7eaecd440f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane
2025-09-18 11:47:36 +01:00
parent 3741dcc257
commit 562d323af4
3 changed files with 0 additions and 323 deletions

View File

@@ -15,43 +15,11 @@
"""The project abstraction."""
import collections
import configparser
import errno
import io
import os
from parsley import makeGrammar
from openstack_requirements import requirement
# PURE logic from here until the IO marker below.
_Comment = collections.namedtuple('Comment', ['line'])
_Extra = collections.namedtuple('Extra', ['name', 'content'])
_extras_grammar = """
ini = (line*:p extras?:e line*:l final:s) -> (''.join(p), e, ''.join(l+[s]))
line = ~extras <(~'\\n' anything)* '\\n'>
final = <(~'\\n' anything)* >
extras = '[' 'e' 'x' 't' 'r' 'a' 's' ']' '\\n'+ body*:b -> b
body = comment | extra
comment = <'#' (~'\\n' anything)* '\\n'>:c '\\n'* -> comment(c)
extra = name:n ' '* '=' line:l cont*:c '\\n'* -> extra(n, ''.join([l] + c))
name = <(anything:x ?(x not in '\\n \\t='))+>
cont = ' '+ <(~'\\n' anything)* '\\n'>
"""
_extras_compiled = makeGrammar(
_extras_grammar, {"comment": _Comment, "extra": _Extra})
Error = collections.namedtuple('Error', ['message'])
File = collections.namedtuple('File', ['filename', 'content'])
StdOut = collections.namedtuple('StdOut', ['message'])
Verbose = collections.namedtuple('Verbose', ['message'])
def extras(project):
"""Return a dict of extra-name:content for the extras in setup.cfg."""
@@ -64,41 +32,6 @@ def extras(project):
return dict(c.items('extras'))
def merge_setup_cfg(old_content, new_extras):
# This is ugly. All the existing libraries handle setup.cfg's poorly.
prefix, extras, suffix = _extras_compiled(old_content).ini()
out_extras = []
if extras is not None:
for extra in extras:
if type(extra) is _Comment:
out_extras.append(extra)
elif type(extra) is _Extra:
if extra.name not in new_extras:
out_extras.append(extra)
continue
e = _Extra(
extra.name,
requirement.to_content(
new_extras[extra.name], ':', ' ', False))
out_extras.append(e)
else:
raise TypeError('unknown type %r' % extra)
if out_extras:
extras_str = ['[extras]\n']
for extra in out_extras:
if type(extra) is _Comment:
extras_str.append(extra.line)
else:
extras_str.append(extra.name + ' =')
extras_str.append(extra.content)
if suffix:
extras_str.append('\n')
extras_str = ''.join(extras_str)
else:
extras_str = ''
return prefix + extras_str + suffix
# IO from here to the end of the file.
def _safe_read(project, filename, output=None):
@@ -143,47 +76,3 @@ def read(root):
result['lower-constraints.txt'] = None
_safe_read(result, 'lower-constraints.txt')
return result
def write(project, actions, stdout, verbose, noop=False):
"""Write actions into project.
:param project: A project metadata dict.
:param actions: A list of action tuples - File or Verbose - that describe
what actions are to be taken.
Error objects write a message to stdout and trigger an exception at
the end of _write_project.
File objects describe a file to have content placed in it.
StdOut objects describe a message to write to stdout.
Verbose objects will write a message to stdout when verbose is True.
:param stdout: Where to write content for stdout.
:param verbose: If True Verbose actions will be written to stdout.
:param noop: If True nothing will be written to disk.
:return None:
:raises IOError: If the IO operations fail, IOError is raised. If this
happens some actions may have been applied and others not.
"""
error = False
for action in actions:
if type(action) is Error:
error = True
stdout.write(action.message + '\n')
elif type(action) is File:
if noop:
continue
fullname = os.path.join(project['root'], action.filename)
tmpname = fullname + '.tmp'
with open(tmpname, 'wt') as f:
f.write(action.content)
if os.path.exists(fullname):
os.remove(fullname)
os.rename(tmpname, fullname)
elif type(action) is StdOut:
stdout.write(action.message)
elif type(action) is Verbose:
if verbose:
stdout.write(u"%s\n" % (action.message,))
else:
raise Exception("Invalid action %r" % (action,))
if error:
raise Exception("Error occurred processing %s" % (project['root']))

View File

@@ -10,17 +10,14 @@
# License for the specific language governing permissions and limitations
# under the License.
import io
import textwrap
import fixtures
import parsley
import testscenarios
import testtools
from testtools import matchers
from openstack_requirements import project
from openstack_requirements import requirement
from openstack_requirements.tests import common
@@ -73,211 +70,3 @@ class TestProjectExtras(testtools.TestCase):
def test_no_setup_cfg(self):
proj = {}
self.assertEqual({}, project.extras(proj))
class TestExtrasParsing(testtools.TestCase):
def test_none(self):
old_content = textwrap.dedent(u"""
[metadata]
# something something
name = fred
[entry_points]
console_scripts =
foo = bar:quux
""")
ini = project._extras_compiled(old_content).ini()
self.assertEqual(ini, (old_content, None, ''))
def test_no_eol(self):
old_content = textwrap.dedent(u"""
[metadata]
# something something
name = fred
[entry_points]
console_scripts =
foo = bar:quux""")
expected1 = textwrap.dedent(u"""
[metadata]
# something something
name = fred
[entry_points]
console_scripts =
""")
suffix = ' foo = bar:quux'
ini = project._extras_compiled(old_content).ini()
self.assertEqual(ini, (expected1, None, suffix))
def test_two_extras_raises(self):
old_content = textwrap.dedent(u"""
[metadata]
# something something
name = fred
[extras]
a = b
[extras]
b = c
[entry_points]
console_scripts =
foo = bar:quux
""")
with testtools.ExpectedException(parsley.ParseError):
project._extras_compiled(old_content).ini()
def test_extras(self):
# We get an AST for extras we can use to preserve comments.
old_content = textwrap.dedent(u"""
[metadata]
# something something
name = fred
[extras]
# comment1
a =
b
c
# comment2
# comment3
d =
e
# comment4
[entry_points]
console_scripts =
foo = bar:quux
""")
prefix = textwrap.dedent(u"""
[metadata]
# something something
name = fred
""")
suffix = textwrap.dedent(u"""\
[entry_points]
console_scripts =
foo = bar:quux
""")
extras = [
project._Comment('# comment1\n'),
project._Extra('a', '\nb\nc\n'),
project._Comment('# comment2\n'),
project._Comment('# comment3\n'),
project._Extra('d', '\ne\n'),
project._Comment('# comment4\n')]
ini = project._extras_compiled(old_content).ini()
self.assertEqual(ini, (prefix, extras, suffix))
class TestMergeSetupCfg(testtools.TestCase):
def test_merge_none(self):
old_content = textwrap.dedent(u"""
[metadata]
# something something
name = fred
[entry_points]
console_scripts =
foo = bar:quux
""")
merged = project.merge_setup_cfg(old_content, {})
self.assertEqual(old_content, merged)
def test_merge_extras(self):
old_content = textwrap.dedent(u"""
[metadata]
name = fred
[extras]
# Comment
a =
b
# comment
c =
d
[entry_points]
console_scripts =
foo = bar:quux
""")
blank = requirement.Requirement('', '', '', '', '')
r1 = requirement.Requirement(
'b', '', '>=1', "python_version=='2.7'", '')
r2 = requirement.Requirement('d', '', '', '', '# BSD')
reqs = {
'a': requirement.Requirements([blank, r1]),
'c': requirement.Requirements([blank, r2])}
merged = project.merge_setup_cfg(old_content, reqs)
expected = textwrap.dedent(u"""
[metadata]
name = fred
[extras]
# Comment
a =
b>=1:python_version=='2.7'
# comment
c =
d # BSD
[entry_points]
console_scripts =
foo = bar:quux
""")
self.assertEqual(expected, merged)
class TestWriteProject(testtools.TestCase):
def test_smoke(self):
stdout = io.StringIO()
root = self.useFixture(fixtures.TempDir()).path
proj = {'root': root}
actions = [
project.File('foo', '123\n'),
project.File('bar', '456\n'),
project.Verbose(u'fred')]
project.write(proj, actions, stdout, True)
foo = open(root + '/foo', 'rt').read()
self.expectThat(foo, matchers.Equals('123\n'))
bar = open(root + '/bar', 'rt').read()
self.expectThat(bar, matchers.Equals('456\n'))
self.expectThat(stdout.getvalue(), matchers.Equals('fred\n'))
def test_non_verbose(self):
stdout = io.StringIO()
root = self.useFixture(fixtures.TempDir()).path
proj = {'root': root}
actions = [project.Verbose(u'fred')]
project.write(proj, actions, stdout, False)
self.expectThat(stdout.getvalue(), matchers.Equals(''))
def test_bad_action(self):
root = self.useFixture(fixtures.TempDir()).path
stdout = io.StringIO()
proj = {'root': root}
actions = [('foo', 'bar')]
with testtools.ExpectedException(Exception):
project.write(proj, actions, stdout, True)
def test_stdout(self):
stdout = io.StringIO()
root = self.useFixture(fixtures.TempDir()).path
proj = {'root': root}
actions = [project.StdOut(u'fred\n')]
project.write(proj, actions, stdout, True)
self.expectThat(stdout.getvalue(), matchers.Equals('fred\n'))
def test_errors(self):
stdout = io.StringIO()
root = self.useFixture(fixtures.TempDir()).path
proj = {'root': root}
actions = [project.Error(u'fred')]
with testtools.ExpectedException(Exception):
project.write(proj, actions, stdout, True)
self.expectThat(stdout.getvalue(), matchers.Equals('fred\n'))

View File

@@ -1,5 +1,4 @@
fixtures>=3.0.0 # Apache-2.0/BSD
Parsley>=1.2 # MIT
packaging!=20.5,!=20.6,!=20.7,>=16.5 # Apache-2.0
requests>=2.14.2 # Apache-2.0
PyYAML>=3.12 # MIT