input: Write a function to create an Environment object that can execute and analyze Python code. The Environment includes predefined global variables and functions, as well as the ability to add additional global variables. The Environment can execute Python code and analyze it for variable usage and imports. It also includes a stdout object to capture and display output from executed code. The function should initialize the Environment with a given path and should include methods to fixup globals and execute or analyze code.
  
  `def create_environment(path):`
  
  `assert create_environment("/path/to/directory").execute("test.py", "print('Hello, World!')")["emitted"][0]["parts"][0]["str"] == "Hello, World!"`
  `assert create_environment("/path/to/directory").analyze("test.py", "x = 10")["variables_set"] == ["x"]`
  `assert create_environment("/path/to/directory").analyze("test.py", "from math import sqrt")["imports"] == ["sqrt"]`
  `assert create_environment("/path/to/directory").analyze("test.py", "import os")["imports"] == ["os"]`
  `assert create_environment("/path/to/directory").execute("test.py", "x = 5 + 5")["defines"]["x"]["json"] == "10"`
output: 
  class Environment:
      def __init__(self, path):
          self.path = path
          self.globals = {}
          self.stdout = []
  
      def fixup_globals(self, additional_globals):
          self.globals.update(additional_globals)
  
      def execute(self, filename, code):
          self.stdout.clear()
          old_stdout = sys.stdout
          sys.stdout = StringIO()
          try:
              exec(code, self.globals)
              output = sys.stdout.getvalue()
              self.stdout.append({"parts": [{"str": output}]})
              defines = {k: {"json": str(v)} for k, v in self.globals.items() if k not in globals()}
              return {"emitted": self.stdout, "defines": defines}
          finally:
              sys.stdout = old_stdout
  
      def analyze(self, filename, code):
          tree = ast.parse(code)
          variables_set = [node.targets[0].id for node in ast.walk(tree) if isinstance(node, ast.Assign)]
          imports = []
          for node in ast.walk(tree):
              if isinstance(node, ast.Import):
                  imports.extend([alias.name for alias in node.names])
              elif isinstance(node, ast.ImportFrom):
                  imports.extend([alias.name for alias in node.names])
          return {"variables_set": variables_set, "imports": imports}
  
  def create_environment(path):
      return Environment(path)
  