Skip to content

Commit

Permalink
Merge pull request #2134 from iamdefinitelyahuman/cli/single-entry-point
Browse files Browse the repository at this point in the history
Standalone binary preparation
  • Loading branch information
iamdefinitelyahuman authored Aug 21, 2020
2 parents 0879886 + d04b7ae commit 0dcd148
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ docs/vyper.*.rst

# vyper
vyper/vyper_git_version.txt
*.spec
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SHELL := /bin/bash
OS := $(shell uname -s | tr A-Z a-z)
VERSION := $(shell vyper --version)

ifeq (, $(shell which pip3))
pip := $(shell which pip3)
Expand Down Expand Up @@ -36,6 +38,11 @@ release: clean
twine check dist/*
#twine upload dist/*


freeze: clean
echo Generating binary...
pyinstaller --clean --onefile vyper/cli/vyper_compile.py --name vyper.$(VERSION).$(OS)

clean: clean-build clean-docs clean-pyc clean-test

clean-build:
Expand Down
9 changes: 8 additions & 1 deletion make.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ if "%1"=="test" goto :test
if "%1"=="dev-deps" goto :dev-deps
if "%1"=="lint" goto :lint
if "%1"=="docs" goto :docs
if "%1"=="freeze" goto :freeze
if "%1"=="clean" goto :clean
if "%1"=="clean-build" goto :clean-build
if "%1"=="clean-pyc" goto :clean-pyc
Expand Down Expand Up @@ -39,6 +40,12 @@ CALL docs\make html
START docs\_build\html\index.html
goto :end

:freeze
CALL :clean
for /f "delims=" %%a in ('vyper --version') do @set VERSION=%%a
pyinstaller --clean --onefile vyper/cli/vyper_compile.py --name vyper.%VERSION%.windows
goto :end

:clean
CALL :clean-build
CALL :clean-pyc
Expand All @@ -64,4 +71,4 @@ goto :end
for /r /d %%x in (htmlcov) do if exist "%%x" RMDIR /Q /S "%%x"
goto :end

:end
:end
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"mypy==0.780",
],
"docs": ["recommonmark", "sphinx>=3.0,<4.0", "sphinx_rtd_theme>=0.5,<0.6"],
"dev": ["ipython", "pre-commit", "twine"],
"dev": ["ipython", "pre-commit", "pyinstaller", "twine"],
}

extras_require["dev"] = (
Expand Down
13 changes: 13 additions & 0 deletions vyper/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
from pathlib import Path
from typing import Sequence

from vyper import ast as vy_ast
from vyper.exceptions import StructureException
from vyper.typing import InterfaceImports, SourceCode


def get_interface_file_path(base_paths: Sequence, import_path: str) -> Path:
relative_path = Path(import_path)
for path in base_paths:
file_path = path.joinpath(relative_path)
suffix = next((i for i in (".vy", ".json") if file_path.with_suffix(i).exists()), None)
if suffix:
return file_path.with_suffix(suffix)
raise FileNotFoundError(f" Cannot locate interface '{import_path}{{.vy,.json}}'")


def extract_file_interface_imports(code: SourceCode) -> InterfaceImports:
ast_tree = vy_ast.parse_to_ast(code)

Expand Down
33 changes: 20 additions & 13 deletions vyper/cli/vyper_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
import warnings
from collections import OrderedDict
from pathlib import Path
from typing import Dict, Iterable, Iterator, Sequence, Set, TypeVar
from typing import Dict, Iterable, Iterator, Set, TypeVar

import vyper
from vyper.cli.utils import extract_file_interface_imports
from vyper.cli import vyper_json
from vyper.cli.utils import (
extract_file_interface_imports,
get_interface_file_path,
)
from vyper.opcodes import DEFAULT_EVM_VERSION, EVM_VERSIONS
from vyper.parser import parser_utils
from vyper.settings import VYPER_TRACEBACK_LIMIT
Expand Down Expand Up @@ -50,9 +54,13 @@ def _parse_cli_args():


def _parse_args(argv):

warnings.simplefilter("always")

if "--standard-json" in argv:
argv.remove("--standard-json")
vyper_json._parse_args(argv)
return

parser = argparse.ArgumentParser(
description="Pythonic Smart Contract Language for the EVM",
formatter_class=argparse.RawTextHelpFormatter,
Expand Down Expand Up @@ -81,6 +89,11 @@ def _parse_args(argv):
help="Set the traceback limit for error messages reported by the compiler",
type=int,
)
parser.add_argument(
"--standard-json",
help="Switch to standard JSON mode. Use `--standard-json -h` for available options.",
action="store_true",
)
parser.add_argument(
"-p", help="Set the root path for contract imports", default=".", dest="root_folder"
)
Expand Down Expand Up @@ -173,16 +186,6 @@ def get_interface_codes(root_path: Path, contract_sources: ContractCodes) -> Dic
return interfaces


def get_interface_file_path(base_paths: Sequence, import_path: str) -> Path:
relative_path = Path(import_path)
for path in base_paths:
file_path = path.joinpath(relative_path)
suffix = next((i for i in (".vy", ".json") if file_path.with_suffix(i).exists()), None)
if suffix:
return file_path.with_suffix(suffix)
raise FileNotFoundError(f" Cannot locate interface '{import_path}{{.vy,.json}}'")


def compile_files(
input_files: Iterable[str],
output_formats: OutputFormats,
Expand Down Expand Up @@ -229,3 +232,7 @@ def compile_files(
compiler_data["version"] = vyper.__version__

return compiler_data


if __name__ == "__main__":
_parse_args(sys.argv[1:])
6 changes: 4 additions & 2 deletions vyper/cli/vyper_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
from typing import Callable, Dict, Tuple, Union

import vyper
from vyper.cli.utils import extract_file_interface_imports
from vyper.cli.vyper_compile import get_interface_file_path
from vyper.cli.utils import (
extract_file_interface_imports,
get_interface_file_path,
)
from vyper.exceptions import JSONError
from vyper.opcodes import DEFAULT_EVM_VERSION, EVM_VERSIONS
from vyper.typing import ContractCodes, ContractPath
Expand Down

0 comments on commit 0dcd148

Please sign in to comment.