diff --git a/.appveyor.yml b/.appveyor.yml index 7305778..7e50cde 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,15 +1,13 @@ build: false platform: - # TODO - get 64 bit build working - # - x64 - x86 install: - git submodule update --init --recursive - - IF "%PLATFORM%" == "x86" set PYTHON=C:\Python37 - - IF "%PLATFORM%" == "x64" set PYTHON=C:\Python37-x64 + - IF "%PLATFORM%" == "x86" set PATH=C:\Python37;%PATH% + - IF "%PLATFORM%" == "x64" set PATH=C:\Python37-x64;%PATH% test_script: - script\fetch-fixtures.cmd - - "%PYTHON%\\python.exe setup.py test" + - python.exe setup.py --quiet test diff --git a/setup.py b/setup.py index 4492236..21f1b2c 100644 --- a/setup.py +++ b/setup.py @@ -1,47 +1,48 @@ """ Py-Tree-sitter """ +import platform from setuptools import setup, Extension setup( name = "tree_sitter", version = "0.0.4", maintainer = "Max Brunsfeld", maintainer_email = "maxbrunsfeld@gmail.com", author = "Max Brunsfeld", author_email = "maxbrunsfeld@gmail.com", url = "https://github.com/tree-sitter/py-tree-sitter", license = "MIT", platforms = ["any"], python_requires = ">=3.3", description = "Python bindings to the Tree-sitter parsing library", classifiers = [ "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Compilers", "Topic :: Text Processing :: Linguistic", ], packages = ['tree_sitter'], ext_modules = [ Extension( "tree_sitter_binding", [ "tree_sitter/core/lib/src/lib.c", "tree_sitter/binding.c", ], include_dirs = [ "tree_sitter/core/lib/include", "tree_sitter/core/lib/utf8proc", ], - extra_compile_args = [ - "-std=c99", - ], + extra_compile_args = ( + ['-std=c99'] if platform.system() != 'Windows' else None + ) ) ], project_urls = { 'Source': 'https://github.com/tree-sitter/py-tree-sitter', 'Documentation': 'http://initd.org/psycopg/docs/', } ) diff --git a/tree_sitter/__init__.py b/tree_sitter/__init__.py index 1749e04..3503121 100644 --- a/tree_sitter/__init__.py +++ b/tree_sitter/__init__.py @@ -1,75 +1,79 @@ from ctypes import cdll, c_void_p from ctypes.util import find_library from distutils.ccompiler import new_compiler from tempfile import TemporaryDirectory from tree_sitter_binding import Parser import os.path as path +import platform class Language: def build_library(output_path, repo_paths): """ Build a dynamic library at the given path, based on the parser repositories at the given paths. Returns `True` if the dynamic library was compiled and `False` if the library already existed and was modified more recently than any of the source files. """ output_mtime = 0 if path.exists(output_path): output_mtime = path.getmtime(output_path) if len(repo_paths) == 0: raise ValueError('Must provide at least one language folder') cpp = False source_paths = [] source_mtimes = [path.getmtime(__file__)] for repo_path in repo_paths: src_path = path.join(repo_path, 'src') source_paths.append(path.join(src_path, "parser.c")) source_mtimes.append(path.getmtime(source_paths[-1])) if path.exists(path.join(src_path, "scanner.cc")): cpp = True source_paths.append(path.join(src_path, "scanner.cc")) source_mtimes.append(path.getmtime(source_paths[-1])) elif path.exists(path.join(src_path, "scanner.c")): source_paths.append(path.join(src_path, "scanner.c")) source_mtimes.append(path.getmtime(source_paths[-1])) compiler = new_compiler() if cpp: if find_library('c++'): compiler.add_library('c++') elif find_library('stdc++'): compiler.add_library('stdc++') if max(source_mtimes) > output_mtime: with TemporaryDirectory(suffix = 'tree_sitter_language') as dir: object_paths = [] for source_path in source_paths: - flags = ['-fPIC'] - if source_path.endswith('.c'): - flags.append('-std=c99') + if platform.system() == 'Windows': + flags = None + else: + flags = ['-fPIC'] + if source_path.endswith('.c'): + flags.append('-std=c99') object_paths.append(compiler.compile( [source_path], output_dir = dir, include_dirs = [path.dirname(source_path)], extra_preargs = flags )[0]) compiler.link_shared_object(object_paths, output_path) return True else: return False def __init__(self, library_path, name): """ Load the language with the given name from the dynamic library at the given path. """ self.name = name self.lib = cdll.LoadLibrary(library_path) language_function = getattr(self.lib, "tree_sitter_%s" % name) language_function.restype = c_void_p self.language_id = language_function()