Extending protobuf.FieldOptions in imported .proto file - c++

I'm trying to define my custom field option in google protocol buffers. If I create such a file, everything works ok:
import "google/protobuf/descriptor.proto";
package tutorial;
extend google.protobuf.FieldOptions {
optional int32 myopt = 70000;
}
message Persona {
required string name = 1 [(myopt)=5];
}
However, if I try to move "myopt" definition to another file, compilation fails:
myext.proto:
package myext;
import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
optional int32 myopt = 70000;
}
addressbook.proto:
import "google/protobuf/descriptor.proto";
import "myext.proto";
package tutorial;
message Persona {
required string name = 1 [(myopt)=5];
}
compilation:
$ protoc --cpp_out=. -I/usr/include -I. addressbook.proto
addressbook.proto:8:29: Option "(myopt)" unknown.
Is there any way to define custom field options in other file than the one that use it? It is important to move common part to a common file if I want to use my option in several .proto files.

Because you have a package myext
you should be doing
import "myext/myext.proto";
with myext.proto located in a sub-directory of myext.
In protocol buffer package indicates the directory where the file should reside (like in java)

Because you've made a new package with your new proto file, you'll need to reference the package's namespace.
As you noted in your comment, just use "(myext.myopt)" instead of "(myopt)", so it looks like this:
myext.proto:
Unmodified from what you showed
package myext;
import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
optional int32 myopt = 70000;
}
addressbook.proto:
Replace "(myopt)" with "(myext.myopt)"
import "google/protobuf/descriptor.proto";
import "myext.proto";
package tutorial;
message Persona {
required string name = 1 [(myext.myopt)=5];
}

Related

how to find a certain named import in vscode

