Skip to content

option not to copy files #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hydrargyrum opened this issue Apr 6, 2025 · 1 comment · May be fixed by #9
Open

option not to copy files #8

hydrargyrum opened this issue Apr 6, 2025 · 1 comment · May be fixed by #9

Comments

@hydrargyrum
Copy link

Current Situation

I have this config

[[tool.hatch.build.hooks.build-scripts.scripts]]
artifacts = ["pjy.1"]
commands = [
    "asciidoctor -b manpage pjy.adoc",
]

So I'm building pjy.1 file into the repo root dir. Then for some reason hatch-build-scripts tries to copy the built file $/pjy.1 into out dir $/pjy.1, which obviously fails:

  File "/tmp/1000/build-env-pvakc__9/lib/python3.13/site-packages/hatch_build_scripts/plugin.py", line 60, in initialize
    shutil.copyfile(src_file, out_file)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/shutil.py", line 240, in copyfile
    raise SameFileError("{!r} and {!r} are the same file".format(src, dst))
shutil.SameFileError: PosixPath('/tmp/1000/release-pjy.fbWHAl/pjy.1') and PosixPath('/tmp/1000/release-pjy.fbWHAl/pjy.1') are the same file

ERROR Backend subprocess exited when trying to invoke build_sdist

Proposed Actions

Either

  • don't call copyfile if the source is the same as the destination
  • or propose an option not to copy artifacts
hydrargyrum added a commit to hydrargyrum/hatch-build-scripts that referenced this issue Apr 6, 2025
If the command generates the artifact in the right place, there's no
need to copy it to out directory

Closes rmorshea#8
@hydrargyrum hydrargyrum linked a pull request Apr 6, 2025 that will close this issue
@johnandersen777
Copy link
Contributor

johnandersen777 commented Apr 20, 2025

Running into this same issue, for example:

[[tool.hatch.build.hooks.build-scripts.scripts]]
out_dir = "src/sshai"
work_dir = "src/sshai/compiled"
commands = [
    "CGO_ENABLED=0 go build -tags netgo -o agi_sshd agi_sshd.go",
]
artifacts = [
    "agi_sshd",
]
$ python -m tarfile -l dist/sshai-0.0.1.tar.gz | grep agi_sshd
sshai-0.0.1/src/sshai/agi_sshd 
sshai-0.0.1/src/sshai/compiled/agi_sshd 
sshai-0.0.1/src/sshai/compiled/agi_sshd.go 

Obviously we don't want both compiled artifacts in the dist.

Setting out_dir to the same as work_dir produces the same shutil error above.

The workaround I have is to put stuff in another directory and exclude the artifact that ends up there from the dist

[tool.hatch.build]
exclude = [
    "src/sshd/agi_sshd",
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants