Options
All
  • Public
  • Public/Protected
  • All
Menu

Class PythonParser

Parser to be used on a directory with Python source code and (optionally) a requirements.txt file. If no requirements.txt file exists then the Parser will attempt to read requirements from the Python source code.

Hierarchy

Index

Constructors

constructor

Properties

folder

folder: string

The directory to scan for relevant files

Protected Readonly urlFetcher

urlFetcher: UrlFetcher

The instance of IUrlFetcher to fetch URLs

Methods

Private createPackage

  • Convert a PythonRequirement into a SoftwarePackage by augmenting with metadata from PyPI

    Parameters

    Returns Promise<SoftwarePackage>

exists

  • exists(subpath: string): boolean
  • Does a path exist within the project folder?

    Parameters

    • subpath: string

      The path within the folder

    Returns boolean

fetch

  • fetch(url: string, options?: any): Promise<any>
  • Fetch content from a URL

    Parameters

    • url: string

      The URL to fetch

    • Default value options: any = { responseType: 'json' }

      Request options

    Returns Promise<any>

findImports

  • findImports(): Array<string>
  • Parse Python source files are find all imports (including system imports).

    Returns Array<string>

generateRequirementsFromSource

glob

  • glob(pattern: string | Array<string>): Array<string>
  • Get a list of paths that match a pattern in the project folder.

    Parameters

    • pattern: string | Array<string>

      The glob pattern

    Returns Array<string>

parse

  • parse(): Promise<SoftwarePackage | null>

parseRequirementsFile

read

  • read(subpath: string): string
  • Read a file within the project folder

    Parameters

    • subpath: string

      The path within the folder

    Returns string

readImportsInFile

  • readImportsInFile(path: string): Array<string>
  • Parse Python a single Python source file for imports.

    Parameters

    • path: string

    Returns Array<string>

write

  • write(subpath: string, content: string): void
  • Write to a file within the project folder

    Parameters

    • subpath: string

      The path within the folder

    • content: string

      The content to write to the file

    Returns void

Generated using TypeDoc