Skip to content

Commit 57e86bc

Browse files
authored
Rework sarif-tools to use poetry (#7)
Rework sarif-tools to use poetry
1 parent 6e5e0aa commit 57e86bc

30 files changed

+1041
-105
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
/dist
33
*.egg-info
44
*.pyc
5+
*.orig
56
/.venv
67
/.vscode

CONTRIBUTING.md

+54-33
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any addi
1818
Pull requests are welcome.
1919
1. Fork the repository.
2020
2. Make and test your changes (see Developer Guide below).
21-
3. Run `python -m black .` to format the code (`python -m pip install black` if necessary).
22-
4. Run `python -m pylint src` and check for no new errors or warnings (`python -m pip install pylint` if necessary).
21+
3. Run `poetry run black sarif` to format the code.
22+
4. Run `poetry run pylint sarif` and check for no new errors or warnings.
2323
5. Raise Pull Request in GitHub.com.
2424

2525
# Developer Guide
@@ -29,41 +29,75 @@ Pull requests are welcome.
2929
- You need Python 3.8 installed.
3030
- This is the minimum supported version of the tool. Developing with a later version risks introducing type hints such as `list[dict]` that are not compatible with Python 3.8.
3131

32-
## Running without installing
32+
Initialise Poetry by telling it where Python 3.8 is, e.g.
3333

34-
Use `run.py`. E.g.
3534
```
36-
python run.py ls "C:\temp\sarif_files"
35+
# Windows - adjust to the path where you have installed Python 3.8.
36+
poetry env use "C:\Python38\python.exe"
37+
# Linux
38+
poetry env use 3.8
3739
```
3840

39-
## Package using `build`
41+
This is not necessary if your system Python version is 3.8.
42+
43+
## Running locally in Poetry virtualenv
4044

41-
Install the [build](https://pypi.org/project/build/) package:
4245
```
43-
python -m pip install --upgrade build
46+
poetry install
47+
poetry run sarif <OPTIONS>
4448
```
4549

46-
Run it on the source code:
50+
To check that the right versions are being run:
4751
```
48-
python -m build
52+
poetry run python --version
53+
poetry run sarif --version
54+
poetry run python -m sarif --version
4955
```
5056

51-
Install the package built by `build` locally:
57+
To see what executable is being run:
5258
```
53-
python -m pip install dist/sarif-*.whl
59+
# Windows
60+
poetry run cmd /c "where sarif"
61+
# Linux
62+
poetry run which sarif
5463
```
5564

56-
## Install locally using `setuptools`
65+
## Update dependency versions
66+
67+
Run `poetry update` to bump package versions in the `poetry.lock` file.
68+
69+
## Update product version
5770

58-
Run this in the base directory:
71+
Change the `version = ` line in `pyproject.toml` for the new semantic version for your change.
72+
73+
To make sure you're paying attention, you need to change it in the test `test_version.py` as well.
74+
75+
## Run unit tests
5976
```
60-
python -m pip install .
77+
poetry run pytest
78+
```
79+
80+
## Package using `poetry build`
81+
82+
Run it on the source code:
83+
```
84+
poetry build
85+
```
86+
87+
If you want, you can install the package built locally at system level (outside the Poetry virtual environment):
88+
```
89+
pip install dist/sarif-*.whl
90+
```
91+
92+
To remove it again:
93+
```
94+
pip uninstall sarif-tools
6195
```
62-
`pip` uses a small shim `setup.py` to invoke `setuptools`. Then `setuptools` installs all runtime requirements and also installs `sarif`.
6396

6497
Note that there are two possible levels of installation:
6598

6699
### User installation
100+
67101
When you run `pip install` and `pip` doesn't have permissions to write to the Python installation's `site-packages` directory, probably because you are not running as an admin/superuser, the package is installed at "user" level only. You can run it using:
68102
```
69103
python -m sarif
@@ -81,28 +115,15 @@ When you run `pip install` and `pip` has permissions to write to the Python inst
81115
sarif
82116
```
83117

84-
## Running locally-installed sarif-tools
85-
86-
Run the installed package using the `python -m sarif` command:
87-
```
88-
python -m sarif ls "C:\temp\sarif_files"
89-
```
90-
If installed at system level, you can alternatively run the installed package using the `sarif command`.
91-
```
92-
sarif ls "C:\temp\sarif_files"
93-
```
94-
95118
## Adding packages from pypi to the project
96119

97-
Add the package and its version to `install_requires` in `setup.cfg`.
120+
Add the package and its latest version number (as minimum version) to `[tool.poetry.dependencies]` in `pyproject.toml`.
98121

99-
Then run this in the base directory to install the tool and all its requirements locally:
122+
Then run this to update Poetry's lockfile.
100123
```
101-
pip install .
124+
poetry update
102125
```
103126

104-
You can also run `pip install <packagename>` before or after this, as you wish. But you need to add the dependency to `setup.cfg` to make sure that the packaged application depends on this dependency when other people install it.
105-
106127
## Adding resource files to the project
107128

108-
Add the glob to `MANIFEST.in`. This is read because `include_package_data` in `setup.cfg` is `True`.
129+
Add the file within the `sarif` directory and it will be installed with the Python source. For example, `sarif/operations/templates/sarif_summary.html`.

MANIFEST.in

-2
This file was deleted.

0 commit comments

Comments
 (0)