Commit 17ebac85 authored by Stefan Behnel's avatar Stefan Behnel

another little Pyrex merge that extracts FQ module names from source file names

parent f6a3f4c6
...@@ -190,7 +190,14 @@ class Context: ...@@ -190,7 +190,14 @@ class Context:
def find_cimported_module_names(self, source_path): def find_cimported_module_names(self, source_path):
return [ name for kind, name in self.read_dependency_file(source_path) return [ name for kind, name in self.read_dependency_file(source_path)
if kind == "cimport" ] if kind == "cimport" ]
def is_package_dir(self, dir_path):
# Return true if the given directory is a package directory.
for filename in ("__init__.py", "__init__.pyx"):
path = os.path.join(dir_path, filename)
if os.path.exists(path):
return 1
def read_dependency_file(self, source_path): def read_dependency_file(self, source_path):
dep_path = replace_suffix(source_path, ".dep") dep_path = replace_suffix(source_path, ".dep")
if os.path.exists(dep_path): if os.path.exists(dep_path):
...@@ -234,10 +241,23 @@ class Context: ...@@ -234,10 +241,23 @@ class Context:
return tree return tree
def extract_module_name(self, path, options): def extract_module_name(self, path, options):
# Get the module name out of a source file pathname. # Find fully_qualified module name from the full pathname
_, tail = os.path.split(path) # of a source file.
name, _ = os.path.splitext(tail) dir, filename = os.path.split(path)
return name module_name, _ = os.path.splitext(filename)
if "." in module_name:
return module_name
if module_name == "__init__":
dir, module_name = os.path.split(dir)
names = [module_name]
while self.is_package_dir(dir):
parent, package_name = os.path.split(dir)
if parent == dir:
break
names.append(package_name)
dir = parent
names.reverse()
return ".".join(names)
def compile(self, source, options = None, full_module_name = None): def compile(self, source, options = None, full_module_name = None):
# Compile a Pyrex implementation file in this context # Compile a Pyrex implementation file in this context
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment