text stringlengths 0 601k |
|---|
let ( ) = if not ! Sys . interactive then Pyml_tests_common . main ( ) |
let use_version = ref ( None , None ) None |
type status = | Passed | Failed of string | Disabled of string |
let tests = Queue . create ( ) |
let add_test ~ title f = Queue . add ( title , f ) f tests |
let failed = ref false |
let launch_test ( title , f ) f = Printf . printf " Test ' % s ' . . . " %! title ; try match f ( ) with Passed -> Printf . printf " passed \ n " %! | Failed reason -> Printf . printf " failed : % s \ n " %! reason ; failed := true | Disabled reason -> Printf . printf " disabled : % s \ n " %! reason with Py . E ( _ , ... |
let rec launch_tests ( ) = match try Some ( Queue . pop tests ) tests with Queue . Empty -> None with None -> ( ) | Some test -> launch_test test ; launch_tests ( ) |
let enable_only_on_unix f arg = if Sys . os_type = " Unix " then f arg else Disabled " only on Unix " |
let show_environment_variable envvar = try Printf . eprintf " % s =% s \ n " envvar ( Sys . getenv envvar ) envvar with Not_found -> Printf . eprintf " % s not set \ n " envvar |
let main ( ) = let library_name , version , minor = match Sys . argv with [ | _ ] | -> None , None , None | [ | _ ; version ] | -> begin match String . length version with 1 -> None , Some ( int_of_string version ) version , None | 3 when version [ . 1 ] 1 = ' . ' -> None , Some ( int_of_string ( String . sub version 0... |
let position ~ line ~ column = { Ast . Location . line ; column } |
let location ~ start ~ stop = { Ast . Location . start ; stop } |
let identifier x = x |
let expression_context = PyreAst . TaglessFinal . ExpressionContext . make ~ load ( ) : ~ store ( ) : ~ del ( ) : ( ) |
let constant = let open Ast . Expression in let integer i = Constant . Integer i in let big_integer _ = Constant . Integer Int . max_value in let float_ f = Constant . Float f in let complex f = Constant . Complex f in let string_ s = Constant . String ( StringLiteral . create s ) in let byte_string s = Constant . Stri... |
let boolean_operator = let open Ast . Expression in PyreAst . TaglessFinal . BooleanOperator . make ~ and_ : BooleanOperator . And ~ or_ : BooleanOperator . Or ( ) |
let binary_operator = PyreAst . TaglessFinal . BinaryOperator . make ~ add " : add " ~ sub " : sub " ~ mult " : mul " ~ matmult " : matmul " ~ div " : truediv " ~ mod_ " : mod " ~ pow " : pow " ~ lshift " : lshift " ~ rshift " : rshift " ~ bitor " : or " ~ bitxor " : xor " ~ bitand " : and " ~ floordiv " : floordiv " (... |
let unary_operator = let open Ast . Expression in PyreAst . TaglessFinal . UnaryOperator . make ~ invert : UnaryOperator . Invert ~ not_ : UnaryOperator . Not ~ uadd : UnaryOperator . Positive ~ usub : UnaryOperator . Negative ( ) |
let comparison_operator = let open Ast . Expression in PyreAst . TaglessFinal . ComparisonOperator . make ~ eq : ComparisonOperator . Equals ~ noteq : ComparisonOperator . NotEquals ~ lt : ComparisonOperator . LessThan ~ lte : ComparisonOperator . LessThanOrEquals ~ gt : ComparisonOperator . GreaterThan ~ gte : Compari... |
let comprehension ~ target ~ iter ~ ifs ~ is_async = let open Ast . Expression in let check_assignment_expression expression = let mapper = let open Ast . Location in let map_walrus_operator ~ mapper : _ ~ location { : start = { line ; column } ; stop = { line = end_line ; column = end_column } } _ = raise ( InternalEr... |
module KeywordArgument = struct type t = { location : Ast . Location . t ; name : Ast . Identifier . t option ; value : Ast . Expression . t ; } end |
let keyword ~ location ~ arg ~ value = { KeywordArgument . location ; name = arg ; value } |
let convert_positional_argument value = { Ast . Expression . Call . Argument . name = None ; value } |
let convert_keyword_argument { KeywordArgument . location ; name ; value } = let open Ast . Expression in let module Node = Ast . Node in match name with | None -> { Call . Argument . name = None ; value = Expression . Starred ( Starred . Twice value ) |> Node . create ~ location ; } | Some keyword_name -> { Call . Arg... |
module SingleParameter = struct type t = { location : Ast . Location . t ; identifier : Ast . Identifier . t ; annotation : Ast . Expression . t option ; } end |
let argument ~ location ~ identifier ~ annotation ~ type_comment = let annotation = match annotation with | Some _ -> annotation | None -> ( match type_comment with | None -> None | Some comment -> let comment_annotation = Ast . Expression . ( Expression . Constant ( Constant . String { StringLiteral . kind = String ; ... |
let arguments ~ posonlyargs ~ args ~ vararg ~ kwonlyargs ~ kw_defaults ~ kwarg ~ defaults = let open Ast . Expression in let module Node = Ast . Node in let to_parameter ( { SingleParameter . location ; identifier ; annotation } , default_value ) = { Parameter . name = identifier ; value = default_value ; annotation } ... |
let expression = let open Ast . Expression in let module Node = Ast . Node in let bool_op ~ location ~ op ~ values = match values with | [ ] -> let default_value = match op with | BooleanOperator . And -> Constant . True | BooleanOperator . Or -> Constant . False in Expression . Constant default_value |> Node . create ... |
module FunctionSignature = struct type t = { parameter_annotations : Ast . Expression . t list ; return_annotation : Ast . Expression . t ; } end |
module StatementContext = struct type t = { parse_function_signature : string -> ( FunctionSignature . t , Error . t ) Result . t ; parent : Ast . Identifier . t option ; } end |
let build_statements ~ context statement_builders = let build_statement builder = builder ~ context in List . concat ( List . map statement_builders ~ f : build_statement ) |
let with_item ~ context_expr ~ optional_vars = context_expr , optional_vars |
let import_alias ~ location ~ name ~ asname = let open Ast in Node . create ~ location { Statement . Import . name = Reference . create name ; alias = asname } |
let exception_handler ~ location : _ ~ type_ ~ name ~ body ~ context = { Ast . Statement . Try . Handler . kind = type_ ; name ; body = build_statements ~ context body } |
let build_exception_handlers ~ context exception_handler_builders = let build_exception_handler builder = builder ~ context in List . map exception_handler_builders ~ f : build_exception_handler |
let match_case ~ pattern ~ guard ~ body ~ context = { Ast . Statement . Match . Case . pattern ; guard ; body = build_statements ~ context body } |
let build_match_cases ~ context match_cases = let build_match_case builder = builder ~ context in List . map match_cases ~ f : build_match_case |
let pattern = let open Ast . Expression in let open Ast . Statement in let module Node = Ast . Node in let match_value ~ location ~ value = Match . Pattern . MatchValue value |> Node . create ~ location in let match_singleton ~ location ~ value = Match . Pattern . MatchSingleton value |> Node . create ~ location in let... |
let create_assign ~ location ~ target ~ annotation ~ value ( ) = let open Ast . Expression in let open Ast . Statement in let module Node = Ast . Node in let value = let location = let open Ast . Location in { location with start = location . stop } in Option . value value ~ default ( : Expression . Constant Constant .... |
let process_function_type_comment ~ context { : StatementContext . parse_function_signature ; parent } ~ parameters ~ returns ~ comment_location = function | None -> Result . Ok ( parameters , returns ) | Some type_comment -> ( match parse_function_signature type_comment with | Result . Error _ -> Result . Error " Synt... |
let statement = let open Ast . Expression in let open Ast . Statement in let module Node = Ast . Node in let create_function_definition ~ location ~ async ~ name ~ args ~ body ~ decorator_list ~ returns ~ type_comment ~ context ( { : StatementContext . parent ; _ } as context ) = let body = build_statements ~ context {... |
let type_ignore ~ lineno : _ ~ tag : _ = ( ) |
let module_ ~ body ~ type_ignores : _ ~ context = build_statements ~ context body |
let function_type ~ argtypes ~ returns = { FunctionSignature . parameter_annotations = argtypes ; return_annotation = returns } |
let specification = PyreAst . TaglessFinal . make ~ argument ~ arguments ~ binary_operator ~ boolean_operator ~ comparison_operator ~ comprehension ~ constant ~ exception_handler ~ expression ~ expression_context ~ function_type ~ identifier ~ import_alias ~ keyword ~ location ~ match_case ~ module_ ~ pattern ~ positio... |
let with_context ? on_failure = PyreAst . Parser . with_context ? on_init_failure : on_failure |
let parse_module ? enable_type_comment ~ context text = try let open Result in let parse_function_signature text = PyreAst . Parser . TaglessFinal . parse_function_type ~ context ~ spec : specification text in PyreAst . Parser . TaglessFinal . parse_module ? enable_type_comment ~ context ~ spec : specification text >>=... |
let parse_module_exn ? enable_type_comment ~ context text = match parse_module ? enable_type_comment ~ context text with | Result . Ok statements -> statements | Result . Error error -> raise ( Exception error ) |
let parse_expression ~ context text = try PyreAst . Parser . TaglessFinal . parse_expression ~ context ~ spec : specification text with | InternalError error -> Result . Error error |
type path = string [ @@ deriving compare , show , sexp , hash ] |
module AbsolutePath = struct type t = path [ @@ deriving compare , show , sexp , hash ] end |
module RelativePath = struct type t = { root : path ; relative : path ; } [ @@ deriving compare , show , sexp , hash ] let relative { relative ; _ } = relative end |
type t = | Absolute of AbsolutePath . t | Relative of RelativePath . t |
let absolute = function | Absolute path -> path | Relative { root ; relative } -> root ^/ relative |
let create_absolute ( ? follow_symbolic_links = false ) path = if follow_symbolic_links then Absolute ( Filename . realpath path ) else Absolute path |
let create_relative ~ root ~ relative = let root = let root = absolute root in if not ( String . is_suffix ~ suffix " " :/ root ) then root ^ " " / else root in let relative = String . chop_prefix ~ prefix : root relative |> Option . value ~ default : relative in Relative { root ; relative } |
let to_yojson path = ` String ( show path ) |
let equal left right = String . equal ( absolute left ) ( absolute right ) |
let compare left right = String . compare ( absolute left ) ( absolute right ) |
let pp format path = Format . fprintf format " % s " ( absolute path ) |
let get_directory path = absolute path |> Filename . dirname |> create_absolute |
let create_directory_recursively ? permission path = let rec do_create = function | path when not ( Caml . Sys . file_exists path ) -> ( match do_create ( Filename . dirname path ) with | Result . Error _ as error -> error | Result . Ok ( ) -> Unix . mkdir path ? perm : permission ; Result . Ok ( ) ) | path when Caml .... |
let ensure_parent_directory_exists ? permission path = create_directory_recursively ? permission ( get_directory path ) |
let get_relative_to_root ~ root ~ path = let root = let root = absolute root in if not ( String . is_suffix ~ suffix " " :/ root ) then root ^ " " / else root in String . chop_prefix ~ prefix : root ( absolute path ) |
let current_working_directory ( ) = create_absolute ( Sys . getcwd ( ) ) |
let append path ~ element = match path with | Absolute path -> Absolute ( path ^/ element ) | Relative { root ; relative } -> let relative = match relative with | " " -> element | _ -> relative ^/ element in Relative { root ; relative } |
let is_directory path = absolute path |> fun path -> match Sys . is_directory path with | ` Yes -> true | ` No | ` Unknown -> false |
let get_suffix_path = function | Absolute path -> path | Relative { relative ; _ } -> relative |
let is_path_python_stub path = String . is_suffix ~ suffix " . : pyi " path |
let is_path_python_init path = String . is_suffix ~ suffix " : __init__ . pyi " path || String . is_suffix ~ suffix " : __init__ . py " path |
let file_exists path = absolute path |> fun path -> match Sys . file_exists path with | ` Yes -> true | ` No | ` Unknown -> false |
let last path = let absolute = absolute path in String . split ~ on ' ' :/ absolute |> List . last |> Option . value ~ default : absolute |
let follow_symbolic_link path = try absolute path |> create_absolute ~ follow_symbolic_links : true |> Option . some with | Unix . Unix_error _ -> None |
let read_directory_ordered path = let entries = Core . Sys . readdir path in Array . sort ~ compare : String . compare entries ; entries |
let list ( ? file_filter = fun _ -> true ) ( ? directory_filter = fun _ -> true ) ~ root ( ) = let rec list sofar path = match Core . Sys . is_directory path with | ` Yes -> if directory_filter path then ( match read_directory_ordered path with | entries -> let collect sofar entry = list sofar ( path ^/ entry ) in Arra... |
let directory_contains ~ directory path = let path = absolute path in let directory = absolute directory in String . is_prefix ~ prefix ( : directory ^ " " ) / path |
module FileType = struct type t = | File | Directory end |
let search_upwards ~ target ~ target_type ~ root = let exists = match target_type with | FileType . File -> Sys . is_file | Directory -> Sys . is_directory in let rec directory_has_target directory = match exists ( directory ^/ target ) with | ` Yes -> Some ( create_absolute directory ) | _ when [ % compare . equal : p... |
let remove path = try Sys . remove ( absolute path ) with | Sys_error _ -> Log . debug " Unable to remove file at % a " pp path |
let remove_if_exists path = let path = absolute path in match Sys . file_exists path with | ` Yes -> Core . Unix . remove path | ` No | ` Unknown -> ( ) |
let remove_recursively path = let rec do_remove path = try let stats = Unix . lstat path in match stats . Unix . st_kind with | Unix . S_DIR -> let contents = Caml . Sys . readdir path in List . iter ( Array . to_list contents ) ~ f ( : fun name -> let name = Filename . concat path name in do_remove name ) ; Unix . rmd... |
let remove_contents_of_directory path = try Caml . Sys . readdir ( absolute path ) |> Array . iter ~ f ( : fun relative -> remove_recursively ( create_relative ~ root : path ~ relative ) ) ; Result . Ok ( ) with | Sys_error message -> Result . Error message |
module Map = Map . Make ( struct type nonrec t = t let compare left right = String . compare ( absolute left ) ( absolute right ) let sexp_of_t = sexp_of_t let t_of_sexp = t_of_sexp end ) |
module Set = Set . Make ( struct type nonrec t = t let compare left right = String . compare ( absolute left ) ( absolute right ) let sexp_of_t = sexp_of_t let t_of_sexp = t_of_sexp end ) |
let with_suffix path ~ suffix = match path with | Absolute prefix -> Absolute ( prefix ^ suffix ) | Relative { root ; relative } -> Relative { root ; relative = relative ^ suffix } |
let get_matching_files_recursively ~ suffix ~ paths = let rec expand path = if is_directory path then let expand_directory_entry entry = let path = append path ~ element : entry in if is_directory path then expand path else if String . is_suffix ~ suffix entry then [ path ] else [ ] in Sys . readdir ( absolute path ) |... |
let set_green cr = Cairo . set_source_rgb cr 0 . 0 . 7 0 . |
let set_darkgreen cr = Cairo . set_source_rgb cr 0 . 0 . 5 0 . |
let set_burlywood cr = Cairo . set_source_rgb cr 0 . 87 0 . 72 0 . 53 |
let transform_data m = function | MOVE_TO ( x , y ) -> let x , y = Matrix . transform_point m x y in MOVE_TO ( x , y ) | LINE_TO ( x , y ) -> let x , y = Matrix . transform_point m x y in LINE_TO ( x , y ) | CURVE_TO ( x1 , y1 , x2 , y2 , x3 , y3 ) -> let x1 , y1 = Matrix . transform_point m x1 y1 and x2 , y2 = Matrix ... |
let transform m path = Array . map ( transform_data m ) path |
let m1 = Matrix . ( let m = init_translate 0 . 1 . in scale m ( 4 . . / 5 . ) ( 4 . . / 5 . ) ; rotate m ( 0 . 5 . * pi . - asin ( 4 . . / 5 . ) ) ; m ) |
let m2 = Matrix . ( let m = init_translate 1 . 1 . in scale m ( 3 . . / 5 . ) ( 3 . . / 5 . ) ; rotate m ( - 0 . 5 . * pi . + asin ( 3 . . / 5 . ) ) ; translate m ( - 1 . ) 0 . ; m ) |
let rec tree cr n square = if n = 0 then ( set_darkgreen cr ; Path . append cr ( Path . of_array square ) ; fill cr ; ) else ( set_burlywood cr ; Path . append cr ( Path . of_array square ) ; fill_preserve cr ; set_green cr ; stroke cr ; let m = Array . append ( transform m1 square ) ( transform m2 square ) in tree cr ... |
let ( ) = let surface = Cairo . PDF . create " pythagoras_tree . pdf " ~ w : 300 . ~ h : 250 . in let cr = Cairo . create surface in translate cr 150 . 220 . ; scale cr 45 . ( - 45 . ) ; set_line_width cr 0 . 01 ; let square = [ | MOVE_TO ( 0 . , 0 . ) ; LINE_TO ( 1 . , 0 . ) ; LINE_TO ( 1 . , 1 . ) ; LINE_TO ( 0 . , 1... |
type t = | Block of t list | Line of string |
let inline_defaults = { | " " " Called from each server dispatcher to return a successful response in case no exceptions were thrown . " " " return { " Status " : " Success " , " Value " : result } result " " " Defines the behavior of the generated CLI code when arguments are passed as JSON and the dispatched function ... |
let compat_block = [ Line " if sys . version_info [ version_info0 ] version_info0 > 2 " : ; Block [ Line " long = int " ; Line " unicode = str " ; Line " str = bytes " ] ; Line " " ] |
let reserved_exns = [ " Rpc_light_failure " ; " Unimplemented " ; " InternalError " ; " UnmarshalException " ; " TypeError " ; " UnknownMethod " ] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.