Beispiel #1
0
    def generate(self):
        """Generate the client with default options. Per client options should be set in
        ./<CLIENT_FOLDER>/openapi_config.json

        The code generation preliminary steps (some are manual (m-) at the moment):
         -- Create/Clean an output folder
         -- Init the git repository
         -- Copy static portion from the source
         -- Add and commit
         -- Run openapi-generator command
         -- m- Review all changed files (git ls-files -m) by running 'git add -p'. Don't forget to git checkout at the end
         -- m- go build -v ./...
         -- m- Run go mod tidy
         ----- The rest of git commands are in publish()
        """

        try:
            if self.source_path.exists():
                shutil.rmtree(self.source_path)
            shutil.copytree(str(self.root_path), str(self.source_path), ignore=shutil.ignore_patterns('*.json'))
            self.command_runner.cwd = self.source_path
            self.run("git init")
            self.run("git add .")
            self.run('git commit -m "Initial_commit"')
            self.run(
                f"openapi-generator-cli generate -i ./openapi.json -g {self.oas_client_name} -o {self.source_path / 'onshape'} --type-mappings DateTime=JSONTime "
                f"-c {self.root_path / 'openapi_config.json'}",
                cwd=self.root_path.parent,
            )
        except Exception:
            raise CliError(
                "Please install openapi-generator-cli by running $onshape-clients setup -tools openapi-generator-cli"
            )
Beispiel #2
0
    def publish(self):
        setup = self.root_path / "setup.py"
        dist = self.root_path / "dist"
        dist.mkdir(exist_ok=True, parents=True)

        self.run(f"python {setup} sdist bdist_wheel -d {str(dist)}", )
        result = self.run(f"twine upload {str(dist)}/*", )
        if result.returncode != 0:
            raise CliError("Error uploading client to pypi.")
        shutil.rmtree(str(dist))
Beispiel #3
0
 def get_onshape_clients_path(inner_path: Path):
     """Return the onshape-clients Path from an inner path."""
     new_path = Path(inner_path)
     while new_path.name != "onshape-clients" and new_path != Path("/"):
         new_path = new_path.absolute().parent
     if new_path.name != "onshape-clients":
         raise CliError(
             f"Most likely calling from the wrong location. Should be in a directory named 'onshape-clients' but "
             f"instead in '{inner_path}'"
         )
     return new_path
Beispiel #4
0
 def set_version_in_source(
         self,
         version="0.0.0",
         file_path_to_version_identifier=None,
         regex_for_version_number=None,
 ):
     """Set the version for clients that include the version number in their source files.
     :param version: String The version to update to: ex "1.1.2"
     :param file_path_to_version_identifier: Path ex "setup.py"
     :param regex_for_version_number: String ex r'version=".*"'"""
     if not all(
             [version, file_path_to_version_identifier, regex_for_version_number]
     ):
         raise CliError("Must specify all parameters.")
     if not version or not re.match(self.version_regex, version):
         raise CliError(
             f"Version specified: {version} does not match regex {self.version_regex}."
         )
     f = file_path_to_version_identifier.open().read()
     result = re.sub(regex_for_version_number, version, f)
     file_path_to_version_identifier.open(mode="w").write(result)
Beispiel #5
0
 def generate(self):
     """Generate the client with default options. Per client options should be set in
     ./<CLIENT_FOLDER>/openapi_config.json"""
     try:
         self.run(
             f"openapi-generator-cli generate -i ./openapi.json -g {self.oas_client_name} -o {self.source_path} "
             f"-c {self.root_path / 'openapi_config.json'}",
             cwd=self.root_path.parent,
         )
     except Exception:
         raise CliError(
             "Please install openapi-generator-cli by running $onshape-clients setup -tools openapi-generator-cli"
         )
Beispiel #6
0
    def publish(self):
        """Copy the contents of the GO package to a new Github repo to get distributed to the broader GO community.

        TODO Make sure we get a correct version: probably from openapi_config.json
        """
        dot_git = self.source_path / ".git"
        if not dot_git.exists():
            CliError("Trying to publish incomplete repo ...")
        self.command_runner.cwd = self.source_path
        self.run("git add .")
        self.run(f'git commit -m "v{self.version_to_publish}"')
        self.run(f"git tag v{self.version_to_publish}")
        self.run(f"git remote add origin https://{os.environ.get('GH_TOKEN')}@github.com/onshape-public/go-client.git", print_divider=False)
        self.run("git push --set-upstream origin master -f --tags")
        return
Beispiel #7
0
 def test(self, marker=None):
     result = self.run(f"pipenv run pytest {f'-m {marker}' if marker else ''} -n 8")
     if result.returncode != 0:
         raise CliError("Error testing client.")