how to remove the unused genreated require when use protobuf anotations - protocol-buffers

package usegogo.api.v1;
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/field_mask.proto";
import "gogoproto/gogo.proto";
option (gogoproto.marshaler_all) = false;
I use gogoproto to generate go codes.
But when I generate nodejs code, there is a var gogoproto_gogo_pb = require('../../../gogoproto/gogo_pb.js');
this is generated because i use import "gogoproto/gogo.proto";
is there any way to let protoc ignore the the import "gogoproto/gogo.proto"; sine i don't use this when i genreate nodejs code.

Protoc will actually generate gogo_pb.js if you point it to gogo.proto like you do with your other proto files.

Related

Error when importing sklearn in pipeline component

When I run this simple pipeline (in GCP's Vertex AI Workbench) I get an error:
ModuleNotFoundError: No module named 'sklearn'
Here is my code:
from kfp.v2 import compiler
from kfp.v2.dsl import pipeline, component
from google.cloud import aiplatform
#component(
packages_to_install=["sklearn"],
base_image="python:3.9",
)
def test_sklearn():
import sklearn
#pipeline(
pipeline_root=PIPELINE_ROOT,
name="sklearn-pipeline",
)
def pipeline():
test_sklearn()
compiler.Compiler().compile(pipeline_func=pipeline, package_path="sklearn_pipeline.json")
job = aiplatform.PipelineJob(
display_name=PIPELINE_DISPLAY_NAME,
template_path="sklearn_pipeline.json",
pipeline_root=PIPELINE_ROOT,
location=REGION
)
job.run(service_account=SERVICE_ACCOUNT)
What do I do wrong? :)
It seems that the package name sklearn does not work after a version upgrade.You need to change the value of packages_to_install from "sklearn" to "scikit-learn" in the #component block.

Is it possible to make the internal dependencies inside a python module user selectable?

After testing the logger library locally, I uploaded it to pypi.
Afterwards, when I proceeded with pip install, there was an error saying that the module inside the library could not be found.
So, as a temporary measure, I added a syntax to register all .py in init.py in the library package folder, and I want to improve this. This is because you have to install all dependencies for features that users may not be using
What improvements can I take in this situation?
If possible, I would like to know how to lazy use only the modules used by the user instead of registering all .py in init.py .
Or is there something structurally I'm overlooking?
Here is the project structure I used
project_name
- pacakge_name
- __init__.py. <- all loggers were registered
- file_logger.py
- console_logger.py
- ...
- fluent_logger.py <- used external library
- scribe_logger.py <- used external library
init.py
"""
Description for Package
"""
from .composite_logger import CompositeLogger
from .console_logger import ConsoleLogger
from .file_logger import FileLogger
from .fluent_logger import FluentLogger
from .jandi_logger import JandiLogger
from .line_logger import LineLogger
from .logger_impl import LoggerImpl
from .logger_interface import LoggerInterface
from .logger import Logger
from .memory_logger import MemoryLogger
from .null_logger import NullLogger
from .scribe_logger import ScribeLogger
from .telegram_logger import TelegramLogger
from .retry import Retry
__all__ = [
'CompositeLogger',
'ConsoleLogger',
'FileLogger',
'FluentLogger',
'JandiLogger',
'LineLogger',
'LoggerImpl',
'LoggerInterface',
'Logger',
'MemoryLogger',
'NullLogger',
'ScribeLogger',
'TelegramLogger',
'Retry',
]
setup.py
import setuptools
from distutils.core import setup
with open("README.md", "r", encoding="utf-8") as f:
long_descriprion = f.read()
setuptools.setup(
name = 'project_name',
version = '0.0.1',
description = 'python logger libary',
long_description = long_descriprion,
long_description_content_type = "text/markdown",
author = 'abc',
author_email = 'abc#gmail.com',
url = "https://github.com/##/##",
packages = ["pacakge_name"],
install_requires=[ <- contains too many external libraries
'requests>=2.0.0',
'thrift>=0.16.0',
'facebook-scribe>=2.0.post1',
'fluent-logger>=0.10.0'
],
keywords = ['logger'],
python_requires = '>=3.7',
classifiers = [
'Programming Language :: Python :: 3.7',
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
],
)

ansible.inventory.Inventory class replacement from Ansible 2.4+ onwards

I'm currently using ansible 2.3.3 and trying to upgrade it to a newever version but since 2.4+ the ansible.inventory.Inventory class has been removed.
Does anybody know what is the equivalent recommended replacement of ansible.inventory.Inventory in Ansible 2.4+?
from ansible.inventory import Inventory
from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager
inv = Inventory(
loader = DataLoader(),
variable_manager = VariableManager(),
host_list = my_path,
)
There isn't a one to one replacement in the newer code but the following code can be used but note that the inventory now has a different data structure
from ansible.inventory.manager import InventoryManager
from ansible.parsing.dataloader import DataLoader
m = InventoryManager(loader=DataLoader(), sources='/path/to/inventory')
m.hosts
m.groups

Cannot import Interaction Type Discord Components

I have done the import of Discord-Components via pip install --upgrade discord-componentsin Shell
And then I imported into the code (line of import from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType)
but I cannot import InteractionType???
File "main.py", line 19, in <module>
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType
ImportError: cannot import name 'InteractionType' from 'discord_components' (/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/__init__.py)
InteractionType is removed in 2.0.0 as stated in the latest (gitbook) docs.
Docs link: https://devkiki7000.gitbook.io/discord-components/change-log/2.0.0#breaking-changes
Use integers to replace them.
ChannelMessageWithSource = 4
DeferredChannelMessageWithSource = 5
DeferredUpdateMessage = 6

proto3 -> go with custom extensions resulting in imports to package ("google/protobuf") in go code

I am prototyping a meta model on top of proto3. To generate domain specific boilerplate as the go proto3 extension syntax is ridiculously expressive. My domain proto files depend on meta.proto which contain the extensions.
I can compile the these to go. When including the meta.proto file the generated go ends up with the following include block:
import proto "github.com/golang/protobuf/proto"
import fmt "fmt"
import math "math"
import google_protobuf "google/protobuf" <--- this import does not exist !!
My extension file has the following structure(based off this):
syntax = "proto2";
package "...";
option go_package = "...";
import "google/protobuf/descriptor.proto"; <--- this causes the import
// message MyExtensionClass ...
// message MyExtensionField ...
extend google.protobuf.MessageOptions {
optional MyExtensionClass class = 50000;
}
extend google.protobuf.FieldOptions {
optional MyExtensionField field = 50001;
}
I know the solution is likely very simple, the google/protobuf include is meant for C++ generation.
In my workspace the included package should be "github.com/golang/protobuf/protoc-gen-go/descriptor"
Poor mans solution. Not ideal, directing it to the relevant go import works:
sed -i '' -e 's/import google_protobuf \"google\/protobuf\"/import google_protobuf \"github.com\/golang\/protobuf\/protoc-gen-go\/descriptor\"/g' pkg/domain/proto/extensions/*.pb.go

Resources