Skip to content
Closed
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
19 changes: 11 additions & 8 deletions Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,17 +969,20 @@ def set_data(self, path, data, *, _mode=0o666):
return

if part == _PYCACHE:
gitignore = _path_join(parent, '.gitignore')
try:
_path_stat(gitignore)
except FileNotFoundError:
gitignore_content = b'# Created by CPython\n*\n'
# Don't create in site-packages as these are managed
# by package installers, not Git
if 'site-packages' not in parent:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this assume that sysconfig.get_path('purelib') is named site-packages?
Users can configure this in site.py; Ubuntu uses dist-packages instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, let's change to use sysconfig.get_path('purelib'). Should we also check sysconfig.get_path('platlib')?

  • platlib: directory for site-specific, platform-specific files.
  • purelib: directory for site-specific, non-platform-specific files (‘pure’ Python).

https://docs.python.org/3/library/sysconfig.html#installation-paths

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

More generally: how can you tell what “manages” a given directory? I don't really have an answer, I'm afraid.

gitignore = _path_join(parent, '.gitignore')
try:
_write_atomic(gitignore, gitignore_content, _mode)
_path_stat(gitignore)
except FileNotFoundError:
gitignore_content = b'# Created by CPython\n*\n'
try:
_write_atomic(gitignore, gitignore_content, _mode)
except OSError:
pass
except OSError:
pass
except OSError:
pass
try:
_write_atomic(path, data, _mode)
_bootstrap._verbose_message('created {!r}', path)
Expand Down
17 changes: 10 additions & 7 deletions Lib/py_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ def compile(file, cfile=None, dfile=None, doraise=False, optimize=-1,
if dirname:
os.makedirs(dirname)
if os.path.basename(dirname) == '__pycache__':
gitignore = os.path.join(dirname, '.gitignore')
if not os.path.exists(gitignore):
try:
with open(gitignore, 'wb') as f:
f.write(b'# Created by CPython\n*\n')
except OSError:
pass
# Don't create in site-packages as these are managed
# by package installers, not Git
if 'site-packages' not in dirname:
gitignore = os.path.join(dirname, '.gitignore')
if not os.path.exists(gitignore):
try:
with open(gitignore, 'wb') as f:
f.write(b'# Created by CPython\n*\n')
except OSError:
pass
except FileExistsError:
pass
if invalidation_mode == PycInvalidationMode.TIMESTAMP:
Expand Down
Loading