aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-12-03 17:36:09 +0000
committerAvatar Piotr Jaroszyński <peper@gentoo.org> 2007-12-03 17:36:09 +0000
commitb954baed8b3979216e4079f62b1a7ee8d616e3b8 (patch)
treee7843f32e644c7b201971db39bea387f57042f52
parent0894d90ee740817bc5c72ba35b60894efcdd6ac7 (diff)
downloadpaludis-b954baed8b3979216e4079f62b1a7ee8d616e3b8.tar.gz
paludis-b954baed8b3979216e4079f62b1a7ee8d616e3b8.tar.xz
Fix PackageDepSpec after r4057. Also allow converting Python lists to Options classes. Fixes: ticket:451
-rw-r--r--python/additional_tests.cc3
-rwxr-xr-xpython/dep_list_TEST.py2
-rw-r--r--python/dep_spec.cc70
-rw-r--r--python/dep_spec.hh3
-rwxr-xr-xpython/dep_spec_TEST.py21
-rwxr-xr-xpython/dep_tag_TEST.py2
-rwxr-xr-xpython/environment_TEST.py11
-rwxr-xr-xpython/mask_TEST.py12
-rwxr-xr-xpython/metadata_key_TEST.py8
-rw-r--r--python/options.hh64
-rwxr-xr-xpython/package_database_TEST.py2
-rw-r--r--python/qa.cc2
-rwxr-xr-xpython/query_TEST.py2
13 files changed, 145 insertions, 57 deletions
diff --git a/python/additional_tests.cc b/python/additional_tests.cc
index 3682bf2..c34cc26 100644
--- a/python/additional_tests.cc
+++ b/python/additional_tests.cc
@@ -32,6 +32,7 @@
#include <paludis/repositories/fake/fake_package_id.hh>
#include <paludis/mask.hh>
#include <paludis/hook.hh>
+#include <paludis/util/options.hh>
#include <paludis/formatter.hh>
#include <paludis/stringify_formatter-impl.hh>
#include <paludis/util/clone-impl.hh>
@@ -275,7 +276,7 @@ namespace formatter
// CanFormat for PackageRoles
void test_package_roles(CanFormat<PackageDepSpec> & f)
{
- PackageDepSpec p("cat/pkg", pds_pm_permissive);
+ PackageDepSpec p(parse_user_package_dep_spec("cat/pkg", UserPackageDepSpecOptions()));
f.format(p, Plain());
f.format(p, Installed());
f.format(p, Installable());
diff --git a/python/dep_list_TEST.py b/python/dep_list_TEST.py
index c684666..a40c7c6 100755
--- a/python/dep_list_TEST.py
+++ b/python/dep_list_TEST.py
@@ -122,7 +122,7 @@ class TestCase_02_DepList(unittest.TestCase):
env = EnvironmentMaker.instance.make_from_spec("")
dl = DepList(env, DepListOptions())
dd = env.default_destinations
- pds = PackageDepSpec("foo/bar", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("foo/bar", [])
cds = env.set("bar")
def test_01_create(self):
diff --git a/python/dep_spec.cc b/python/dep_spec.cc
index 5158437..00e0c7f 100644
--- a/python/dep_spec.cc
+++ b/python/dep_spec.cc
@@ -20,6 +20,7 @@
#include "dep_spec.hh"
#include <python/paludis_python.hh>
#include <python/exception.hh>
+#include <python/options.hh>
#include <python/nice_names-nn.hh>
#include <paludis/dep_tag.hh>
@@ -291,34 +292,42 @@ PythonPackageDepSpec::~PythonPackageDepSpec()
{
}
-tr1::shared_ptr<const PythonPackageDepSpec>
-PythonPackageDepSpec::make_from_string(const std::string & ss, const PackageDepSpecParseMode p)
-{
- return make_shared_ptr(new PythonPackageDepSpec(PackageDepSpec(ss, p)));
-}
-
PythonPackageDepSpec::operator PackageDepSpec() const
{
- PackageDepSpec p
- (
- deep_copy(package_ptr()),
- deep_copy(category_name_part_ptr()),
- deep_copy(package_name_part_ptr()),
- make_shared_ptr(new VersionRequirements),
- version_requirements_mode(),
- deep_copy(slot_ptr()),
- deep_copy(repository_ptr()),
- deep_copy(use_requirements_ptr()),
- tag()
- );
+ PartiallyMadePackageDepSpec p;
+
+ if (package_ptr())
+ p.package(*package_ptr());
+
+ if (category_name_part_ptr())
+ p.category_name_part(*category_name_part_ptr());
+
+ if (package_name_part_ptr())
+ p.package_name_part(*package_name_part_ptr());
+
+ p.version_requirements_mode(version_requirements_mode());
+
+ if (slot_ptr())
+ p.slot(*slot_ptr());
+
+ if (repository_ptr())
+ p.repository(*repository_ptr());
+
+ if (use_requirements_ptr())
+ {
+ for (UseRequirements::ConstIterator i(use_requirements_ptr()->begin()),
+ i_end(use_requirements_ptr()->end()) ; i != i_end ; ++i)
+ p.use_requirement(i->first, i->second);
+ }
if (version_requirements_ptr())
{
- std::copy(version_requirements_ptr()->begin(), version_requirements_ptr()->end(),
- p.version_requirements_ptr()->back_inserter());
+ for (VersionRequirements::ConstIterator i(version_requirements_ptr()->begin()),
+ i_end(version_requirements_ptr()->end()) ; i != i_end ; ++i)
+ p.version_requirement(*i);
}
- return p;
+ return p.to_package_dep_spec();
}
@@ -1047,8 +1056,14 @@ void expose_dep_spec()
/**
* Enums
*/
- enum_auto("PackageDepSpecParseMode", last_pds_pm,
- "How to parse a PackageDepSpec string.");
+ enum_auto("UserPackageDepSpecOption", last_updso,
+ "Options for parse_user_package_dep_spec.");
+
+ /**
+ * Options
+ */
+ class_options<UserPackageDepSpecOptions>("UserPackageDepSpecOptions", "UserPackageDepSpecOption",
+ "Options for parse_user_package_dep_spec.");
RegisterSpecTreeToPython<DependencySpecTree>();
RegisterSpecTreeToPython<ProvideSpecTree>();
@@ -1182,6 +1197,12 @@ void expose_dep_spec()
/**
* PackageDepSpec
*/
+
+ bp::def("parse_user_package_dep_spec", &parse_user_package_dep_spec,
+ "parse_user_package_dep_spec(str, options=UserPackageDepSpecOptions()) -> PackageDepSpec\n"
+ "Create a PackageDepSpec from user input."
+ );
+
bp::implicitly_convertible<PythonPackageDepSpec, PackageDepSpec>();
bp::implicitly_convertible<PythonPackageDepSpec, tr1::shared_ptr<PackageDepSpec> >();
bp::implicitly_convertible<tr1::shared_ptr<PackageDepSpec>, tr1::shared_ptr<const PackageDepSpec> >();
@@ -1194,9 +1215,6 @@ void expose_dep_spec()
" possibly with associated version and SLOT restrictions.",
bp::no_init
)
- .def("__init__", bp::make_constructor(&PythonPackageDepSpec::make_from_string),
- "__init__(string, PackageDepSpecParseMode)"
- )
.add_property("package", &PythonPackageDepSpec::package_ptr,
"[ro] QualifiedPackageName\n"
diff --git a/python/dep_spec.hh b/python/dep_spec.hh
index b200a0d..98f8638 100644
--- a/python/dep_spec.hh
+++ b/python/dep_spec.hh
@@ -164,9 +164,6 @@ namespace paludis
PythonPackageDepSpec(const PythonPackageDepSpec &);
~PythonPackageDepSpec();
- static tr1::shared_ptr<const PythonPackageDepSpec>
- make_from_string(const std::string &, const PackageDepSpecParseMode);
-
operator PackageDepSpec() const;
operator tr1::shared_ptr<PackageDepSpec>() const;
diff --git a/python/dep_spec_TEST.py b/python/dep_spec_TEST.py
index 7079cdf..bc2fb04 100755
--- a/python/dep_spec_TEST.py
+++ b/python/dep_spec_TEST.py
@@ -24,7 +24,11 @@ import unittest
class TestCase_1_DepSpecs(unittest.TestCase):
def get_depspecs(self):
self.ptds = PlainTextDepSpec("foo")
- self.pds = PackageDepSpec(">=foo/bar-1:100::testrepo", PackageDepSpecParseMode.PERMISSIVE)
+ self.pds = parse_user_package_dep_spec(">=foo/bar-1:100::testrepo", [])
+ self.pds2 = parse_user_package_dep_spec("*/*::testrepo",
+ UserPackageDepSpecOptions() + UserPackageDepSpecOption.ALLOW_WILDCARDS)
+ self.pds3 = parse_user_package_dep_spec("*/*::testrepo", [UserPackageDepSpecOption.ALLOW_WILDCARDS])
+ self.pds4 = parse_user_package_dep_spec("cat/pkg::testrepo", [])
self.bds = BlockDepSpec(self.pds)
self.nds = NamedSetDepSpec("system")
@@ -33,9 +37,16 @@ class TestCase_1_DepSpecs(unittest.TestCase):
def test_02_create_error(self):
self.assertRaises(Exception, DepSpec)
+ self.assertRaises(Exception, PackageDepSpec)
self.assertRaises(Exception, StringDepSpec)
- self.assertRaises(BadVersionOperatorError, PackageDepSpec, "<>foo/bar", PackageDepSpecParseMode.PERMISSIVE)
- self.assertRaises(PackageDepSpecError, PackageDepSpec, "=foo/bar", PackageDepSpecParseMode.PERMISSIVE)
+ self.assertRaises(BadVersionOperatorError, parse_user_package_dep_spec,
+ "<>foo/bar", UserPackageDepSpecOptions())
+ self.assertRaises(PackageDepSpecError, parse_user_package_dep_spec,
+ "=foo/bar", [])
+ self.assertRaises(PackageDepSpecError, parse_user_package_dep_spec,
+ "*/*::testrepo", UserPackageDepSpecOptions())
+ self.assertRaises(PackageDepSpecError, parse_user_package_dep_spec,
+ "*/*::testrepo", [])
def test_03_str(self):
self.get_depspecs()
@@ -69,13 +80,13 @@ class TestCase_1_DepSpecs(unittest.TestCase):
self.assertEquals(self.pds.version_requirements_mode, VersionRequirementsMode.AND)
def test_09_use_requirements(self):
- spec = PackageDepSpec("foo/monkey[foo]", PackageDepSpecParseMode.PERMISSIVE)
+ spec = parse_user_package_dep_spec("foo/monkey[foo]", UserPackageDepSpecOptions())
ur = iter(spec.use_requirements).next()
self.assertEquals(str(ur[0]), "foo")
self.assertEquals(ur[1], UseFlagState.ENABLED)
def test_10_without_use_requirements(self):
- spec = PackageDepSpec("foo/monkey[foo]", PackageDepSpecParseMode.PERMISSIVE)
+ spec = parse_user_package_dep_spec("foo/monkey[foo]", UserPackageDepSpecOptions())
pds = spec.without_use_requirements()
self.assertEquals(pds.use_requirements, None)
self.assertEquals(str(pds), "foo/monkey")
diff --git a/python/dep_tag_TEST.py b/python/dep_tag_TEST.py
index 47486fd..bcde430 100755
--- a/python/dep_tag_TEST.py
+++ b/python/dep_tag_TEST.py
@@ -57,7 +57,7 @@ class TestCase_04_DependencyDepTag(unittest.TestCase):
env = TestEnvironment()
repo = FakeRepository(env, "repo")
pid = repo.add_version("cat/foo", "1.0")
- pds = PackageDepSpec("=cat/boo-1", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("=cat/boo-1", [])
cds = env.set("everything")
dt = DependencyDepTag(pid, pds, cds);
diff --git a/python/environment_TEST.py b/python/environment_TEST.py
index 26339d8..98f7542 100755
--- a/python/environment_TEST.py
+++ b/python/environment_TEST.py
@@ -53,7 +53,7 @@ class TestCase_01_Environments(unittest.TestCase):
def test_04_query_use(self):
pid = iter(self.e.package_database.query(Query.Matches(
- PackageDepSpec("=foo/bar-1.0", PackageDepSpecParseMode.PERMISSIVE)),
+ parse_user_package_dep_spec("=foo/bar-1.0", [])),
QueryOrder.REQUIRE_EXACTLY_ONE)).next()
self.assert_(self.e.query_use("enabled", pid))
@@ -103,9 +103,9 @@ class TestCase_02_AdaptedEnvironment(unittest.TestCase):
def test_02_adapt_use(self):
env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
pid = iter(env.package_database.query(Query.Matches(
- PackageDepSpec("=foo/bar-1.0", PackageDepSpecParseMode.PERMISSIVE)),
+ parse_user_package_dep_spec("=foo/bar-1.0", [])),
QueryOrder.REQUIRE_EXACTLY_ONE)).next()
- pds = PackageDepSpec("foo/bar", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("foo/bar", [])
self.assert_(env.query_use("enabled", pid))
self.assert_(not env.query_use("not_enabled", pid))
@@ -122,10 +122,9 @@ class TestCase_02_AdaptedEnvironment(unittest.TestCase):
def test_03_clear_adaptions(self):
env = AdaptedEnvironment(EnvironmentMaker.instance.make_from_spec(""))
- pid = iter(env.package_database.query(Query.Matches(
- PackageDepSpec("=foo/bar-1.0", PackageDepSpecParseMode.PERMISSIVE)),
+ pid = iter(env.package_database.query(Query.Matches(parse_user_package_dep_spec("=foo/bar-1.0", [])),
QueryOrder.REQUIRE_EXACTLY_ONE)).next()
- pds = PackageDepSpec("foo/bar", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("foo/bar", [])
self.assert_(env.query_use("enabled", pid))
diff --git a/python/mask_TEST.py b/python/mask_TEST.py
index fdc6575..123f62e 100755
--- a/python/mask_TEST.py
+++ b/python/mask_TEST.py
@@ -35,7 +35,7 @@ class TestCase_01_Masks(unittest.TestCase):
self.db = self.e.package_database
def test_01_user_mask(self):
- q = Query.Matches(PackageDepSpec("=masked/user-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ q = Query.Matches(parse_user_package_dep_spec("=masked/user-1.0", []))
pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
m = iter(pid.masks).next()
@@ -46,7 +46,7 @@ class TestCase_01_Masks(unittest.TestCase):
self.assertEquals(m.description(), "user")
def test_02_unaccepted_mask(self):
- q = Query.Matches(PackageDepSpec("=masked/unaccepted-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ q = Query.Matches(parse_user_package_dep_spec("=masked/unaccepted-1.0", []))
pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
m = iter(pid.masks).next()
@@ -58,7 +58,7 @@ class TestCase_01_Masks(unittest.TestCase):
self.assert_(isinstance(m.unaccepted_key(), MetadataKeywordNameIterableKey))
def test_03_repository_mask(self):
- q = Query.Matches(PackageDepSpec("=masked/repo-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ q = Query.Matches(parse_user_package_dep_spec("=masked/repo-1.0", []))
pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
m = iter(pid.masks).next()
@@ -73,7 +73,7 @@ class TestCase_01_Masks(unittest.TestCase):
self.assert_(isinstance(m.mask_key().value().comment, StringIterable))
def test_04_unsupported_mask(self):
- q = Query.Matches(PackageDepSpec("=masked/unsupported-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ q = Query.Matches(parse_user_package_dep_spec("=masked/unsupported-1.0", []))
pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
m = iter(pid.masks).next()
@@ -85,7 +85,7 @@ class TestCase_01_Masks(unittest.TestCase):
self.assertEquals(m.explanation(), "Unsupported EAPI 'unsupported'")
def test_05_association_mask(self):
- q = Query.Matches(PackageDepSpec("=virtual/association-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ q = Query.Matches(parse_user_package_dep_spec("=virtual/association-1.0", []))
pid = iter(self.db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
m = iter(pid.masks).next()
@@ -157,7 +157,7 @@ class TestCase_02_Masks_subclassing(unittest.TestCase):
def associated_package(self):
e = EnvironmentMaker.instance.make_from_spec("")
db = e.package_database
- q = Query.Matches(PackageDepSpec("=masked/user-1.0", PackageDepSpecParseMode.PERMISSIVE))
+ q = Query.Matches(parse_user_package_dep_spec("=masked/user-1.0", []))
pid = iter(db.query(q, QueryOrder.REQUIRE_EXACTLY_ONE)).next()
return pid
diff --git a/python/metadata_key_TEST.py b/python/metadata_key_TEST.py
index cc55b74..4822c94 100755
--- a/python/metadata_key_TEST.py
+++ b/python/metadata_key_TEST.py
@@ -207,11 +207,11 @@ class TestCase_02_MetadataKeys_suclassing(unittest.TestCase):
return AllDepSpec()
def pretty_print(self, f):
- pds = PackageDepSpec("cat/pkg", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("cat/pkg", [])
return f.format_package_dep_spec_plain(pds)
def pretty_print_flat(self, f):
- pds = PackageDepSpec("cat/pkg", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("cat/pkg", [])
return f.format_package_dep_spec_plain(pds)
test_metadata_provide_spec_tree_key(TestKey())
@@ -225,11 +225,11 @@ class TestCase_02_MetadataKeys_suclassing(unittest.TestCase):
return AllDepSpec()
def pretty_print(self, f):
- pds = PackageDepSpec("cat/pkg", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("cat/pkg", [])
return f.format_package_dep_spec_plain(pds)
def pretty_print_flat(self, f):
- pds = PackageDepSpec("cat/pkg", PackageDepSpecParseMode.PERMISSIVE)
+ pds = parse_user_package_dep_spec("cat/pkg", [])
return f.format_package_dep_spec_plain(pds)
test_metadata_dependency_spec_tree_key(TestKey())
diff --git a/python/options.hh b/python/options.hh
index ce20981..29c66bc 100644
--- a/python/options.hh
+++ b/python/options.hh
@@ -28,6 +28,64 @@ namespace paludis
{
namespace python
{
+ template <typename O_>
+ struct RegisterOptionsFromPython;
+
+ template <typename E_>
+ struct RegisterOptionsFromPython<Options<E_> >
+ {
+ static std::string _name;
+
+ RegisterOptionsFromPython(const std::string & name)
+ {
+ boost::python::converter::registry::push_back(&convertible, &construct,
+ boost::python::type_id<Options<E_> >());
+
+ _name = name;
+ }
+
+ static void *
+ convertible(PyObject * obj_ptr)
+ {
+ if (boost::python::extract<boost::python::list>(obj_ptr).check())
+ return obj_ptr;
+ else
+ return 0;
+ }
+
+ static void
+ construct(PyObject * obj_ptr, boost::python::converter::rvalue_from_python_stage1_data * data)
+ {
+ typedef boost::python::converter::rvalue_from_python_storage<Options<E_> > Storage;
+ void * storage = reinterpret_cast<Storage *>(data)->storage.bytes;
+
+ data->convertible = storage;
+
+ new (storage) Options<E_>;
+
+ Options<E_> * o(reinterpret_cast<Options<E_> *>(storage));
+
+ boost::python::list l = boost::python::extract<boost::python::list>(obj_ptr);
+
+ while (PyList_Size(obj_ptr))
+ {
+ boost::python::object py_e(l.pop());
+ if (boost::python::extract<E_>(py_e).check())
+ {
+ E_ e = boost::python::extract<E_>(py_e);
+ *o += e;
+ }
+ else
+ {
+ throw PythonError(std::string("Cannot add object of type ")
+ + py_e.ptr()->ob_type->tp_name + " to " + _name);
+ }
+ }
+ }
+ };
+ template <typename E_>
+ std::string RegisterOptionsFromPython<Options<E_> >::_name("unknown");
+
// expose Options classes
template <typename O_>
class class_options :
@@ -36,7 +94,9 @@ namespace paludis
public:
class_options(const std::string & set_name, const std::string & bit_name,
const std::string & class_doc) :
- boost::python::class_<O_>(set_name.c_str(), class_doc.c_str(),
+ boost::python::class_<O_>(set_name.c_str(),
+ (class_doc + "\n\n Note that python lists containing suitable enum "
+ "values are convertible to Options classes.").c_str(),
boost::python::init<>("__init__()"))
{
this->add_property("any", &O_::any,
@@ -79,6 +139,8 @@ namespace paludis
("subtract("+set_name+") -> "+set_name+"\n"
"Disable any bits that are enabled in the parameter.").c_str()
);
+
+ RegisterOptionsFromPython<O_> tmp(set_name);
}
};
} // namespace paludis::python
diff --git a/python/package_database_TEST.py b/python/package_database_TEST.py
index 1fba70a..f21c374 100755
--- a/python/package_database_TEST.py
+++ b/python/package_database_TEST.py
@@ -57,7 +57,7 @@ class TestCase_PackageDatabase(unittest.TestCase):
"foo/bar-1.0::testrepo",
"foo/bar-2.0::testrepo"])
- pkgs = list(self.db.query(Query.Matches(PackageDepSpec(">=foo/bar-10", PackageDepSpecParseMode.PERMISSIVE)),
+ pkgs = list(self.db.query(Query.Matches(parse_user_package_dep_spec(">=foo/bar-10", [])),
QueryOrder.ORDER_BY_VERSION))
self.assertEqual(len(pkgs), 0)
diff --git a/python/qa.cc b/python/qa.cc
index 50303e7..3f7408a 100644
--- a/python/qa.cc
+++ b/python/qa.cc
@@ -67,7 +67,7 @@ void expose_qa()
* Options
*/
class_options<QACheckProperties>("QACheckProperties", "QACheckProperty",
- "NEED_DOC");
+ "A collection of properties for a QA check.");
/**
* QAMessage
diff --git a/python/query_TEST.py b/python/query_TEST.py
index 609853c..5def69d 100755
--- a/python/query_TEST.py
+++ b/python/query_TEST.py
@@ -36,7 +36,7 @@ class TestCase_01_Queries(unittest.TestCase):
self.queries.append(Query.InstalledAtRoot("/bar"))
self.queries.append(Query.NotMasked())
self.queries.append(Query.Package("foo/bar"))
- self.queries.append(Query.Matches(PackageDepSpec(">=foo/bar-1", PackageDepSpecParseMode.PERMISSIVE)))
+ self.queries.append(Query.Matches(parse_user_package_dep_spec(">=foo/bar-1", [])))
self.queries.append(Query.All())
self.queries.append(Query.Category("cat-foo"))
self.queries.append(Query.Repository("foo_repo"))