小编Ope*_*lex的帖子

使用python包在'<packageName>'中收到'找不到'__main__'模块

我正试图在野外发布我的第一个Python包,我成功地在PyPi上设置它并且能够做到pip install.当我尝试通过命令行($ python etlTest)运行包时,我收到以下错误:

/usr/bin/python: can't find '__main__' module in 'etlTest'

当我直接从我的IDE运行代码时,它没有问题.我正在使用Python 2.7并__init__.py在需要时使用脚本.为了让这个工作,我需要做什么?

python command-line packaging python-2.7

13
推荐指数
3
解决办法
4万
查看次数

如何在XSLT中将字符串格式化为Pascal案例?

我正在尝试在XSLT中格式化字符串,这些字符串需要处于pascal情况下才能正确地用于我正在使用的应用程序.

例如:

this_text将成为ThisText
this_long_text将成为ThisLongText

是否有可能将其设置在我可以向格式发送输入的位置,以便我不必多次重新创建格式?

string xslt pascalcasing string-formatting

10
推荐指数
2
解决办法
5492
查看次数

测试KeyError

我正在尝试编写一个单元测试,用于验证KeyError在将错误的密钥传递给字典时创建的单元测试.

引发异常的代码:

connections = SettingsManager().get_connections()
try:
    connection = connections[self.conn_name]
except Exception:
    self.log.error("Connection %s does not exist, exiting." % conn_name)
    self.log.error(sys.exc_info()[0])
    raise
Run Code Online (Sandbox Code Playgroud)

我看过并发现KeyError使用lambda的测试,但我没有太多运气.这是我到目前为止的测试,但它与实际的错误KeyError.

def test_bad_connection(self):
    #Testing to see if a non existant connection will fail gracefully.
    records = [1, 2]
    given_result = DataConnector("BadConnection").generate_data(self.table, records)
    expected_result = "BadConnection"

    self.assertRaises(KeyError, given_result[:1])
Run Code Online (Sandbox Code Playgroud)

python unit-testing keyerror

10
推荐指数
2
解决办法
6930
查看次数

将变量从 Github Action 传递到 Docker 镜像构建

我一直致力于设置 Github Actions 工作流程来构建 docker 映像。我需要将环境变量传递到图像中,以便我的 Django 项目能够正确运行。不幸的是,当我构建图像时,它没有收到变量的值。

我的工作流程文件的相关部分:

     - name: Build, tag, and push image to AWS ECR
    id: build-image
    env:
      ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
      IMAGE_TAG: ${{ github.sha }}
      aws_ses_access_key_id: ${{ secrets.AWS_SES_ACCESS_KEY_ID }}
      aws_ses_secret_access_key: ${{ secrets.AWS_SES_SECRET_ACCESS_KEY }}
      DATABASE_ENGINE: ${{ secrets.DATABASE_ENGINE }}
      db_host: ${{ secrets.DB_HOST }}
      db_password: ${{ secrets.DB_PASSWORD }}
      db_port: ${{ secrets.DB_PORT }}
      db_username: ${{ secrets.DB_USERNAME }}
      django_secret_key: ${{ secrets.DJANGO_SECRET_KEY }}
      fcm_server_key: ${{ secrets.FCM_SERVER_KEY }}
    run: |
      docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
      docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
      echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_ENV …
Run Code Online (Sandbox Code Playgroud)

dockerfile github-actions

9
推荐指数
1
解决办法
1万
查看次数

使用Neo4J创建族树

我在Neo4J中有一组家族树的数据,我正在尝试构建一个Cypher查询,该查询生成类似于以下内容的JSON数据集:

{Name:  "Bob",
      parents: [
          {Name:  "Roger",
             parents: [
                Name: "Robert",
                Name: "Jessica"
             ]},
          {Name:  "Susan",
             parents: [
                Name: "George",
                Name: "Susan"
             ]}
      ]}
Run Code Online (Sandbox Code Playgroud)

我的图在MEMBER节点之间具有PARENT关系(即MATCH(p.Member) - [:PARENT] - >(c.Member)).我cypherneo4j cypher嵌套收集中发现了嵌套的has_many关系,最终将所有父节点组合在一起,用于我正在搜索的主子节点.

根据反馈添加一些清晰度:

每个成员都有唯一的标识符.工会目前都与父母关系有关.所有内容都被编入索引,以便性能不会受到影响.当我运行查询以返回节点图时,我得到了我期望的结果.我正在尝试返回一个输出,我可以将其用于D3的可视化目的.理想情况下,这将通过Cypher查询完成,因为我正在使用API​​从正在构建的前端访问neo4j.

添加示例查询:

MATCH (p:Person)-[:PARENT*1..5]->(c:Person)
WHERE c.FirstName = 'Bob'
RETURN p.FirstName, c.FirstName
Run Code Online (Sandbox Code Playgroud)

此查询返回五代的每个父级列表,但不是显示层次结构,而是将"Bob"列为每个关系的子级.是否有Cypher查询至少会显示数据中的每个关系?我可以根据需要格式化它...

json neo4j

6
推荐指数
2
解决办法
6847
查看次数

如何防止 moto 测试抛出 NoSuchBucketError?

我正在尝试编写一个测试来验证 register_extracts_by_location 是否能够从 s3 存储桶读取并获取文件。在编写 moto 模拟测试时,我收到一条错误,指出存储桶不存在。

这是 register_extracts_by_location 方法:

class ProcessTracker:
    # ... other methods and init here.

    def register_extracts_by_location(self, location_path, location_name=None):
        """
        For a given location, find all files and attempt to register them.
        :param location_name: Name of the location
        :param location_path: Path of the location
        :return:
        """
        location = LocationTracker(location_path=location_path, location_name=location_name)

        if location.location_type.location_type_name == "s3":
            s3 = boto3.resource("s3")

            path = location.location_path

            if path.startswith("s3://"):
                path = path[len("s3://")]

            bucket = s3.Bucket(path)

            for file in bucket.objects.all():
                ExtractTracker(process_run=self
                               , filename=file
                               , …
Run Code Online (Sandbox Code Playgroud)

python unit-testing moto

5
推荐指数
1
解决办法
2848
查看次数

确定SPARQL中的日期时间

我有一个图表,我试图按周计算过滤报告.例如,我希望找到周二发生的所有实例.有没有办法将日期时间字段格式化为星期几,或者直接在日期时间字段中按星期几来过滤?

datetime sparql

2
推荐指数
2
解决办法
602
查看次数