for example I have a following line in some file in my project:
import { Button, Switch, message, notification } from 'antd';
and the following line in another file:
import { Table, notification } from 'antd';
How can I use VSCode search to find both of these files? and any other file which also has notification function import from antd, among other functions/components from antd library
import \{.*notification.*from 'antd';

Imported library 'owaspapi' contains no keywords. (if it's installed using pip)

I have made a library for Robot Framework (myapi.py). If I place it in the same directory with my robot test I can import the library like this:
Library myapi.py
It works just fine.
However, I made the library pip installable so that others may take it into use in other projects easily. The library installs just fine with pip. I also changed the robot test to import the library like this:
Library myapi
When I run the robot test I get warning:
[ WARN ] Imported library 'myapi' contains no keywords.
Here's the (pip installable) library file structure:
setup.py
myapi
\__init__.py
\myapi.py
\version.py
The setup.py content is:
from setuptools import setup, find_packages
exec(open('myapi/version.py').read())
setup(
name='myapi',
version=__version__,
packages=['myapi'],
install_requires=['requests']
)
The init.py content is:
from .version import __version__
The version.py content is:
__version__ = '1.1.0'
The myapi.py content is (included only the first function I have):
import requests
import time
from time import strftime
import urllib2
__all__ = ['create_new_MY_session']
def create_new_MY_session():
session_name = strftime('my_session_%S_%H_%M_%d_%m_%Y')
r = requests.get("http://localhost:8080/JSON/core/action/newSession/?zapapiformat=JSON&name=" + session_name + "/'")
print ("Creating new session: " + session_name + ". Status code...")
print (r.status_code)
assert (r.status_code) == 200
And finally the beginning of the robot test (login.robot):
*** Settings ***
Suite Setup Open Firefox With Proxy
Suite Teardown Close Browser
Library mypapi
Library OperatingSystem
Library Selenium2Library
Resource ws_keywords/product/webui.robot
*** Test Cases ***
MY Start New MY Session
Create New MY Session
I wonder if the library works just fine when located right next to the robot test, what am I missing if I make it pip installable...? Why does it complain that there are no keywords?
In your myapi.py file you missing the class reference. When the file is placed inside your Robot Framework project this wasn't an issue, but when creating a pip installable module, this is required. A basic Python Library code example is this:
myapi.py
class myapi(object):
ROBOT_LIBRARY_VERSION = 1.0
def __init__(self):
pass
def keyword(self):
pass

Issue with import module in python framework when working with Appium integrated with toolium

I have created an automation framework using toolium with Appium which works for both IOS and Android. Toolium is a python wrapper that I've used to facilitate page object modelling. Basically the UI is separated from the test case so that the same test case can be used across android as well as IOS.
I now need to get the framework working with IOS 10 (With XCUI test framework). So I have changed the elements for IOS so as to support XCUI (Places were XPATH is used and there is no other means of element identification). There is no change in the folder structure/execution mechanism whatsoever. But with the new framework I get an import error from toolium.
Code from tooling mobile page objects.py looks something like this.
# -*- coding: utf-8 -*-
import importlib
from toolium.driver_wrapper import DriverWrappersPool
from toolium.pageobjects.page_object import PageObject
class MobilePageObject(PageObject):
def __new__(cls, driver_wrapper=None):
"""Instantiate android or ios page object from base page object depending on driver configuration
Base, Android and iOS page objects must be defined with following structure:
FOLDER/base/MODULE_NAME.py
class BasePAGE_OBJECT_NAME(MobilePageObject)
FOLDER/android/MODULE_NAME.py
class AndroidPAGE_OBJECT_NAME(BasePAGE_OBJECT_NAME)
FOLDER/ios/MODULE_NAME.py
class IosPAGE_OBJECT_NAME(BasePAGE_OBJECT_NAME)
:param driver_wrapper: driver wrapper instance
:returns: android or ios page object instance
"""
if cls.__name__.startswith('Base'):
__driver_wrapper = driver_wrapper if driver_wrapper else DriverWrappersPool.get_default_wrapper()
__os_name = 'ios' if __driver_wrapper.is_ios_test() else 'android'
__class_name = cls.__name__.replace('Base', __os_name.capitalize())
try:
return getattr(importlib.import_module(cls.__module__), __class_name)(__driver_wrapper)
except AttributeError:
__module_name = cls.__module__.replace('.base.', '.{}.'.format(__os_name))
print __module_name
print __class_name
print __driver_wrapper
return getattr(importlib.import_module(__module_name), __class_name)(__driver_wrapper)
else:
return super(MobilePageObject, cls).__new__(cls)
I follow the folder structure as mentioned in toolium. Basically I have,
pageobjects folder under which I have base folder, ios folder and android folder. All my methods are in the base class. The elements are picked up either from the iOS folder or android folder at run time based on the driver type.
Below is the error from the import module
name = 'pageobjects.ios.intro', package = None
def import_module(name, package=None):
"""Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
level = 0
for character in name:
if character != '.':
break
level += 1
name = _resolve_name(name[level:], package, level)
__import__(name)
E ImportError: No module named ios.intro
When I print the module name and class name this is what I get.
module name = pageobjects.ios.intro
class name = IosIntroduction
intro is one of the modules basically. I access it something like this
from pageobjects.base.intro import BaseIntroduction
On the same machine I have the old framework working without any problem. I have checked environment variables/permissions etc. But I can't seem to figure out as to why the import is failing.
PS: I am running this on MACOSX and also use virtualenvironment for python

How to use public imports in D

I am trying to replicate a namespace kind of pattern in D. I would like to have one class per file and be able to use a single import statement to include all classes from a group of files.
in my root folder I have moduleExp.d
import foo.module;
import std.stdio;
void main()
{
writeln("hello world");
auto quakk = new Quakk();
quakk.write();
}
In my foo folder I have module1.d:
module foo.module1;
import std.stdio;
class Quakk
{
public string name = "thename";
public void write()
{
writeln(this.name);
}
}
Also in foo folder, I have module.d which I thought I could use to publicly import all my class modules into so they can be used in moduleExp.d of the root folder.
module foo.module;
public import foo.module1;
When I try to compile on Windows from the root folder with rdmd moduleExp, I get errors:
moduleExp.d(1): Error: identifier expected following package
moduleExp.d(1): Error: ';' expected
Failed: ["dmd", "-v", "-o-", "moduleExp.d", "-I."]
I'm not sure what I'm doing wrong here. if I change line 1 in module.Exp.d to import foo.module1; then everything works.
module is a reserved keyword that you shouldn't use as a module name. And what you are trying to do exists as a feature in dlang called package modules. Look in http://dlang.org/module.html for documentation.
So basically, you have a module under the folder foo, its name should be package.d, where you publicly import the modules within foo and any other modules that you want. Example:
module foo; // notice the module name is used
// for the package module and not foo.package
public import foo.module1;
public import foo.module2;
...
And now when you want to import the package, just write import foo.

How to configure pyximport to always make a cpp file? [duplicate]

pyximport is super handy but I can't figure out how to get it to engage the C++ language options for Cython. From the command line you'd run cython --cplus foo.pyx. How do you achieve the equivalent with pyximport? Thanks!
One way to make Cython create C++ files is to use a pyxbld file. For example, create foo.pyxbld containing the following:
def make_ext(modname, pyxfilename):
from distutils.extension import Extension
return Extension(name=modname,
sources=[pyxfilename],
language='c++')
Here's a hack.
The following code monkey-patches the get_distutils_extension function in pyximport so that the Extension objects it creates all have their language attribute set to c++.
import pyximport
from pyximport import install
old_get_distutils_extension = pyximport.pyximport.get_distutils_extension
def new_get_distutils_extension(modname, pyxfilename, language_level=None):
extension_mod, setup_args = old_get_distutils_extension(modname, pyxfilename, language_level)
extension_mod.language='c++'
return extension_mod,setup_args
pyximport.pyximport.get_distutils_extension = new_get_distutils_extension
Put the above code in pyximportcpp.py. Then, instead of using import pyximport; pyximport.install(), use import pyximportcpp; pyximportcpp.install().
A more lightweight/less intrusive solution would be to use setup_args/script_args, which pyximport would pass to distutils used under the hood:
script_args = ["--cython-cplus"]
setup_args = {
"script_args": script_args,
}
pyximport.install(setup_args=setup_args, language_level=3)
Other options for python setup.py build_ext can be passed in similar maner, e.g. script_args = ["--cython-cplus", "--force"].
The corresponding part of the documentation mentions the usage of setup_args, but the exact meaning is probably clearest from the code itself (here is a good starting point).
You can have pyximport recognize the header comment # distutils : language = c++ by having pyximport make extensions using the cythonize command. To do so, you can create a new file filename.pyxbld next to your filename.pyx:
# filename.pyxbld
from Cython.Build import cythonize
def make_ext(modname, pyxfilename):
return cythonize(pyxfilename, language_level = 3, annotate = True)[0]
and now you can use the distutils header comments:
# filename.pyx
# distutils : language = c++
Pyximport will use the make_ext function from your .pyxbld file to build the extension. And cythonize will recognize the distutils header comments.