Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/_data/infiles/_helpers/local_pckages/e_vcs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# the local git repository is created on demand -- see README
/.git/

# python caches and build artifacts
__pycache__/
*.py[cod]
*.egg-info/
/build/
/dist/
22 changes: 22 additions & 0 deletions tests/_data/infiles/_helpers/local_pckages/e_vcs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# package E -- from a local VCS repository

This package is used to showcase/test dependencies that are installed or locked
from a **local VCS repository**, e.g. `git+file:///path/to/e_vcs`.

The VCS repository itself is not part of this project's source control.
It is created on demand, by running

```shell
python init_repo.py
```

The script does the following:
- if a `.git` folder exists already, it does nothing.
- otherwise, it runs `git init` in this folder, sets a fixed author and branch name,
and commits all files with a fixed date.
This way, the commit hash is reproducible on every machine.

Testbeds that depend on this package call `init_repo.py` before installing/locking.

URLs to this repository must be absolute (`git+file:///...`);
relative URLs are not supported for VCS installs by pip.
63 changes: 63 additions & 0 deletions tests/_data/infiles/_helpers/local_pckages/e_vcs/init_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This file is part of CycloneDX Python
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.

"""
Turn this folder into a local git repository with a reproducible commit -- see README.md.
"""

from os import environ
from os.path import dirname, isdir, join
from subprocess import check_call # nosec:B404
from sys import stderr

__all__ = ['main', 'repo_dir']

repo_dir = dirname(__file__)

# fixed author/committer and dates, so the commit hash is reproducible
_GIT_ENV = {
'GIT_AUTHOR_DATE': '2026-01-01T00:00:00Z',
'GIT_COMMITTER_DATE': '2026-01-01T00:00:00Z',
}
_GIT_CONFIG = (
('user.name', 'CycloneDX Python testbed'),
('user.email', 'testbed@cyclonedx.example'),
('commit.gpgsign', 'false'),
# normalize line endings on commit, so checkouts with CRLF result in the same commit hash
('core.autocrlf', 'input'),
)


def git(*args: str) -> None:
call = ('git', *args)
print('+ ', *call, file=stderr)
check_call(call, cwd=repo_dir, env={**environ, **_GIT_ENV}, shell=False) # nosec:B603 B607


def main() -> None:
if isdir(join(repo_dir, '.git')):
print('git repository exists already - skip', file=stderr)
return
git('init', '--quiet', '--initial-branch=main')
for key, value in _GIT_CONFIG:
git('config', '--local', key, value)
git('add', '--all')
git('commit', '--quiet', '--message=initial')


if __name__ == '__main__':
main()
20 changes: 20 additions & 0 deletions tests/_data/infiles/_helpers/local_pckages/e_vcs/module_e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This file is part of CycloneDX Python
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# Copyright (c) OWASP Foundation. All Rights Reserved.

"""
module E
"""
14 changes: 14 additions & 0 deletions tests/_data/infiles/_helpers/local_pckages/e_vcs/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "package-e"
version = "23.42"
description = "some package E, installed from a local VCS repository"
license = { text = "Apache-2.0" }
authors = []
requires-python = ">=3.8"

[tool.setuptools]
py-modules = ["module_e"]

[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"
5 changes: 5 additions & 0 deletions tests/_data/infiles/environment/local/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from os import name as os_name
from os.path import abspath, dirname, join
from pathlib import Path
from subprocess import check_call # nosec:B404
from sys import executable, stderr
from venv import EnvBuilder
Expand Down Expand Up @@ -50,10 +51,14 @@ def main() -> None:
with_pip=False,
).create(env_dir)

# local VCS repository -- see its README
vcs_repo_dir = join(localpackages_dir, 'e_vcs')
check_call((executable, join(vcs_repo_dir, 'init_repo.py')), shell=False) # nosec:B603
pip_install(
join(localpackages_dir, 'a', 'dist', 'package_a-23.42-py3-none-any.whl'),
join(localpackages_dir, 'b', 'dist', 'package-b-23.42.tar.gz'),
join(localpackages_dir, 'c'),
f'package-e @ git+{Path(vcs_repo_dir).absolute().as_uri()}',
)


Expand Down
3 changes: 3 additions & 0 deletions tests/_data/infiles/requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ foo @ file://../foo

# unnamed source distribution
./downloads/numpy-1.26.1.tar.gz

# local VCS -- https://pip.pypa.io/en/stable/topics/vcs-support/
git+file:///path/to/local_pckages/e_vcs@main#egg=package-e
3 changes: 3 additions & 0 deletions tests/_data/infiles/requirements/with-urls.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ https://files.pythonhosted.org/packages/78/23/f78fd8311e0f710fe1d065d50b92ce0057

## named fetchable file
urllib3 @ https://github.com/urllib3/urllib3/archive/refs/tags/2.2.0.zip

## VCS via ssh
git+ssh://git@github.com/path/to/package-six@0.1#egg=package-six
6 changes: 6 additions & 0 deletions tests/_data/snapshots/environment/plain_local_1.0.xml.bin

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/_data/snapshots/environment/plain_local_1.1.xml.bin

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions tests/_data/snapshots/environment/plain_local_1.2.json.bin

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions tests/_data/snapshots/environment/plain_local_1.2.xml.bin

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/_data/snapshots/environment/plain_local_1.3.json.bin

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions tests/_data/snapshots/environment/plain_local_1.3.xml.bin

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/_data/snapshots/environment/plain_local_1.4.json.bin

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading