无法访问使用setuptools打包的非python文件

时间:2017-01-17 20:22:13

标签: python setuptools

我正在尝试为我的Python 3.5.2项目创建一个setup.py文件,并运行非python文件的问题。

所以这是我粗略的目录设置:

/
--/seleniumspec
  -- cli.py
  --/plugins
    -- html_reporter.py
    -- template.html
    -- junit_reporter.py
    -- template.xml

setup.py

from setuptools import setup, find_packages

setup(
    name="seleniumspec",
    version="0.1.0",
    description="A test framework written for selenium",
    keywords="selenium test testing",
    packages=find_packages(exclude=['dist', 'output', 'seleniumspec.egg-info', 'specs']),
    install_requires=["selenium", 'Jinja2'],
    entry_points={
        'console_scripts': [
            'seleniumspec=seleniumspec:cli.main'
        ]
    },
    package_data={
        '': ['*template.xml', '*template.html']
    }
)

我的MANIFEST.in文件:

include *template.html
include *template.xml

JUnit记者了解更多背景信息:

import os
import codecs
from typing import cast
import pkgutil
import jinja2
from seleniumspec.plugin import *
from seleniumspec.runner import Runner


def render_file_template(path, context):
    """
    Render jinja2 template from file on disk
    :param path:
    :param context:
    :return:
    """
    path, filename = os.path.split(path)
    return jinja2.Environment(
        loader=jinja2.FileSystemLoader(path or './')
    ).get_template(filename).render(context)


class JUnitReporterPlugin(Plugin):
    """
    Prints run information/results to junit report
    """

    config_section = "junit_reporter"

    def runner_stop(self, event: RunnerStopPluginEvent):
        runner = cast(Runner, event.runner)
        run_specs = runner.run_specs
        failed_results = runner.failed_results
        results = runner.results

        results_path = runner.config.get('results_path', '')
        template_path = self.config.get('template_path', './seleniumspec/plugins/junit_template.xml')
        report_path = self.config.get('report_path', 'junit.xml')
        full_report_path = os.path.join('.', results_path, report_path)

        junit_report = render_file_template(template_path, {
            'run_specs': run_specs,
            'results': results,
            'failed_results': failed_results
        })

        with codecs.open(full_report_path, 'w', 'utf-8') as f:
            f.write(junit_report)

当我在seleniumspec项目目录中运行它时,一切正常。当我将seleniumspec导入另一个项目时,它会抱怨找不到template.xml。我检查了我的venv site-package并确认该文件已被复制为sdist

的一部分

任何人都可以指出我缺少的东西吗?

0 个答案:

没有答案