Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Primary navigation
Search or go to…
Project
I
importlib_resources
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Privacy statement
Keyboard shortcuts
?
What's new
6
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
python-devs
importlib_resources
Commits
9d0270ae
Commit
9d0270ae
authored
5 years ago
by
Stefaan
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#79
use original resource filename in temp filename
parent
1a14b39b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!94
Use original resource filename in temp filename
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
importlib_resources/_common.py
+3
-3
3 additions, 3 deletions
importlib_resources/_common.py
importlib_resources/_py3.py
+1
-1
1 addition, 1 deletion
importlib_resources/_py3.py
importlib_resources/tests/test_path.py
+1
-0
1 addition, 0 deletions
importlib_resources/tests/test_path.py
with
5 additions
and
4 deletions
importlib_resources/_common.py
+
3
−
3
View file @
9d0270ae
...
...
@@ -40,11 +40,11 @@ def fallback_resources(spec):
@contextlib.contextmanager
def
_tempfile
(
reader
):
def
_tempfile
(
reader
,
suffix
=
''
):
# Not using tempfile.NamedTemporaryFile as it leads to deeper 'try'
# blocks due to the need to close the temporary file to work on Windows
# properly.
fd
,
raw_path
=
tempfile
.
mkstemp
()
fd
,
raw_path
=
tempfile
.
mkstemp
(
suffix
=
suffix
)
try
:
os
.
write
(
fd
,
reader
())
os
.
close
(
fd
)
...
...
@@ -63,7 +63,7 @@ def as_file(path):
Given a Traversable object, return that object as a
path on the local file system in a context manager.
"""
with
_tempfile
(
path
.
read_bytes
)
as
local
:
with
_tempfile
(
path
.
read_bytes
,
suffix
=
path
.
name
)
as
local
:
yield
local
...
...
This diff is collapsed.
Click to expand it.
importlib_resources/_py3.py
+
1
−
1
View file @
9d0270ae
...
...
@@ -161,7 +161,7 @@ def _path_from_reader(reader, resource):
yield
Path
(
reader
.
resource_path
(
norm_resource
))
return
opener_reader
=
reader
.
open_resource
(
norm_resource
)
with
_common
.
_tempfile
(
opener_reader
.
read
)
as
res
:
with
_common
.
_tempfile
(
opener_reader
.
read
,
suffix
=
norm_resource
)
as
res
:
yield
res
...
...
This diff is collapsed.
Click to expand it.
importlib_resources/tests/test_path.py
+
1
−
0
View file @
9d0270ae
...
...
@@ -19,6 +19,7 @@ class PathTests:
# Test also implicitly verifies the returned object is a pathlib.Path
# instance.
with
resources
.
path
(
self
.
data
,
'
utf-8.file
'
)
as
path
:
self
.
assertTrue
(
path
.
name
.
endswith
(
"
utf-8.file
"
),
repr
(
path
))
# pathlib.Path.read_text() was introduced in Python 3.5.
with
path
.
open
(
'
r
'
,
encoding
=
'
utf-8
'
)
as
file
:
text
=
file
.
read
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment