Skip to content

convert python files to vs code snippets [.code-snippets]

License

Notifications You must be signed in to change notification settings

azerv1/pythonsnip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What it Does

This tool converts python source code or .py files to VS code snippets

Usage

from pythonsnip.pythonsnip import PythonSnip

if __name__ == "__main__":

    example_file = "examples/example.py"
    with open(example_file, "r") as f:
        source_code = f.read()
    parser = PythonSnip(source_code)
    parser.get_snippets().to_json_snippet(filename="examples/example.json")

From:

from dataclasses import dataclass


@dataclass
class Person:
    """random example class"""

    name: str
    age: int
    email: str

    def years_until(self, target_age: int) -> int:
        """Returns the number of years until the person reaches the target age."""
        if target_age <= self.age:
            return 0  # No years left to reach that age
        return target_age - self.age
        return target_age - self.age

To:

{
  "Person": {
    "prefix": "Person",
    "body": [
      "\"@dataclass\",",
      "\"class Person:\",",
      "\"    \"\"\"random example class\"\"\"\",",
      "\"    name: str\",",
      "\"    age: int\",",
      "\"    email: str\",",
      "\"\",",
      "\"    def years_until(self, target_age: int) -> int:\",",
      "\"        \"\"\"Returns the number of years until the person reaches the target age.\"\"\"\",",
      "\"        if target_age <= self.age:\",",
      "\"            return 0\",",
      "\"        return target_age - self.age\",",
      "\"        return target_age - self.age\""
    ],
    "description": "random example class"
  }
}

About

convert python files to vs code snippets [.code-snippets]

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages