-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 268fe44
Showing
8 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Publish | ||
|
||
on: | ||
workflow_dispatch: | ||
release: | ||
types: | ||
- created | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Github actions init | ||
uses: actions/checkout@v4 | ||
with: | ||
# To force fetching tags | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.8" | ||
|
||
- name: Install build dependencies | ||
run: pip install build | ||
|
||
- name: Build distribution | ||
run: python -m build | ||
|
||
- name: Publish | ||
uses: pypa/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Github actions init | ||
uses: actions/checkout@v4 | ||
with: | ||
# To force fetching tags | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.8" | ||
|
||
- name: Install build dependencies | ||
run: pip install build | ||
|
||
- name: Build | ||
run: python -m build | ||
|
||
- name: Read VERSION file | ||
id: getversion | ||
run: echo "version=$(cat VERSION.md)" >> $GITHUB_OUTPUT | ||
|
||
- name: Changelog | ||
run: git log $(git describe --tags --abbrev=0)..HEAD --format="%s %h" > LATEST-CHANGES.md | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v2 | ||
with: | ||
files: | | ||
dist/*.whl | ||
dist/*.tar.gz | ||
tag_name: v${{ steps.getversion.outputs.version }} | ||
body_path: LATEST-CHANGES.md | ||
token: ${{ secrets.PAT_ISVIRTUAL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.venv | ||
__pycache__ | ||
dist | ||
*.egg-info | ||
.pypirc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2016 | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
**isVirtual** is a very simple tool to detect if the current script is within a virtual environment. | ||
|
||
# Disclaimer | ||
|
||
The goal of this project was to play around with the process to publish to [Pypi](https://pypi.org). The code of this module is coming from this [stackoverflow thread](https://stackoverflow.com/questions/1871549/how-to-determine-if-python-is-running-inside-a-virtualenv). | ||
|
||
If you find use cases in which it doesn't work please open an [issue](https://github.com/AlexMili/isVirtual/issues). I intend to maintain this small package even if it can be seen as *"useless"*. | ||
|
||
# Install | ||
|
||
```bash | ||
pip install isvirtual | ||
``` | ||
|
||
# Usage | ||
|
||
Within a python script: | ||
```python | ||
from isvirtual import is_virtual_env | ||
|
||
if __name__ == "__main__": | ||
if is_virtual_env() is True: | ||
print("You are within a virtual environment") | ||
else: | ||
print("You are not in a virtual env") | ||
``` | ||
|
||
CLI mode: | ||
```console | ||
$ isvirtual | ||
Yes | ||
``` | ||
|
||
# License | ||
|
||
This project is licensed under the terms of the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os.path as osp | ||
import sys | ||
|
||
version_path = osp.join(osp.dirname(__file__), "VERSION.md") | ||
|
||
if osp.exists(version_path): | ||
with open(version_path, "r") as f: | ||
__version__ = f.readline() | ||
|
||
|
||
def is_virtual_env(): | ||
# The check for sys.real_prefix covers virtualenv, the equality of | ||
# non-empty sys.base_prefix with sys.prefix covers venv. | ||
# note: Python versions before 3.3 don't have sys.base_prefix | ||
# if you're not in virtual environment | ||
return hasattr(sys, "real_prefix") or ( | ||
hasattr(sys, "base_prefix") and sys.base_prefix != sys.prefix | ||
) | ||
|
||
|
||
def is_virtual_env_cli(): | ||
if is_virtual_env() is True: | ||
print("Yes") | ||
else: | ||
print("No") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[build-system] | ||
requires = ["hatchling"] | ||
build-backend = "hatchling.build" | ||
|
||
[project] | ||
name = "isvirtual" | ||
version = "1.0.0" | ||
description = "Detect if your script is running inside a virtual environment" | ||
readme = "README.md" | ||
authors = [{ name = "Alex Mili" }] | ||
license = { file = "LICENSE" } | ||
requires-python = ">=3.3" | ||
classifiers = [ | ||
"License :: OSI Approved :: MIT License", | ||
"Intended Audience :: Developers", | ||
"Programming Language :: Python", | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.3", | ||
"Programming Language :: Python :: 3.4", | ||
"Programming Language :: Python :: 3.5", | ||
"Programming Language :: Python :: 3.6", | ||
"Programming Language :: Python :: 3.7", | ||
"Programming Language :: Python :: 3.8", | ||
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
"Programming Language :: Python :: 3.13", | ||
] | ||
keywords = ["virtual", "env", "venv", "virtualenv", "pyenv", "environment"] | ||
dependencies = [] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/AlexMili/isVirtual" | ||
Issues = "https://github.com/AlexMili/isVirtual/issues" | ||
Repository = "https://github.com/AlexMili/isVirtual" | ||
Documentation = "https://github.com/AlexMili/isVirtual" | ||
|
||
[project.scripts] | ||
isvirtual = "main:is_virtual_env_cli" | ||
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["."] |