From 0b5e3ce7ed0c10eaef44b232334f52f12fc47bf2 Mon Sep 17 00:00:00 2001 From: ctrl-felix <62290842+ctrl-Felix@users.noreply.github.com> Date: Mon, 1 Aug 2022 13:31:21 +0200 Subject: [PATCH] fix aggregation include pattern & create release --- .gitignore | 2 - aggregate.py | 21 +++++++-- src/cosmospy_protobuf/gogoproto/Makefile | 36 --------------- .../gogoproto/gogo.pb.golden | 45 ------------------- 4 files changed, 17 insertions(+), 87 deletions(-) delete mode 100644 src/cosmospy_protobuf/gogoproto/Makefile delete mode 100644 src/cosmospy_protobuf/gogoproto/gogo.pb.golden diff --git a/.gitignore b/.gitignore index 2b7fb280..81e53af7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ .idea -*.pyc -*.pyi test/ dist/ cosmospy_protobuf.egg-info diff --git a/aggregate.py b/aggregate.py index 1e6e6d89..3b114ad7 100644 --- a/aggregate.py +++ b/aggregate.py @@ -1,9 +1,9 @@ -import errno import json import os import shutil import time -from os.path import dirname, abspath, isfile +from os.path import dirname, abspath, isfile, isdir +import fnmatch import argparse from git import Repo @@ -12,6 +12,16 @@ parser.add_argument('coin', type=str, help="Coin to parse from the .json file in the config folder") args = parser.parse_args() +# https://stackoverflow.com/questions/52071642/python-copying-the-files-with-include-pattern +def include_patterns(*patterns): + def _ignore_patterns(path, names): + keep = set(name for pattern in patterns + for name in fnmatch.filter(names, pattern)) + ignore = set(name for name in names + if name not in keep and not isdir(os.path.join(path, name))) + return ignore + + return _ignore_patterns # Get current directory d = dirname(abspath(__file__)) @@ -38,6 +48,9 @@ root_dir = 'src/cosmospy_protobuf' root_abs_path = os.path.join(d, root_dir) for filename in os.listdir(root_abs_path): + if filename == ".gitignore": + continue + file_path = os.path.join(root_abs_path, filename) try: if os.path.isfile(file_path) or os.path.islink(file_path): @@ -63,9 +76,9 @@ proto_dir = os.path.join(repo_dir, proto_folder) category_name = proto_folder.split('/')[-1] try: - shutil.copytree(proto_dir, root_abs_path + "/" + category_name, dirs_exist_ok=True, ignore=shutil.ignore_patterns("*.go")) + shutil.copytree(proto_dir, root_abs_path + "/" + category_name, dirs_exist_ok=True, ignore=include_patterns("*.proto")) print(f"Copied {category_name}") - except OSError as exc: # python >2.5 + except OSError as exc: try: shutil.copy(proto_dir, root_abs_path) print(f"File {proto_dir} copied successfully") diff --git a/src/cosmospy_protobuf/gogoproto/Makefile b/src/cosmospy_protobuf/gogoproto/Makefile deleted file mode 100644 index 6763edd8..00000000 --- a/src/cosmospy_protobuf/gogoproto/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -# Protocol Buffers for Go with Gadgets -# -# Copyright (c) 2013, The GoGo Authors. All rights reserved. -# http://github.com/cosmos/gogoproto -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# * Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# * Redistributions in binary form must reproduce the above -# copyright notice, this list of conditions and the following disclaimer -# in the documentation and/or other materials provided with the -# distribution. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -regenerate: - protoc --gogo_out=Mgoogle/protobuf/descriptor.proto=github.com/cosmos/gogoproto/protoc-gen-gogo/descriptor:../../../../ --proto_path=../../../../:../protobuf/:. *.proto - -restore: - cp gogo.pb.golden gogo.pb.go - -preserve: - cp gogo.pb.go gogo.pb.golden diff --git a/src/cosmospy_protobuf/gogoproto/gogo.pb.golden b/src/cosmospy_protobuf/gogoproto/gogo.pb.golden deleted file mode 100644 index 5a9d59d1..00000000 --- a/src/cosmospy_protobuf/gogoproto/gogo.pb.golden +++ /dev/null @@ -1,45 +0,0 @@ -// Code generated by protoc-gen-go. -// source: gogo.proto -// DO NOT EDIT! - -package gogoproto - -import proto "github.com/cosmos/gogoproto/proto" -import json "encoding/json" -import math "math" -import google_protobuf "github.com/cosmos/gogoproto/protoc-gen-gogo/descriptor" - -// Reference proto, json, and math imports to suppress error if they are not otherwise used. -var _ = proto.Marshal -var _ = &json.SyntaxError{} -var _ = math.Inf - -var E_Nullable = &proto.ExtensionDesc{ - ExtendedType: (*google_protobuf.FieldOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 51235, - Name: "gogoproto.nullable", - Tag: "varint,51235,opt,name=nullable", -} - -var E_Embed = &proto.ExtensionDesc{ - ExtendedType: (*google_protobuf.FieldOptions)(nil), - ExtensionType: (*bool)(nil), - Field: 51236, - Name: "gogoproto.embed", - Tag: "varint,51236,opt,name=embed", -} - -var E_Customtype = &proto.ExtensionDesc{ - ExtendedType: (*google_protobuf.FieldOptions)(nil), - ExtensionType: (*string)(nil), - Field: 51237, - Name: "gogoproto.customtype", - Tag: "bytes,51237,opt,name=customtype", -} - -func init() { - proto.RegisterExtension(E_Nullable) - proto.RegisterExtension(E_Embed) - proto.RegisterExtension(E_Customtype) -}