Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
swh-search
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Platform
Development
swh-search
Commits
7b2a9618
Verified
Commit
7b2a9618
authored
1 month ago
by
Antoine Lambert
Browse files
Options
Downloads
Patches
Plain Diff
Migrate from deprecated pkg_resources package to importlib.resources
parent
6944d656
No related branches found
Branches containing commit
No related tags found
1 merge request
!165
Migrate from deprecated pkg_resources package to importlib.resources
Pipeline
#13572
passed
3 days ago
Stage: external
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
swh/search/translator.py
+20
-15
20 additions, 15 deletions
swh/search/translator.py
with
20 additions
and
15 deletions
swh/search/translator.py
+
20
−
15
View file @
7b2a9618
# Copyright (C) 2021-202
2
The Software Heritage developers
# Copyright (C) 2021-202
5
The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
from
importlib.resources
import
as_file
,
files
import
logging
import
os
import
tempfile
from
pkg_resources
import
resource_filename
from
tree_sitter
import
Language
,
Parser
from
swh.search.exc
import
SearchQuerySyntaxError
...
...
@@ -25,19 +25,24 @@ class Translator:
}
def
__init__
(
self
):
ql_path
=
resource_filename
(
"
swh.search
"
,
"
static/swh_ql.so
"
)
if
not
os
.
path
.
exists
(
ql_path
):
logging
.
info
(
"
%s does not exist, building in temporary directory
"
,
ql_path
)
self
.
_build_dir
=
tempfile
.
TemporaryDirectory
(
prefix
=
"
swh.search-build
"
)
source_path
=
resource_filename
(
"
swh.search
"
,
"
query_language
"
)
ql_path
=
os
.
path
.
join
(
self
.
_build_dir
.
name
,
"
swh_ql.so
"
)
Language
.
build_library
(
ql_path
,
[
source_path
])
search_ql
=
Language
(
ql_path
,
"
swh_search_ql
"
)
self
.
parser
=
Parser
()
self
.
parser
.
set_language
(
search_ql
)
self
.
query
=
""
ql_file
=
files
(
"
swh.search
"
).
joinpath
(
"
static/swh_ql.so
"
)
with
as_file
(
ql_file
)
as
ql_filepath
:
ql_path
=
ql_filepath
.
as_posix
()
if
not
ql_filepath
.
exists
():
logging
.
info
(
"
%s does not exist, building in temporary directory
"
,
ql_path
,
)
self
.
_build_dir
=
tempfile
.
TemporaryDirectory
(
prefix
=
"
swh.search-build
"
)
source_path
=
str
(
files
(
"
swh.search
"
).
joinpath
(
"
query_language
"
))
ql_path
=
os
.
path
.
join
(
self
.
_build_dir
.
name
,
"
swh_ql.so
"
)
Language
.
build_library
(
ql_path
,
[
source_path
])
search_ql
=
Language
(
ql_path
,
"
swh_search_ql
"
)
self
.
parser
=
Parser
()
self
.
parser
.
set_language
(
search_ql
)
self
.
query
=
""
def
parse_query
(
self
,
query
):
if
query
:
...
...
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